Ignore:
Timestamp:
2023-01-27T23:52:38+13:00 (17 months ago)
Author:
davidb
Message:

Reworking of file-level document-version history, in light of a clearer understanding of how hardlinking works in terms of inodes on disk. The new solution needs to make use of moving archives to archives_keep, them copying things back. As copying is involved this means time-stamp on the archive infodb used for incremental building can no longer be used to establish which files in 'import' are newer than the last build. The implemented solution here is to store the timestamp of the previous build in a a file (rather than relying on the timestamp of a file created). The opportunity was also taken to record in this file the type of infodb used on that import.pl. With this extra information it is now possible to detect when the type of infodb used has changed in the collectionConfi.xml, meaning import.pl can still function correctly, even in the case of an incremental or incremental-add import.pl being run.

File:
1 edited

Legend:

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

    r37151 r37187  
    120120# internal version that copies a file or a group of files
    121121#
    122 sub _copyFilesGeneral
     122sub copyFilesGeneral
    123123{
    124124    my ($srcfiles_ref,$dest,$options) = @_;
     
    137137    if (scalar(@$srcfiles_ref) == 0)
    138138    {
    139     print STDERR "FileUtils::_copyFilesGeneral() no destination directory given\n";
     139    print STDERR "FileUtils::copyFilesGeneral() no destination directory given\n";
    140140    return 0;
    141141    }
    142142    elsif ((scalar(@$srcfiles_ref) > 1) && (!-d $dest))
    143143    {
    144     print STDERR "FileUtils::_copyFilesGeneral() if multiple source files are given the destination must be a directory\n";
     144    print STDERR "FileUtils::copyFilesGeneral() if multiple source files are given the destination must be a directory\n";
    145145    return 0;
    146146    }
     
    159159    if (!-e $file)
    160160    {
    161         print STDERR "FileUtils::_copyFilesGeneral() $file does not exist\n";
     161        print STDERR "FileUtils::copyFilesGeneral() $file does not exist\n";
    162162        $had_an_error = 1;
    163163        if ($strict) {
     
    167167    elsif (!-f $file)
    168168    {
    169         print STDERR "FileUtils::_copyFilesGeneral() $file is not a regular file\n";
     169        print STDERR "FileUtils::copyFilesGeneral() $file is not a regular file\n";
    170170        $had_an_error = 1;
    171171        if ($strict) {
     
    181181        if (!link($file, $tempdest))
    182182        {
    183             print STDERR "Warning: FileUtils::_copyFilesGeneral(): unable to create hard link. ";
     183            print STDERR "Warning: FileUtils::copyFilesGeneral(): unable to create hard link. ";
    184184            print STDERR "  Attempting file copy: $file -> $tempdest\n";
    185185            $success = &File::Copy::copy($file, $tempdest);
     
    195195       
    196196        if (!$success) {
    197         print STDERR "FileUtils::_copyFilesGeneral() failed to copy $file -> $tempdest\n";
     197        print STDERR "FileUtils::copyFilesGeneral() failed to copy $file -> $tempdest\n";
    198198        $had_an_error = 1;
    199199       
     
    226226  my (@srcfiles) = @_;
    227227 
    228   return &_copyFilesGeneral(\@srcfiles,$dest,undef);
     228  return &copyFilesGeneral(\@srcfiles,$dest,undef);
    229229}
    230230
     
    306306    my $strict = 0;
    307307    my $make_fullpath = 0;
     308    my $exclude_dirs  = 0;
     309    my $exclude_files = 0;
    308310    my $exclude_filter_re = undef;
    309311    my $include_filter_re = undef;
     
    312314    $strict = $options->{'strict'} if defined $options->{'strict'};
    313315    $make_fullpath = $options->{'make_fullpath'} if defined $options->{'make_fullpath'};
     316    $exclude_dirs  = $options->{'exclude_dirs'}  if defined $options->{'exclude_dirs'};
     317    $exclude_files = $options->{'exclude_files'} if defined $options->{'exclude_files'};
    314318    $exclude_filter_re = $options->{'exclude_filter_re'} if defined $options->{'exclude_filter_re'};
    315319    $include_filter_re = $options->{'include_filter_re'} if defined $options->{'include_filter_re'};
     
    330334    {
    331335        next if $f_or_d =~ /^\.\.?$/;
     336        next if $exclude_dirs  && -d &filenameConcatenate($src_dir_fullpath, $f_or_d);
     337        next if $exclude_files && -f &filenameConcatenate($src_dir_fullpath, $f_or_d);     
    332338        next if (defined $exclude_filter_re && ($f_or_d =~ m/$exclude_filter_re/));
    333339       
     
    556562            {
    557563                my $fullpath_subf = $fullpath_subf_or_subd;
    558                 my $ret_val_success = &_copyFilesGeneral([$fullpath_subf],$dest,$options);
     564                my $ret_val_success = &copyFilesGeneral([$fullpath_subf],$dest,$options);
    559565
    560566                if ($ret_val_success == 0) {
     
    585591    else
    586592    {
    587         my $ret_val_success = &_copyFilesGeneral([$file], $dest, $options);
     593        my $ret_val_success = &copyFilesGeneral([$file], $dest, $options);
    588594        if ($ret_val_success == 0) {
    589595
     
    14871493## moveFiles()
    14881494
     1495
     1496## @function renameDirectory()
     1497#
     1498# rename a directory
     1499# (effectively a move, where the destination name cannot already exist)
     1500#
     1501sub renameDirectory
     1502{
     1503    my ($srcdir,$dstdir) = @_;
     1504
     1505    my $had_an_error = 0;
     1506
     1507    if (!-d $srcdir) {
     1508    print STDERR "FileUtils::renameDirectory() Error - Source name must be an existing directory\n";
     1509    print STDERR "Source name was: $srcdir\n";
     1510    $had_an_error = 1;
     1511    }
     1512    elsif (-e $dstdir) {
     1513    print STDERR "FileUtils::renameDirectory() Error - Destination name must not already exist\n";
     1514    print STDERR "Destination name was: $dstdir\n";
     1515    $had_an_error = 1;
     1516
     1517    }
     1518    else {
     1519    if (!rename($srcdir,$dstdir)) {
     1520        print STDERR "FileUtils::renameDirectory() -- Error occured moving source name to destination name\n";
     1521        print STDERR "Source name was: $srcdir\n";
     1522        print STDERR "Destination name was: $dstdir\n";
     1523        $had_an_error = 1;
     1524    }
     1525    }
     1526   
     1527    if ($had_an_error) {
     1528    return 0; # i.e., not OK!
     1529    }
     1530    else {
     1531    return 1;
     1532    }
     1533}
     1534## renameDirectory()
     1535 
    14891536## @function openFileHandle()
    14901537#
Note: See TracChangeset for help on using the changeset viewer.