Changeset 25577

Show
Ignore:
Timestamp:
11.05.2012 16:40:12 (7 years ago)
Author:
ak19
Message:

Moved some more general methods from activate.pl to util.pm and in the recently added sub mv_dir_contents, use rmdir to remove empty dirs rather than using rm_r.

Files:
1 modified

Legend:

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

    r25572 r25577  
    206206                # now all content is moved across, delete empty dir in source folder 
    207207                if(&is_dir_empty($file)) { 
    208                     &rm_r($file);  
     208                    if (!rmdir $file) { 
     209                        print STDERR "util::mv_dir_contents couldn't remove directory $file\n"; 
     210                    }  
    209211                } else { # error 
    210212                    print STDERR "ERROR. util::mv_dir_contents: subfolder $file still non-empty after moving contents to $dest_dir\n"; 
     
    17791781 
    17801782 
     1783# Given the qualified collection name (colgroup/collection),  
     1784# returns the collection and colgroup parts 
     1785sub get_collection_parts { 
     1786    # http://perldoc.perl.org/File/Basename.html 
     1787    # my($filename, $directories, $suffix) = fileparse($path); 
     1788    # "$directories contains everything up to and including the last directory separator in the $path  
     1789    # including the volume (if applicable). The remainder of the $path is the $filename." 
     1790    #my ($collection, $colgroup) = &File::Basename::fileparse($qualified_collection);    
     1791 
     1792    my $qualified_collection = shift(@_);  
     1793 
     1794    # Since activate.pl can be launched from the command-line, including by a user,  
     1795    # best not to assume colgroup uses URL-style slashes as would be the case with GLI 
     1796    # Also allow for the accidental inclusion of multiple slashes 
     1797    my ($colgroup, $collection) = split(/[\/\\]+/, $qualified_collection); #split('/', $qualified_collection); 
     1798     
     1799    if(!defined $collection) { 
     1800        $collection = $colgroup; 
     1801        $colgroup = ""; 
     1802    } 
     1803    return ($collection, $colgroup); 
     1804} 
     1805 
     1806# work out the "collectdir/collection" location 
     1807sub resolve_collection_dir { 
     1808    my ($collect_dir, $qualified_collection, $site) = @_; #, $gs_mode 
     1809     
     1810    my ($colgroup, $collection) = &util::get_collection_parts($qualified_collection);    
     1811     
     1812    if (defined $collect_dir) { 
     1813        return &util::filename_cat($collect_dir,$colgroup, $collection); 
     1814    } 
     1815    else { 
     1816        if (defined $site) { 
     1817            return &util::filename_cat($ENV{'GSDL3HOME'},"sites",$site,"collect",$colgroup, $collection); 
     1818        } 
     1819        else { 
     1820            return &util::filename_cat($ENV{'GSDLHOME'},"collect",$colgroup, $collection); 
     1821        } 
     1822    } 
     1823} 
     1824 
    178118251;