sub situate_imports { my ($pid, $uname) = @_; my ($filename, $size, $date); my $newfilename; my $tempsubdir; my $totalsize = 0; my @stats; open T, ">$temp_path/.importnow"; close T; system($SYSTEM_CHMOD, "0777", "$temp_path/.importnow"); print "Waiting to import...
" if ($DEBUG); while (-e "$temp_path/.importnow") { sleep(1); } print "Setting permissions...
" if ($DEBUG); while (-e "$temp_path/.importing") { sleep(1); } print "Ready to import!
" if ($DEBUG); foreach my $k (keys %$input) { next if ($k !~ /^imp/); next if (! -e $temp_path."/".$$input{$k}); $filename = $$input{$k}; if (! -e $data_path."/".$pid) { print "creating $data_path/$pid
\n" if $DEBUG; system("$MKDIR_PATH", $data_path."/".$pid); system("$MKDIR_PATH", $data_path."/".$pid."/.thumb"); system("$CHMOD_PATH", "755", $data_path."/".$pid); system("$CHMOD_PATH", "755", $data_path."/".$pid."/.thumb"); } print $filename."
" if ($DEBUG); @stats = stat($temp_path."/".$filename); $size = $stats[7]; $date = $stats[9]; $newfilename = $filename; $newfilename =~ s/^(.*)\///; $tempsubdir = $1; if (-e $data_path."/".$pid."/".$newfilename) { my $tfile = "another-$newfilename"; my $i = 2; while (-e $data_path."/".$pid."/".$tfile) { $tfile = $newfilename; $tfile =~ s/(\....)$/-$i$1/; $i++; } $newfilename = $tfile; } system($MV_PATH, $temp_path."/".$filename, $data_path."/".$pid."/".$newfilename); add_file($pid, $uname, $newfilename, $size, $date); $totalsize += $size; } update_thread_size($pid); flush_imports($tempsubdir); } sub flush_imports { while ($tsd) { foreach my $d (recurse_imports($temp_path."/".$tsd."/")) { if (! -d $temp_path."/".$tsd."/".$d) { print "Files still in $tsd, will not flush!
" if $DEBUG; return; } } system($RM_PATH, "-rf", $temp_path."/".$tsd); return if ($tsd !~ /\//); $tsd =~ s/^(.*)\///; $tsd = $1; } } sub list_imports { my $r = 0; my $i = 0; my $size = 0; my $inc = 0; my $title = ""; my $files; print < FILES @files = recurse_imports($temp_path."/"); foreach $file (sort @files) { if (-d $temp_path."/".$file) { if ($file =~ /$title\//) { $file =~ s/^.*\///; $title .= " - $file"; } else { $title = $file; } next; } my @stats = stat($temp_path."/".$file); $inc += display_import({filename => $file, date => $stats[9], size => $stats[7]}, $r, $i); $size += $stats[7]; $r = $r ? 0 : 1; $i++; } print qq!
   Name Date  Size 
total size: !.(sprintf "%0.1fmb",$size/1000000).qq!
\n\n!; return ($title, $inc, $size); } sub recurse_imports { my $d = shift; return unless (-d $d); my @files; opendir (DIR, $d) or die "couldn't list: $d, $!"; @files = grep (!/^\./, sort readdir (DIR)); closedir DIR; foreach my $f (@files) { push @files, map { $f . "/" . $_ } recurse_imports($d.$f); } return @files; } sub display_import { my ($f, $r, $i) = @_; my $color; my $inc = 0; if (abs(time - $$f{date}) < 5) # incomplete! use abs in case these are files from THE FUTURE! { $color = "incomplete"; $inc = 1; } elsif ((time - $$f{date}) < 86400) # modified today { $color = "new"; } elsif ((time - $$f{date}) < 604800) # modifed this week { $color = "recent"; } elsif ((time - $$f{date}) < 1209600) # modifed 2 weeks ago { $color = "old"; } else { $color = "quiet"; } print qq[]; if ($color eq "incomplete") { print qq[ ]; print ''; print qq[ $$f{filename}]; print qq[]. (verbosedate($$f{date})), qq[]; print qq[ $$f{size} ]; } else { if ($f->{filename} =~ /^temp_/) { print qq[ ]; } else { print qq[]; } if ($f->{filename} =~ /jpg|gif|png$/) { #print ""; print ''; } else { print ''; } print qq[ ]; print qq[$$f{filename}]; print qq[]. (verbosedate($$f{date})), qq[]; print qq[ $$f{size} ]; } print qq[\n]; return $inc; } 1;