X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=scripts%2Farchival%2Fshared_snarfer.pl;h=5d1ac7377b1090978732d32bb2ffb31627f07b1b;hb=2eab636d6e37cd612c1a77bb50d4e30458724f6a;hp=0a37bf093a29d71a5ab4b001ed7da7cd26bc7ae9;hpb=2952ccf47b80174880141a7ecfa122089f349b8d;p=feisty_meow.git diff --git a/scripts/archival/shared_snarfer.pl b/scripts/archival/shared_snarfer.pl index 0a37bf09..5d1ac737 100644 --- a/scripts/archival/shared_snarfer.pl +++ b/scripts/archival/shared_snarfer.pl @@ -21,21 +21,14 @@ ############################################################################### require "filename_helper.pl"; -require "hostname.pl"; -require "importenv.pl"; require "inc_num.pl"; use Cwd; +use Sys::Hostname; +use File::Which; +use Env qw(FEISTY_MEOW_SCRIPTS TMP); -#hmmm: maybe move this to a utility script file. $null_log = "/dev/null"; -#hmmm: move especially this check to a script file, and recast anything -# referring to Windows_NT to it. -if ( ("$OS" =~ /[wW][iI][nN]/) || ("$OS" =~ /[Oo][Ss]2/) - || ("$OS" =~ /[Dd][Oo][Ss]/) ) { - $null_log = "nul" -} -#print "nul log=$null_log \n"; $TMP =~ s/\\/\//g; # fix the temp variable for ms-winders. @@ -45,15 +38,16 @@ $TMP =~ s/\\/\//g; # fix the temp variable for ms-winders. # these files are considered unimportant and won't be included in the archive. @junk_file_list = ("*~", "*.$$$", "3rdparty", "*.aps", "*.bak", "binaries", "*.bsc", "*.cgl", "*.csm", "CVS", "Debug", "*.dll", "*.err", "*.exe", - "generated_*", "*.glb", "inprogress", "ipch", "*.llm", "*.log", "*.lnk", + "generated_*", "*.git", "*.glb", "inprogress", "ipch", "*.llm", + "*.log", "*.lnk", "makefile.fw*", "*.mbt", "*.mrt", "*.ncb", "*.o", "obj", "*.obj", "octalforty.Wizardby", "*.obr", "*.opt", "packages", "*.pch", "*.pdb", "*.plg", "*.r$p", "*.rcs", "Release", "*.res", "*.RES", "*.rws", "*.sbr", "*.scc", "*.spx", "*.stackdump", + "Steam", "*.sdf", "*.suo", ".svn", "*.sym", "*.td", "*.tds", "*.tdw", "*.tlb", "*.trw", "*.tmp", "*.tr", "*.user", "*_version.h", "*_version.rc", - "*.vspscc", "waste"); -###, "*.wav" + "*.vspscc", "waste", "zeitgeist"); #print "junk list=@junk_file_list\n"; @excludes = (); for (local($i) = 0; $i < scalar(@junk_file_list); $i++) { @@ -62,18 +56,8 @@ for (local($i) = 0; $i < scalar(@junk_file_list); $i++) { #print "excludes list=@excludes\n"; # generic versions work on sane OSes. -$find_tool = `which find`; chop $find_tool; -$tar_tool = `which tar`; chop $tar_tool; - -# pick a more specific version for windows. -if ( ("$OS" =~ /[wW][iI][nN]/) || ("$OS" =~ /[Oo][Ss]2/) - || ("$OS" =~ /[Dd][Oo][Ss]/) ) { - $top_level = "$BUILD_TOP"; - $msys_folder = "$top_level/build/msys/bin"; - $find_tool = "$msys_folder/find.exe"; - $tar_tool = "$msys_folder/tar.exe"; -} - +$find_tool = which('find'); +$tar_tool = which('tar'); #print "find tool: $find_tool\n"; #print "tar tool: $tar_tool\n"; @@ -91,7 +75,8 @@ sub initialize_snarfer { # returns the current hostname, but without any domain included. sub short_hostname { - local($temphost) = &hostname(); + local($temphost) = hostname(); +#&hostname(); $temphost =~ s/([^.]*)\..*/\1/; return &lower($temphost); } @@ -100,23 +85,12 @@ sub short_hostname { # a timestamp and hostname. sub snarf_prefix { local($base) = @_; - local($extra_path) = ""; - if ($OS =~ /win/i) { - if (length($MINGBIN)) { - # we rely on the ming binary path on windows, since otherwise a strange - # interaction between perl and windowz causes 'date' to use the retarded - # windows date program, even with the ming binaries in the path before - # the windows directory. - $extra_path = "$MINGBIN/"; -#print "ming path here is:\n$MINGBIN\n"; - } else { - # just hope that this is running under msys in our build bin. - $extra_path = "$HOME/hoople2/build/msys/bin/"; - } - } - local($date_part) = `${extra_path}date +%Y-%m-%d-%H%M`; +#hmmm: extract this shared code to new function (also in safedel) + $date_tool = "date"; + local($date_part) = `$date_tool +%Y-%m-%d-%H%M`; while ($date_part =~ /[\r\n]$/) { chop $date_part; } + local($host) = &short_hostname(); while ($host =~ /[\r\n]$/) { chop $host; } $base = $base . "_" . $host . "_" . $date_part; @@ -194,7 +168,7 @@ sub snarfer { chdir($root); local($outcome) = 0; - my @lines = qx( $find_tool $subdir @extra_flags "-type" "f" ); + my @lines = qx( $find_tool "$subdir" @extra_flags "-type" "f" ); # if ( ($! != 0) || ($? != 0) ) { # die("failure to find files in $subdir"); # } @@ -210,8 +184,8 @@ sub snarfer { } local($outcome) = 0xff & system $tar_tool, - "-rf", &msys_canonicalize($target_file), @excludes, - "--files-from=" . &msys_canonicalize($temp_file); + "-rf", &canonicalize($target_file), @excludes, + "--files-from=" . &canonicalize($temp_file); if ($outcome) { unlink($temp_file); die("failure to archive"); @@ -234,6 +208,7 @@ sub snarf_file_list { local($target_file) = &snarf_name($prefix, $number); local($currdir) = cwd(); +#print "got root as: '$root'\n"; chdir("$root"); local(@files) = &glob_list($file_pattern); @@ -250,7 +225,7 @@ sub snarf_file_list { } local($outcome) = 0xff & system $tar_tool, #"--directory=" . "$root", - @extra_flags, "-rf", &msys_canonicalize($target_file), @excludes, $i; + @extra_flags, "-rf", &canonicalize($target_file), @excludes, $i; if ($outcome) { die("failure to archive"); } } chdir("$currdir"); @@ -286,7 +261,7 @@ sub remove_from_backup { #print "remove_from_backup: pref=$prefix, num=$number, patt=$pattern,\n"; local($target_file) = &snarf_name($prefix, $number); - open(TARPROC, "$tar_tool --delete -f " . &msys_canonicalize($target_file) + open(TARPROC, "$tar_tool --delete -f " . &canonicalize($target_file) . " \"$pattern\" 2>$null_log |"); ; } @@ -341,22 +316,37 @@ sub backup_hierarchies { } } -# grab up all the files in a directory (first parm) that are named matching -# a simple text pattern (second parm). +# grab up all the files in a directory (second parm) that are named matching +# a simple text pattern (third parm). if there is a fourth parameter, it is +# used as an extra directory component after the main directory. sub snarf_by_pattern { - local($dir, $pattern) = @_; -# print "dir = $dir and patt = $pattern\n"; - + local($prefix, $dir, $pattern, $extra_component) = @_; + local($had_extra) = length($extra_component) != 0; +#print "snarf by pattern, dir = $dir, patt = $pattern, extra = $extra_component\n"; + if ($had_extra) { + $dir = "$dir/$extra_component"; + } @dir_contents = &glob_list("$dir/*$pattern*"); -# print "dir contents: @dir_contents\n"; +#print "dir contents: @dir_contents\n"; if (!scalar(@dir_contents)) { - print "no $pattern directores were backed up in $dir.\n"; + print "no '$pattern' directores were backed up in $dir.\n"; } + foreach $item (@dir_contents) { if ( ($item =~ /$pattern.*snarf/) || ($item =~ /$pattern.*tar/) ) { next; } if ( ! -d "$item" ) { next; } - &backup_hierarchy($base, $number, $item, "."); +#print "now really planning to backup hier of $item\n"; + # normal backup had no extra component. + local $upper_dir = &dirname($item); + local $dir_plus_base = &basename($item); + # if we did have an extra component, we do this a bit differently. + if ($had_extra) { + $upper_dir = &dirname( &dirname($item) ); + $dir_plus_base = &basename( &dirname($item) ) . "/" . &basename($item); + } +#print "using upper=$upper_dir and dir+base=$dir_plus_base\n"; + &backup_hierarchy($prefix, $number, $upper_dir, $dir_plus_base); } } @@ -384,7 +374,7 @@ sub backup_number { chdir($TMP); local($outcome) = 0xff & system $tar_tool, "-cf", - &msys_canonicalize($target_file), &msys_canonicalize($number_file); + &canonicalize($target_file), &canonicalize($number_file); if ($outcome) { die("failure to archive"); } local($prefix_file) = "prefix.bac"; @@ -393,7 +383,7 @@ sub backup_number { close(NUM_PREFIX); $outcome = 0xff & system $tar_tool, "-rf", - &msys_canonicalize($target_file), &msys_canonicalize($prefix_file); + &canonicalize($target_file), &canonicalize($prefix_file); if ($outcome) { die("failure to archive"); } unlink($prefix_file); chdir($currdir); @@ -462,11 +452,11 @@ sub restore_archive { } local($outcome) = 0xff & system $tar_tool, "-xzf", - &msys_canonicalize($filename); + &canonicalize($filename); if ($outcome) { die("failure to undo archive"); } local($outcome) = - 0xff & system "bash", "$SHELLDIR/files/normal_perm.sh", "."; + 0xff & system "bash", "$FEISTY_MEOW_SCRIPTS/security/normal_perm.sh", "."; if ($outcome) { die("failure to normalize permissions"); } # remove any links that might have crept in; these can cause mischief.