more verbose

This commit is contained in:
Denis Knauf 2010-09-27 15:34:24 +02:00
parent 46cd565e34
commit 7d602e5e31
3 changed files with 49 additions and 13 deletions

29
c.rb
View file

@ -1,14 +1,39 @@
#!/usr/bin/env ruby
class IO
def readall
buf = ''
loop do
buf << begin
self.sysread 4096
rescue EOFError
return buf
end
end
end
end
class String
def shdump
"'#{gsub( /[\\']/, '\'\\\\\&\'')}'"
end
end
class File
def self.readall file
open( file) {|f| f.readall }
end
end
tor = IO.pipe
tos = IO.pipe
fork do
$stdin.reopen tor.first
$stdout.reopen tos.last
exec 'ssh', ARGV[0], 'perl', 'r.pl', ARGV[1]
exec 'ssh', ARGV[0], 'perl', '-e', File.readall( 's.pl').shdump, ARGV[1].shdump
end
$stdin.reopen tos.first
$stdout.reopen tor.last
exec 'perl', 's.pl', ARGV[2]
exec 'perl', 'r.pl', ARGV[2].shdump

15
r.pl
View file

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

18
s.pl
View file

@ -1,17 +1,25 @@
#!/usr/bin/env perl
my $dir = shift @ARGS;
$dir =~ /^(\/.*)\/[^/]*$/ or die( '{error: "invalid_path_expression", message: "Path-Expression is invalid."}');
$dir, my $fexpr = $1, $2;
$fexpr = /$fexpr/;
my $dir = shift @ARGV;
$dir =~ /^(\/.*)\/([^\/]+)$/ or die( "{proc: \"s\", error: \"invalid_path_expression\", message: \"Path-Expression is invalid.\"}\n");
($dir, my( $fexpr)) = ($1, $2);
opendir( my $dh, $dir) || die '{error: "dir_not_found", message: "Directory not found."}';
print STDERR $fexpr;
chdir( $dir) or die( "{proc: \"s\", error: \"change_directory\", value: \"$dir\", message: \"$!\"}\n");
opendir( my( $dh), '.') || die "{proc: \"s\", error: \"dir_not_found\", message: \"Directory not found.\"}\n";
while( $filename = readdir( $dh)) {
print STDERR "{proc: \"s\", action: \"find\", file: \"$filename\"}\n";
$filename =~ /$fexpr/ or next;
print pack( 'nN/(A*)', 1, $filename);
print STDERR "{proc: \"s\", action: \"open\", file: \"$filename\"}\n";
open F, $filename;
read STDIN, my $length, 4; # Was wenn < 4 ?
seek F, $length, SEEK_SET;
print pack( 'nN/(A*)', 2, $r) while read( F, $r, 2048);
print STDERR "{proc: \"s\", action: \"close\", file: \"$filename\"}\n";
close F;
}
closedir $dh;
print STDERR "{proc: \"s\", exit: 0}\n";
exit(0);