From 8feabec3db24134087b491e730d63a11127fee15 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 22 Apr 2010 16:51:07 +0000 Subject: temporary import now in seperate folder for each user git-svn-id: https://svn.helsinki.at/rhimport/trunk@56 7c65635b-ec39-4f67-a626-873dbafdd612 diff --git a/rhimport b/rhimport index 64694f4..8b2b3f0 100755 --- a/rhimport +++ b/rhimport @@ -267,12 +267,12 @@ sub start_import_gui() $log = rhimport::clear_carts($dbh, $group, $to_cart, $gui_progress_cb); } my $import_log; - ($ret, $import_log) = rhimport::import_playlist($file, $dropbox, $gui_progress_cb, $gui_error_cb); + ($ret, $import_log) = rhimport::import_playlist($file, $dropbox, $user, $gui_progress_cb, $gui_error_cb); $log .= $import_log; } else { $log = rhimport::clear_carts($dbh, $group, $to_cart, $gui_progress_cb); my $import_log; - ($ret, $import_log) = rhimport::import_single($file, $dropbox, $gui_progress_cb, $gui_error_cb); + ($ret, $import_log) = rhimport::import_single($file, $dropbox, $user, $gui_progress_cb, $gui_error_cb); $log .= $import_log; } @@ -443,12 +443,12 @@ if($POOL) { } my $import_log; - ($ret, $import_log) = rhimport::import_playlist($FILE, $DROPBOX, 0, $cl_error_cb); + ($ret, $import_log) = rhimport::import_playlist($FILE, $DROPBOX, $user, 0, $cl_error_cb); $log .= $import_log; } else { $log = rhimport::clear_carts($dbh, $group, $to_cart); my $import_log; - ($ret, $import_log) = rhimport::import_single($FILE, $DROPBOX, 0); + ($ret, $import_log) = rhimport::import_single($FILE, $DROPBOX, $user, 0, $cl_error_cb); $log .= $import_log; } 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"; -- cgit v0.10.2