App-Followme

 view release on metacpan or  search on metacpan

lib/App/Followme/UploadSite.pm  view on Meta::CPAN

    foreach my $filename (@$files) {
        # Skip check if in quick mode and modification date is old

        if ($self->{quick_update}) {
            next if $self->{target_date} > fio_get_date($filename);
        }

        my $file = abs2rel($filename, $self->{top_directory});
        delete $local->{$file} if exists $local->{$file};

        my $value = ${$self->{data}->build('checksum', $filename)};

        # Add file if new or changed

        if (! exists $hash->{$file} || $hash->{$file} ne $value) {
            if ($self->update_file($filename)) {
                $hash->{$file} = $value;
                print "add $file\n" if $self->{verbose};
            }
        }
    }

    # Recursively check each of the subdirectories

    my $folders = $self->{data}->build('folders', $folder);
    foreach my $subfolder (@$folders) {
        $self->update_folder($subfolder, $hash, $local);
    }

    return;
}

#----------------------------------------------------------------------
# Write the hash back to a file

sub write_hash_file {
    my ($self, $hash) = @_;

    my @hash_list;
    while (my ($name, $value) = each(%$hash)) {
        push(@hash_list, "$name\t$value\n");
    }

    my $filename = catfile($self->{top_directory},
                           $self->{state_directory},
                           $self->{hash_file});

    fio_write_page($filename, join('', @hash_list));

    return;
}

#----------------------------------------------------------------------
# WRITE_WORD -- Write the secret word to a file

sub write_word {
    my ($self, $filename, $user, $pass) = @_;

    my $obstr = $self->obfuscate ($user, $pass);
    fio_write_page($filename, "$obstr\n");
    chmod (0600, $filename);

    return;
}

1;
__END__

=encoding utf-8

=head1 NAME

App::Followme::UploadSite - Upload changed and new files

=head1 SYNOPSIS

    my $app = App::Followme::UploadSite->new(\%configuration);
    $app->run($folder);

=head1 DESCRIPTION

This module uploads changed files to a remote site. The default method to do the
uploads is ftp, but that can be changed by changing the parameter upload_pkg.
This package computes a checksum for every file in the site. If the checksum has
changed since the last time it was run, the file is uploaded to the remote site.
If there is a checksum, but no local file, the file is deleted from the remote
site. If this module is run in quick mode, only files whose modification date is
later then the last time it was run are checked.

=head1 CONFIGURATION

The following fields in the configuration file are used:

=over 4

=item credentials

The name of the file which holds the user name and password for the remote site
in obfuscated form. Te default name is 'upload.cred'.

=item hash_file

The name of the file containing all the checksums for files on the site. The
default name is 'upload.hash'.

=item max_errors

The number of upload errors the module tolerate before quitting. The default
value is 5.

=item remote_url

The url of the remote website, e.g. http://www.cloudhost.com.

=item state_directory

The name of the directory containing the credentials and hash file. This
directory name is relative to the top directory of the site. The default
name is '_state'.

=item upload_pkg



( run in 1.977 second using v1.01-cache-2.11-cpan-98e64b0badf )