Ticket #5441: move.diff

File move.diff, 1.6 KB (added by tim at wheresrover.co.uk, 16 years ago)

diff of myth.findorphans.pl

  • contrib/maintenance/myth.find_orphans.pl

     
    4040use DBI;
    4141use Sys::Hostname;
    4242use Getopt::Long;
    43 
     43use File::Copy;
    4444#
    4545# options
    4646#
     
    5858my $opt_help =          0;
    5959my $opt_dryrun =        0;
    6060my $opt_rerecord =      0;
    61 
     61my $opt_domove =        0;
     62my $opt_destdir =       "/tmp";
    6263GetOptions(
    6364        'host=s'        => \$opt_host,
    6465        'dbhost=s'      => \$opt_dbhost,
     
    7374        'debug+'        => \$debug,
    7475        'help'          => \$opt_help,
    7576        'h'             => \$opt_help,
    76         'v'             => \$opt_help);
     77        'v'             => \$opt_help,
     78        'domove'        => \$opt_domove,
     79        'destdir=s'     => \$opt_destdir);
    7780
    7881if ($opt_help) {
    7982        print<<EOF
     
    9295        --dodelete              delete files with no record (default: don't)
    9396        --dryrun                display delete actions without doing them
    9497        --rerecord              set db entries to re-record missing files (requires --dodbdelete)
    95 
     98        --domove                move files instead of deleting specify destination with --destdir= (default /tmp)
    9699EOF
    97100;
    98101        exit(0);
     
    207210                                                }
    208211                                        }
    209212                                }
     213                                if ($opt_domove) {
     214                                        printf STDERR "moving [%s]: %s/%s to %s\n",pretty_filesize($this_filesize),$this_dir,$this_file, $opt_destdir;
     215                                        if (!$opt_dryrun) {
     216                                                move("$this_dir/$this_file",$opt_destdir);
     217                                                if (-f "$this_dir/$this_file") {
     218                                                        $errors++;
     219                                                        printf "ERROR: Could not move $this_dir/$this_file to $opt_destdir";
     220                                                        }
     221                                                }
     222                                        }
    210223                        } else {
    211224                                $known_files++;
    212225                                $known_size += $this_filesize;