summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOthmar Gsenger <otti@wirdorange.org>2013-01-22 23:29:42 +0000
committerOthmar Gsenger <otti@wirdorange.org>2013-01-22 23:29:42 +0000
commit82e293464270475fab3cf0e34cb9562862842dcf (patch)
treefedf531e66920b071f2a1fe675f143e88b937585
parentremoved languge request to speed up nzbindex (diff)
added detection of broken and missing downloads
-rwxr-xr-xcron/read_filesize_from_filesystem.pl26
1 files changed, 24 insertions, 2 deletions
diff --git a/cron/read_filesize_from_filesystem.pl b/cron/read_filesize_from_filesystem.pl
index 702ddb4..a4bc86c 100755
--- a/cron/read_filesize_from_filesystem.pl
+++ b/cron/read_filesize_from_filesystem.pl
@@ -3,14 +3,36 @@ use strict;
use Cwd 'abs_path';
use File::Basename;
use local::db;
+use File::Copy;
use config;
-
+my %seen;
for my $dl (local::db::download->retrieve_all)
{
- my $du = "du -sm ".$config::config{files_dir}.'/'.$dl->category->name.'/'.$dl->download_id;
+ my $dir = $config::config{files_dir}.'/'.$dl->category->name.'/'.$dl->download_id;
+ if (not -d $dir)
+ {
+ warn "Download dir is missing: $dir";
+ }
+ my $du = "du -sm $dir";
+ $seen{$dl->category->name}{$dl->download_id} = 1;
my $du_resp = `$du`;
my ($size) = $du_resp =~ /^(\d+)/;
# warn $size;
$dl->size($size);
$dl->update;
}
+
+for my $category (keys %seen)
+{
+ opendir(my $dh, $config::config{files_dir}.'/'.$category) || next;
+ while(readdir $dh) {
+ next if /^\.\.?$/;
+ if (not $seen{$category}{$_})
+ {
+ #warn "invisible download ".$config::config{files_dir}."/$category/$_";
+ mkdir($config::config{files_dir}."/broken/$category");
+ move($config::config{files_dir}."/$category/$_",$config::config{files_dir}."/broken/$category/$_");
+ }
+ }
+ closedir $dh;
+}