Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update individual file information after syncing and set static ip addresses for vagrant machines #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions FileSync/SyncDiff/DB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ sub process_request {
return $self->_clean_stop();
}

if( $request->{operation} eq "delete_file" ){
return $self->_delete_file( $request->{file} );
}

} # end process_request()

sub clean_stop {
Expand Down Expand Up @@ -362,14 +366,19 @@ sub send_request {
}

## print Dumper $line;

chomp( $line );
if (defined $line) {
chomp( $line );
}

## print "Got response\n";

## print "*** DB->send_request() - return line:\n";
## print Dumper $line;

if (!(defined $line)) {
return 0;
}

if( $line eq "0" ){
return 0;
}
Expand Down Expand Up @@ -746,6 +755,51 @@ sub _mark_deleted {
return 0;
} # end _mark_deleted()

sub delete_file {
my( $self, $file ) = @_;

my %file_hash = $file->to_hash();

my %request = (
operation => 'delete_file',
file => \%file_hash,
);

my $response = $self->send_request( %request );
} # end delete_file()

sub _delete_file {
my( $self, $file ) = @_;
my $dbh = $self->dbh;

my $file_obj = FileSync::SyncDiff::File->new(dbref => $self );
$file_obj->from_hash( $file );

## print "Marking deleted:\n";
## print "\tlast transaction: ". $file_obj->last_transaction ."\n";
## print "\tFilepath: ". $file_obj->filepath ."\n";
## print "\tsyncgroup: ". $file_obj->syncgroup ."\n";
## print "\tsyncbase: ". $file_obj->syncbase ."\n";

my $sql = "DELETE FROM files WHERE filepath=? and syncgroup=? and syncbase=?";

## print "\tSQL: ". $sql ."\n";

my $delete_file_sth = $dbh->prepare($sql);

$delete_file_sth->execute(
$file_obj->filepath,
$file_obj->syncgroup,
$file_obj->syncbase
);

if ( $delete_file_sth->err ){
die "ERROR! return code: ". $delete_file_sth->err . " error msg: " . $delete_file_sth->errstr . "\n";
}

return 0;
} # end _delete_file()

sub update_file {
my( $self, $file ) = @_;

Expand Down
25 changes: 23 additions & 2 deletions FileSync/SyncDiff/Protocol/v1.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use PerlIO::scalar;
use File::Temp qw/ tempfile tempdir /;
use File::Copy;
use Digest::SHA qw(sha256 sha256_hex sha256_base64);
use File::Basename;

#
# Debugging
Expand Down Expand Up @@ -203,6 +204,13 @@ sub get_updates_from_remote {
next;
}

if ($temp_file->deleted) {
$temp_file->{syncbase} = $self->groupbase;
$self->dbref->delete_file($temp_file);
unlink $temp_file->filepath;
next;
}

if( ( $pid = fork() ) == 0 ){
# child process
print "V1: About to chroot to - |". $self->groupbase ."|\n";
Expand Down Expand Up @@ -238,7 +246,7 @@ sub get_updates_from_remote {
#file exists, we should compare things before we get too far here.... *BUT* I don't want to deal with that code quite yet
#}
if( $temp_file->filetype eq "file" ){
$self->sync_file( $temp_file->path, $temp_file->filename, $temp_file->filepath, $temp_file->checksum );
$self->sync_file( $temp_file->path, $temp_file->filename, $temp_file->filepath, $temp_file->checksum, $temp_file->last_transaction);
}

exit(0);
Expand Down Expand Up @@ -298,11 +306,13 @@ sub get_updates_from_remote {
} # end get_updates_from_remote()

sub sync_file {
my( $self, $path, $filename, $filepath, $checksum) = @_;
my( $self, $path, $filename, $filepath, $checksum, $last_transaction ) = @_;

my $sig_buffer = undef;
my $basis = undef;
my $sig = undef;
my $dbref = $self->dbref;
my $new_file_flag = 0;

print "Going to sync the file $filepath\n";

Expand Down Expand Up @@ -331,6 +341,7 @@ sub sync_file {
if( ! -e $filepath ){
open HANDLE, ">>$filepath" or die "touch $filepath: $!\n";
close HANDLE;
$new_file_flag = 1;
}

open $basis, "<", $filepath or die "$filepath - $!";
Expand Down Expand Up @@ -478,6 +489,16 @@ sub sync_file {

move( $new_path, $filepath );

($new_file_obj->{filename}, $new_file_obj->{path}) = fileparse($filepath);
$new_file_obj->{last_transaction} = $last_transaction;

if ($new_file_flag) {
$dbref->add_file($new_file_obj);
}
else {
$dbref->update_file($new_file_obj);
}

} # end sync_file

sub _get_files_changed_since {
Expand Down
2 changes: 1 addition & 1 deletion FileSync/SyncDiff/Scanner.pm
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ sub find_wanted {
#

# prep the object since it's obviously changed
$found_file_obj->checksum();
$found_file_obj->checksum_file();
$found_file_obj->last_transaction( $self->current_transaction_id() );

# update the file in the database
Expand Down
4 changes: 4 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Set up two machines
config.vm.define "server0" do |server0|
server0.vm.box = "CentOS-6.4-x86_64-v20130731"
server0.vm.network "private_network", ip: "192.168.0.2"
server0.vm.provision "shell", inline: "echo -e '192.168.0.2\tserver0\n192.168.0.3\tserver1' >> /etc/hosts", privileged: "true"
end

config.vm.define "server1" do |server1|
server1.vm.box = "CentOS-6.4-x86_64-v20130731"
server1.vm.network "private_network", ip: "192.168.0.3"
server1.vm.provision "shell", inline: "echo -e '192.168.0.2\tserver0\n192.168.0.3\tserver1' >> /etc/hosts", privileged: "true"
end

# Create a forwarded port mapping which allows access to a specific port
Expand Down