Changeset 25578 for main/trunk


Ignore:
Timestamp:
2012-05-11T18:36:54+12:00 (12 years ago)
Author:
ak19
Message:

Modifying recently introduced mv_dir_contents method again: recursion call to mv_dir_contents on any directory need only happen if the same directory (with the same sub path) also exists in the target directory. For regular files and any directories not duplicated in target, a straightforward call to mv is sufficient. Reducing the amount of recursion would make it more efficient.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/util.pm

    r25577 r25578  
    192192    close(DIR);
    193193   
    194     # construct absolute paths
    195194    my @full_path_files = ();
    196195    foreach my $file (@files) {
    197196        # process all except . and ..
    198197        unless($file eq "." || $file eq "..") {
    199             my $tailname = $file;
    200             $file = &filename_cat($src_dir, $file);
    201                
    202             if(-d $file) { # recursion on directories
    203                 #print STDERR "**** $file is a directory, to be copied to $dest_dir\\$tailname\n";
    204                 &mv_dir_contents($file, &filename_cat($dest_dir, $tailname));
     198           
     199            my $dest_subdir = &filename_cat($dest_dir, $file); # $file still relative path
     200       
     201            # construct absolute paths
     202            $file = &filename_cat($src_dir, $file); # $file is now an absolute path
     203           
     204            # Recurse on directories which have an equivalent in target dest_dir
     205            # If $file is a directory that already exists in target $dest_dir,
     206            # then a simple move operation will fail (definitely on Windows).
     207            if(-d $file && -d $dest_subdir) {
     208                print STDERR "**** $file is a directory also existing in target, to be copied to $dest_subdir\n";
     209                &mv_dir_contents($file, $dest_subdir);
    205210               
    206211                # now all content is moved across, delete empty dir in source folder
     
    212217                    print STDERR "ERROR. util::mv_dir_contents: subfolder $file still non-empty after moving contents to $dest_dir\n";
    213218                }
    214             } else { # process files with a simple move
     219            } else { # process files and any directories that don't already exist with a simple move
    215220                push(@full_path_files, $file);
    216221            }           
Note: See TracChangeset for help on using the changeset viewer.