diff options
author | Christian Pointner <equinox@helsinki.at> | 2010-04-22 16:51:07 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2010-04-22 16:51:07 (GMT) |
commit | 8feabec3db24134087b491e730d63a11127fee15 (patch) | |
tree | 0df01564b885c32df782fe3720e642de39a2a9b9 /rhimport.pm | |
parent | 41d257b2ba4f3a995acdaa3b57bbe991e939d0e5 (diff) |
temporary import now in seperate folder for each user
git-svn-id: https://svn.helsinki.at/rhimport/trunk@56 7c65635b-ec39-4f67-a626-873dbafdd612
Diffstat (limited to 'rhimport.pm')
-rw-r--r-- | rhimport.pm | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/rhimport.pm b/rhimport.pm index 948d675..b9a430a 100644 --- a/rhimport.pm +++ b/rhimport.pm @@ -150,7 +150,7 @@ sub clear_carts sub import_playlist { - my ($playlist, $dropbox, $progress_cb, $error_cb) = @_; + my ($playlist, $dropbox, $user, $progress_cb, $error_cb) = @_; print "Starting import from playlist $playlist to $dropbox"; my @entries; @@ -168,11 +168,12 @@ sub import_playlist my $cnt = 0; my $ret = 0; my $log = ""; + prepare_import($user); for my $entry ( @entries ) { $progress_cb->($cnt, $num_entries, $entry) if($progress_cb); my $out; - ($ret, $out) = import_file($entry, $dropbox, $error_cb); + ($ret, $out) = import_file($entry, $dropbox, $user, $error_cb); $log .= "\n--- $entry ---\n$out\n" if $out; last if($ret == 0); @@ -190,10 +191,11 @@ sub import_playlist sub import_single { - my ($file, $dropbox, $progress_cb, $error_cb) = @_; + my ($file, $dropbox, $user, $progress_cb, $error_cb) = @_; print "Starting import from file $file to $dropbox\n"; $progress_cb->(0, 1, $file) if($progress_cb); - my ($ret, $out) = import_file($file, $dropbox, $error_cb); + prepare_import($user); + my ($ret, $out) = import_file($file, $dropbox, $user, $error_cb); if($ret) { $progress_cb->(1, 1, "Import abgeschlossen!") if($progress_cb); } else { @@ -204,8 +206,8 @@ sub import_single sub scp_put_file { - my ($file) = @_; - my @cmd = ( 'scp', '-prqB', '-i', $ssh_key_file, $file, "$ssh_user\@$ssh_host:$ssh_dir/" ); + my ($file, $user, $host, $path) = @_; + my @cmd = ( 'scp', '-prqB', '-i', $ssh_key_file, $file, "$user\@$host:$path/" ); my ($reader, $writer, $error ) = ( new IO::Handle, new IO::Handle, new IO::Handle ); $writer->autoflush(1); local $SIG{CHLD} = 'DEFAULT'; @@ -236,15 +238,23 @@ sub ssh_exec_command return ($out, $errstr); } +sub prepare_import +{ + my ($user) = @_; + + ### create user directory + ssh_exec_command("umask 002; mkdir -p \"$ssh_dir/$user\""); +} + sub import_file { - my ($file, $dropbox, $error_cb) = @_; + my ($file, $dropbox, $user, $error_cb) = @_; print " - importing $file to $dropbox .. "; $| = 1; - ### copy file to master server and - my $err = scp_put_file($file); + ### copy file to master server + my $err = scp_put_file($file, $ssh_user, $ssh_host, "$ssh_dir/$user"); if($err ne "") { print "Transfer Error\n"; if($error_cb) { @@ -256,7 +266,7 @@ sub import_file ### remotely call rdimport my ($volume, $directories, $remote_file) = File::Spec->splitpath($file); - $remote_file = "$ssh_dir/$remote_file"; + $remote_file = "$ssh_dir/$user/$remote_file"; my ($out ,$error) = ssh_exec_command("$rdimport_wrapper --path \"$dropbox\" --file \"$remote_file\""); if($error ne "") { print "Import Error\n"; |