summaryrefslogtreecommitdiff
path: root/bin/flushzips.pl
blob: 392e7823afdf36e67a179e5c73bf4127151c3d0f (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/perl

use localbucky;
use lib "/var/www/vhosts/carbonpictures.com/bucky/lib";
use Bucky1;

$dbh = DBI->connect ("DBI:mysql:$BUCKY_DB:localhost;mysql_read_default_file=$BUCKY_DB_CNF");

#our $dbh = DBI->connect ($dsn);
#our $DEBUG = 1;

my $threads = get_threads();
my ($zips, $zip_size) = find_all_zips($threads);
print STDERR scalar(@$zips)." in ".hushsize($zip_size)."\n";
foreach my $f (@$zips)
  {
  delete_file($f);
  }
$dbh->disconnect();

sub find_all_zips
  {
  my ($threads) = @_;
  my @zips;
  my $zip_size = 0;
  foreach my $t (@$threads)
  	{
    my $files = get_files($t->{id});
    my $zip_file = generate_zip_filename($t);
    foreach my $f (@$files)
      {
      next unless $f->{filename} eq $zip_file;
      push @zips, $f;
      $zip_size += $f->{size};
      }
	  }
  return \@zips, $zip_size;
  }

sub delete_file
  {
  my ($f) = @_;
  my $file_path = join "/", $data_path, $f->{thread}, $f->{filename};
  if (! -e $file_path)
    { 
    print STDERR "DNE: $file_path ...\n";
    return;
    }
  delete_file_record($f->{id});
  system($RM_PATH, "-f", $file_path);
  update_thread_size($f->{thread});
  print STDERR qq(deleted $file_path\n);
  }