pcp-atopsar: fix swptotal and swpfree reporting units
[pcp.git] / build / cleantmpdirs
blob547fa070eaa10e0b7070274be232bd907f252033
1 # Function to do all of the temporary dir/file migration work
3 _clean_tmpdirs()
5     #
6     # Usage: _clean_tmpdirs [-v] new_dir old_dir ...
7     #
8     # Move temporary directories (which may be actively in use as
9     # with pmdammv files) from one temporary directory to another
10     # so as to transparently upgrade without loss of service.
11     #
12     # -v option is verbose mode for debugging
13     #
15     _verbose=false
16     if [ $# -gt 0 -a X"$1" = "X-v" ]
17     then
18         _verbose=true
19         shift
20     fi
22     if [ $# -lt 2 ]
23     then
24         echo >&2 "Usage: _clean_tmpdirs [-v] new_dir old_dir subdirs ..."
25         return
26     fi
28     _new_tmp_dir="$1"
29     _old_tmp_dir="$2"
31     [ "$_new_tmp_dir" != "$old_tmp_dir" ] || return
33     for _subdir
34     do
35         d="$_old_tmp_dir/$_subdir"
36         test -d "$d" -a -k "$d" || continue
37         cd "$d" || continue
38         for f in * ; do
39             [ "$f" != "*" ] || continue
40             source="$d/$f"
41             target="$_new_tmp_dir/$_subdir/$f"
42             [ "$source" != "$target" ] || continue
43             [ ! -f "$target" ] || continue
44             $_verbose && echo + mv -fu "$source" "$target"
45             mv -fu "$source" "$target" || true
46         done
47         $_verbose && echo + rmdir "$d"
48         cd && rmdir "$d" 2>/dev/null || true
49     done