summaryrefslogtreecommitdiff
path: root/rhimport.pm
diff options
context:
space:
mode:
Diffstat (limited to 'rhimport.pm')
-rw-r--r--rhimport.pm34
1 files changed, 21 insertions, 13 deletions
diff --git a/rhimport.pm b/rhimport.pm
index 264119d..f96f7b4 100644
--- a/rhimport.pm
+++ b/rhimport.pm
@@ -102,7 +102,7 @@ sub get_used_carts
sub clear_carts
{
- my ($dbh, $group, $to_cart) = @_;
+ my ($dbh, $group, $to_cart, $error_cb) = @_;
my ($low_cart, $high_cart) = ($to_cart, $to_cart);
if($to_cart == 0) {
@@ -116,6 +116,7 @@ sub clear_carts
my $sth = $dbh->prepare($sql);
$sth->execute();
while(my $cut_name = $sth->fetchrow_array()) {
+## TODO: Error handling would be nice!
delete_file("/var/snd/$cut_name.wav");
}
$sth->finish();
@@ -136,7 +137,7 @@ sub clear_carts
sub import_playlist
{
- my ($playlist, $dropbox, $progress_cb) = @_;
+ my ($playlist, $dropbox, $progress_cb, $error_cb) = @_;
print "Starting import from playlist $playlist to $dropbox";
my @entries;
@@ -158,8 +159,8 @@ sub import_playlist
$progress_cb->($cnt, $num_entries, $entry);
}
- $ret = import_file($entry, $dropbox);
- last if($ret ne "");
+ $ret = import_file($entry, $dropbox, $error_cb);
+ last if($ret == 0);
$cnt++;
}
@@ -173,12 +174,12 @@ sub import_playlist
sub import_single
{
- my ($file, $dropbox, $progress_cb) = @_;
+ my ($file, $dropbox, $progress_cb, $error_cb) = @_;
print "Starting import from file $file to $dropbox\n";
if($progress_cb) {
$progress_cb->(0, 1, $file);
}
- my $ret = import_file($file, $dropbox, $progress_cb);
+ my $ret = import_file($file, $dropbox, $error_cb);
if($progress_cb) {
$progress_cb->(1, 1, "Import abgeschlossen!");
@@ -219,7 +220,7 @@ sub ssh_exec_command {
sub import_file
{
- my ($file, $dropbox) = @_;
+ my ($file, $dropbox, $error_cb) = @_;
print " - importing $file to $dropbox .. ";
$| = 1;
@@ -228,21 +229,28 @@ sub import_file
my $err = scp_put_file($file);
if($err ne "") {
print "Transfer Error\n";
- return $err;
+ if($error_cb) {
+ return $error_cb->($err);
+ }
+ return 0;
}
print "transferred .. ";
- ### remotly call rdimport
+ ### remotely call rdimport
my ($volume, $directories, $remote_file) = File::Spec->splitpath($file);
$remote_file = "$ssh_dir/$remote_file";
my ($out ,$error) = ssh_exec_command("$rdimport_wrapper --path \"$dropbox\" --file \"$remote_file\"");
if($error ne "") {
print "Import Error\n";
- return $error;
+ delete_file($remote_file);
+ if($error_cb) {
+ return $error_cb->($err);
+ }
+ return 0;
}
print "imported OK\n";
- return "";
+ return 1;
}
sub delete_file
@@ -252,9 +260,9 @@ sub delete_file
print " - deleting $filename\n";
my ($out ,$err) = ssh_exec_command("rm \"$filename\"");
if($err ne "") {
- return 1;
+ return 0;
}
- return 0;
+ return 1;
}
1;