# ftp.gnu.org does not allow overwrites or deletes.
#
sub scan_incoming {
- my @ret;
+ my $directory = shift;
+ my $scratchpad = shift;
+
my %possible;
# Get list of all possible files from incoming dir.
#
- opendir (INCOMING, $incoming_dir)
- or ftp_die("FATAL opendir($incoming_dir) failed: $!");
+ opendir (INCOMING, $directory)
+ or ftp_die("FATAL opendir($directory) failed: $!");
while (my $tainted_ent = readdir (INCOMING)) {
# don't look at files with a leading dot or dash, but allow those chars
# subsequently. Omit files containing any other weird characters.
$possible{$ent} = 1;
}
closedir (INCOMING)
- or ftp_die("FATAL: closedir($incoming_dir) failed: $!");
+ or ftp_die("FATAL: closedir($directory) failed: $!");
# No possible files found, so return before we call lsof
return () unless %possible;
# the open files because they are owned by another user.
# On modern (Debian) systems, condition a) is not met.
my @lsof_args = (LSOF_BIN, "-Fn",
- map { "$incoming_dir/$_" } keys %possible);
+ map { "$directory/$_" } keys %possible);
ftp_syslog('debug', "DEBUG: "
."lsof command line: " . join(' ',@lsof_args))
if DEBUG;
ftp_syslog('debug', "DEBUG: " . "lsof output: $line")
if DEBUG;
# only look at the name lines.
- next unless $line =~ /^n${incoming_dir}\/(.+)$/;
+ next unless $line =~ /^n${directory}\/(.+)$/;
ftp_syslog('debug', "DEBUG: "
."upload in progress for $1, ignoring during this run")
if DEBUG;
}
}
+ my @ret;
+
# For each remaining possibility, do some more checks
for my $ent (keys %possible) {
my $base = $ent;
# consume lots of memory reading it.
if (exists($possible{$base}) && exists($possible{$sig})
&& exists($possible{$directive})
- && (-s "$incoming_dir/$directive" < 50*1024)
- && (-s "$incoming_dir/$sig" < 50*1024)) {
+ && (-s "$directory/$directive" < 50*1024)
+ && (-s "$directory/$sig" < 50*1024)) {
push (@ret, { "directive" => $directive, "sig" => $sig,
"upload" => $base, "directive_only" => 0 });
ftp_syslog('info', "processing [$directive:$sig:$base]");
# anything, for safety.
#
for my $f (($directive, $sig, $base)) {
- rename ($f, "$incoming_tmp/$f")
- or fatal("rename $incoming_dir/$f to $incoming_tmp/$f failed: $!",0);
+ rename ($f, "$scratchpad/$f")
+ or fatal("rename $directory/$f to $scratchpad/$f failed: $!",0);
}
# don't bother to try any part of this triple again.
# Here we have a potential problem. It's possible that we are seeing a
# directive file that belongs to a triplet the rest of which has not been
# uploaded yet. If so, we should ignore this file and not move it to
- # $incoming_dir. This means we need to read the file and see if there is a
+ # $directory. This means we need to read the file and see if there is a
# 'filename:' directive.
my $racecondition = 0;
"upload" => '', "directive_only" => 1 });
# Do atomic rename to temp incoming directory before reading
# anything, for safety.
- rename ($base, "$incoming_tmp/$base")
- or fatal("rename $incoming_dir/$base "
- ."to $incoming_tmp/$base failed: $!",0);
+ rename ($base, "$scratchpad/$base")
+ or fatal("rename $directory/$base "
+ ."to $scratchpad/$base failed: $!",0);
}
delete $possible{$base};
} elsif ((-f $directive) && ((-s $directive) >= MAX_DIRECTIVE_SIZE)) {
- rename ("$incoming_dir/$directive", "$incoming_dir/.$directive");
+ rename ("$directory/$directive", "$directory/.$directive");
ftp_syslog('info', "directive file ($directive) larger than 50KB");
fatal("The directive file $directive is larger than 50KB. "
."This can not be correct, ignoring upload.",0);
} elsif ((-f $sig) && ((-s $sig) >= MAX_SIGNATURE_SIZE)) {
- rename ("$incoming_dir/$sig", "$incoming_dir/.$sig");
+ rename ("$directory/$sig", "$directory/.$sig");
ftp_syslog('info', "signature file ($sig) larger than 50KB");
fatal("The signature file $sig is larger than 50KB. "
."This can not be correct, ignoring upload.",0);
# have any directory.
chdir ($incoming_dir)
or ftp_die("FATAL: chdir($incoming_dir) failed: $!");
-my @incoming = scan_incoming ();
+my @incoming = scan_incoming ($incoming_dir, $incoming_tmp);
# we've moved the files to work on to a new directory.