minisync/s.pl

31 lines
988 B
Perl
Raw Normal View History

2010-09-27 13:40:21 +02:00
#!/usr/bin/env perl
2010-09-27 16:33:31 +02:00
use strict;
use warnings;
$|++;
my$dir = shift @ARGV;
$dir =~ /^(\/.*)\/([^\/]+)$/ or die( "{proc: \"s\", error: \"invalid_path_expression\", message: \"Path-Expression is invalid.\"}\n");
($dir, my$fexpr) = ($1, $2);
2010-09-27 15:34:24 +02:00
chdir( $dir) or die( "{proc: \"s\", error: \"change_directory\", value: \"$dir\", message: \"$!\"}\n");
2010-09-27 16:33:31 +02:00
opendir( my$dh, '.') || die "{proc: \"s\", error: \"dir_not_found\", message: \"Directory not found.\"}\n";
while( my$filename = readdir( $dh)) {
2010-09-27 15:34:24 +02:00
$filename =~ /$fexpr/ or next;
2010-09-27 16:33:31 +02:00
-f $filename or next;
2010-09-27 16:42:03 +02:00
print pack( 'nN/A*', 1, $filename);
2010-09-27 15:34:24 +02:00
print STDERR "{proc: \"s\", action: \"open\", file: \"$filename\"}\n";
2010-09-27 13:40:21 +02:00
open F, $filename;
2010-09-27 16:33:31 +02:00
read STDIN, my$length, 4; # Was wenn < 4 ?
$length = unpack 'N', $length;
seek F, $length, 0;
2010-09-27 16:42:03 +02:00
while( read( F, my$r, 2040)) {
print pack( 'nN/A*', 2, $r);
2010-09-27 16:33:31 +02:00
}
2010-09-27 15:34:24 +02:00
print STDERR "{proc: \"s\", action: \"close\", file: \"$filename\"}\n";
2010-09-27 13:40:21 +02:00
close F;
}
closedir $dh;
2010-09-27 15:34:24 +02:00
print STDERR "{proc: \"s\", exit: 0}\n";
exit(0);