summaryrefslogtreecommitdiff
path: root/cron/read_filesize_from_filesystem.pl
blob: a4bc86c02da9dd7c2f91e7a017a674774328741b (plain)
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
#!/usr/bin/perl
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 $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;
}