[BACK]Return to fs.pm CVS log [TXT][DIR] Up to [local] / wpscripts / ezreturn

Annotation of wpscripts/ezreturn/fs.pm, Revision 1.1.1.1

1.1       yason       1: package fs;
                      2:
                      3: use index;
                      4:
                      5: # total returned files
                      6: our $NRETURNED = 0;
                      7:
                      8: sub copy($$$$)
                      9: {
                     10:        my $ID_ref = shift;
                     11:        my $file_type_ref = shift;
                     12:        my $file_name_ref = shift;
                     13:        my $file_retpath_ref = shift;
                     14:
                     15:        my @ID           = @$ID_ref;
                     16:        my @file_type    = @$file_type_ref;
                     17:        my @file_name    = @$file_name_ref;
                     18:        my @file_retpath = @$file_retpath_ref;
                     19:
                     20:        my $i;
                     21:        my $bfilepath;
                     22:        my $bfilebasename;
                     23:        my $retval;
                     24:
                     25:        my $oldsize;
                     26:        my $newsize;
                     27:
                     28:        print "[fs::copy] entering with " . scalar(@file_type) . " ab_want files\n";
                     29:
                     30:        # TODO
                     31:
                     32:        # iterate over all given files
                     33:        for($i = 0; $i < scalar(@file_type); $i++) {
                     34:
                     35:                $bfilepath = index::lookup($file_type[$i], $file_name[$i]);
                     36:
                     37:                if ($bfilepath eq "") {
                     38:                        # requested file not found in backups
                     39:                        # XXX notify via email ?
                     40:                        print "[fs::copy] $file_name[$i] of type $file_type[$i] not found in backups\n";
                     41:
                     42:                        # XXX unwant file in db, maybe unneccessary?
                     43:                        dbops::unwant($file_type[$i], $ID[$i]);
                     44:
                     45:                        next;
                     46:                        # NOTREACHED
                     47:                }
                     48:
                     49:                # here it is safe to do basename
                     50:                $bfilebasename = `basename $bfilepath`;
                     51:                chomp($bfilebasename);
                     52:
                     53:                print "[fs::copy] initiating copy $bfilepath to $file_retpath[$i]/$bfilebasename\n";
                     54:
                     55:                # execute system command
                     56:                system("cp $bfilepath $file_retpath[$i]");
                     57:
                     58:                if ($? != 0) {
                     59:                        # cp failed
                     60:                        print "[fs::copy] copy failed (retval=$?)\n";
                     61:
                     62:                        # process next element
                     63:                        next;
                     64:                }
                     65:
                     66:                # check sizes
                     67:                if (-s $bfilepath == -s "$file_retpath[$i]/$bfilebasename") {
                     68:
                     69:                        print "[fs::copy] copy completed, sizes matched\n";
                     70:
                     71:                        $NRETURNED++;
                     72:
                     73:                        # update database
                     74:                        print "file_type=$file_type[$i] ID=$ID[$i]\n";
                     75:                        dbops::unwant($file_type[$i], $ID[$i]);
                     76:
                     77:                }
                     78:                else {
                     79:                        # sized did not matched
                     80:
                     81:                        print "[fs::copy] copy completed, but sizes DID NOT MATCHED\n";
                     82:                        print "[fs::copy] will NOT update database\n";
                     83:
                     84:                }
                     85:
                     86:                # next file
                     87:                next;
                     88:        }
                     89:
                     90:
                     91:        print "[fs::copy] leaving (copied $NRETURNED files)\n";
                     92: }
                     93:
                     94: return 1;
                     95:

CVSweb