minisync/r.pl

22 lines
667 B
Perl
Raw Normal View History

2010-09-27 13:40:21 +02:00
#!/usr/bin/env perl
2010-09-27 15:34:24 +02:00
while( read( STDIN, my $data, 6)) {
2010-09-27 13:40:21 +02:00
my( $cmd, $length) = unpack 'nN', $data;
read STDIN, my $data, $length;
if( 1 == $cmd) {
2010-09-27 15:34:24 +02:00
print STDERR "{proc: \"r\", action: \"open_file\", file: \"$data\"}\n";
open( F, '>>', $data) or print STDERR ("{proc: \"r\", error: \"unable_to_open_file\", message: \"Can't open file <$data>.\"}\n");
2010-09-27 13:40:21 +02:00
my( $dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = stat F;
print pack( 'N', $size);
}
elsif( 2 == $cmd) {
2010-09-27 15:34:24 +02:00
print F $data;
}
else {
die( "{proc: \"r\", error: \"unknown_command\", command: $cmd}\n");
2010-09-27 13:40:21 +02:00
}
}
2010-09-27 15:34:24 +02:00
print STDERR "{proc: \"r\", exit: 0}\n";
exit 0;