blob: c68c3241bc4ae53bb38d674f8aa4f2d4944fed04 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#!/usr/bin/perl
use strict;
use Cwd 'abs_path';
use File::Basename;
use local::db;
use File::Copy;
use File::Path;
use config;
my %seen;
for my $dl (local::db::download->retrieve_all)
{
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(my $file = readdir $dh) {
next if $file =~ /^\.\.?$/;
next if not $file;
if (not $seen{$category}{$file})
{
#warn "invisible download ".$config::config{files_dir}."/$category/$file";
if ($config::config{purge_broken})
{
rmtree($config::config{files_dir}."/$category/$file");
} else {
mkpath($config::config{files_dir}."/broken/$category");
move($config::config{files_dir}."/$category/$file",$config::config{files_dir}."/broken/$category/$file");
}
}
}
closedir $dh;
}
|