libpcp: optimise DSO lookups for local context mode startup
[pcp.git] / build / cleanconfigs
blobe9c539dee2bf60690c3ccbd83ffaec45fe45a109
1 # Function to do all of the configuration file migration work
3 _clean_configs()
5     #
6     # Usage: _clean_configs [-v] new_dir old_dir ...
7     #
8     # Across all the files in the new_dir and old_dir args, match
9     # names and pick the most recently modified version and leave
10     # this (same mode and modification date) in new_dir
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_configs [-v] new_dir old_dir ..."
25         return
26     fi
28     _new="$1"
29     if [ ! -d "$_new" ]
30     then
31         $verbose && echo >&2 + mkdir -p "$_new"
32         mkdir -p "$_new"
33     fi
35     shift
36     for _dir
37     do
38         [ "$_dir" = "$_new" ] && continue
39         if [ -d "$_dir" ]
40         then
41             ( cd "$_dir" ; find . -type f -print ) \
42             | sed -e 's/^\.\///' \
43             | while read _file
44             do
45                 _want=false
46                 if [ -f "$_new/$_file" ]
47                 then
48                     # file exists in both directories, pick the more
49                     # recently modified one
50                     #
51                     _try=`find "$_dir/$_file" -newer "$_new/$_file" -print`
52                     [ -n "$_try" ] && _want=true
53                 else
54                     _want=true
55                 fi
56                 if $_want
57                 then
58                     _dest=`dirname $_new/$_file`
59                     if [ ! -d "$_dest" ]
60                     then
61                         $verbose && >&2 echo + mkdir "$_dest"
62                         mkdir "$_dest"
63                     fi
64                     $_verbose && echo >&2 + cp -p "$_dir/$_file" "$_new/$_file"
65                     cp -p "$_dir/$_file" "$_new/$_file"
66                 fi
67             done
68         fi
69     done