App-DistSync

 view release on metacpan or  search on metacpan

lib/App/DistSync.pm  view on Meta::CPAN


    # Filling the list of exclusion files using the MANIFEST.SKIP file and
    # the list of system files from the SKIPFILES constant
    {
        debug("Getting the list of skipped files");
        my @skip_keys = @{(SKIPFILES)};
        my $maniskip = maniread($self->{file_maniskip}, SKIPMODE); # MANIFEST.SKIP
        push @skip_keys, keys %$maniskip if ref($maniskip) eq 'HASH';
        for (@skip_keys) {$skips{$_} = qrreconstruct($_)}
        debug("Found %d keys in the list of skipped files", scalar(keys %skips));
        #debug(Data::Dumper::Dumper(\%skips)) && return 0;
    }

    # Deleting files listed in the MANIFEST.DEL file but not in the exclusion list
    {
        debug("Deleting files from list: %s", MANIDEL);
        my $delfile = $self->{file_manidel};  # MANIFEST.DEL
        my $deltime = $self->{mtime_manidel}; # Modify time in seconds
        my $dellist = maniread($delfile) // {}; # { file => expire };
        my $expire = 0;
        foreach (values %$dellist) {
            my $dt = _expire($_->[0] || 0);
            $_ = [$dt];
            $expire = $dt if $dt > $expire;
        }
        $expire = _expire(EXPIRE) unless $expire > 0;
        debug("The file '$delfile' will expire on %s", scalar(localtime($deltime + $expire)))
            if $deltime;
        #debug(Data::Dumper::Dumper($dellist)) && return 0;
        if ($deltime && (time - $deltime) > $expire) { # MANIFEST.DEL is expired!
            # Delete files physically if they exist physically and are not on the exclusion list!
            foreach my $k (keys %$dellist) {
                if (_skipcheck(\%skips, $k)) { # The file is in the exclusion list.
                    debug("> [SKIPPED] %s", $k);
                    next;
                }
                my $f = File::Spec->canonpath(File::Spec->catfile($self->dir, $k));
                if (-e $f) {
                    fdelete($f);

lib/App/DistSync.pm  view on Meta::CPAN

                    # {file => [epoch, size, wday, month, day, time, year]}
                    foreach my $k (keys(%$manifest), keys(%$remote_manifest)) {
                        unless (exists $mtmp{$k}) {
                            $mtmp{$k} = 1;
                            next;
                        }
                        my $mt_l = $manifest->{$k}[0] || 0; # Modified time (local, left)
                        my $mt_r = $remote_manifest->{$k}[0] || 0;  # Modified time (remote, right)
                        $mtmp{$k}++ if $mt_l && $mt_r && $mt_l == $mt_r; # =2 if the files are identical
                    }
                    #debug(Data::Dumper::Dumper(\%mtmp));

                    # Getting the difference between the lists of local and remote files
                    #
                    # [=] The files do not differ; they are identical in both lists
                    # [<] The file exists in the local (left) file list
                    # [>] The file exists in the remote (right) file list
                    # [{] The "newer" file is the one in the local list
                    # [}] The "newer" file is the one in the remote list
                    # [~] The file sizes differ between the lists. This is only reported as information,
                    #     since modification times and file presence have higher priority than sizes

lib/App/DistSync.pm  view on Meta::CPAN

        foreach my $k (keys %delete_list) {
            my $f = File::Spec->canonpath(File::Spec->catfile($self->dir, $k));
            if (-e $f) {
                fdelete($f);
                debug("> [DELETED] %s", $k);
            } else {
                debug("> [SKIPPED] %s (%s)", $k, $f);
            }
        }
    }
    #debug(Data::Dumper::Dumper(\%delete_list));

    # Iterate through the synchronization list and download all files that
    # are NOT present in the previously generated deletion list.
    #debug(Data::Dumper::Dumper(\%sync_list));
    {
        debug("Downloading files");
        my $total = 0; # Size
        my $cnt = 0; # File number
        my $all = scalar(keys %sync_list);
        my $af = '[%0' . length("$all") . 'd/%0' . length("$all") . 'd] %s';
        foreach my $k (sort {lc($a) cmp lc($b)} keys %sync_list) { $cnt++;
            debug($af, $cnt, $all, $k);
            my $list = $sync_list{$k} // []; # Get list of urls
            unless (scalar(@$list)) {

lib/App/DistSync.pm  view on Meta::CPAN

    # Cteating MANIFEST file
    debug("Generating new manifest");
    my $new_manifest = manifind($self->dir);

    # We select files excluding files listed in the exclusion list
    foreach my $k (keys %$new_manifest) {
        my $nskip = _skipcheck(\%skips, $k);
        delete $new_manifest->{$k} if $nskip;
        debug("> [%s] %s", $nskip ? "SKIPPED" : " ADDED ", $k);
    }
    #debug(Data::Dumper::Dumper($new_manifest));

    # Save the created file
    debug("Saving manifest to %s", MANIFEST);
    return 0 unless maniwrite($self->{file_manifest}, $new_manifest);

    # Creating new META file
    debug("Generating new META file");
    # NOTE! The status in the META file is set only after the final directory structure
    # has been successfully generated. This change distinguishes already "working"
    # resources from those that have just been initialized.

lib/App/DistSync.pm  view on Meta::CPAN

        push @skip_keys, keys %$maniskip if ref($maniskip) eq 'HASH';
        for (@skip_keys) {$skips{$_} = qrreconstruct($_)}
        debug("Found %d keys in the list of skipped files", scalar(keys %skips));
    }

    # Getting list files from MANIFEST.DEL file but not in the exclusion list
    {
        debug("Getting list files from: %s", MANIDEL);
        my $delfile = $self->{file_manidel};  # MANIFEST.DEL
        my $dellist = maniread($delfile) // {}; # { file => expire };
        #debug(Data::Dumper::Dumper($dellist));

        # Check by exclusion list
        foreach my $k (keys %$dellist) {
            if (_skipcheck(\%skips, $k)) { # The file is in the exclusion list.
                debug("> [SKIPPED] %s", $k);
                next;
            }

            # Adding files listed in MANIFEST.DEL to the exclusion list
            $skips{$k} = qrreconstruct($k);
        }
        #debug(Data::Dumper::Dumper(\%skips));
    }

    # Cteating MANIFEST file
    debug("Generating new manifest");
    my $new_manifest = manifind($self->dir);

    # We select files excluding files listed in the exclusion list
    foreach my $k (keys %$new_manifest) {
        my $nskip = _skipcheck(\%skips, $k);
        delete $new_manifest->{$k} if $nskip;
        debug("> [%s] %s", $nskip ? "SKIPPED" : " ADDED ", $k);
    }
    #debug(Data::Dumper::Dumper($new_manifest));

    # Save the created file
    debug("Saving manifest to %s", MANIFEST);
    return 0 unless maniwrite($self->{file_manifest}, $new_manifest);

    # Ok
    return 1;
}

sub _check_lockfile { # Checking if a file is private



( run in 0.938 second using v1.01-cache-2.11-cpan-0d24bc4d141 )