# - Main execution path
#
-exit (&main ());
+# Initialize our syslogging
+if (IN_TEST_MODE) {
+ $ENV{TEST_SYSLOG_SOCKET} =~ m/^([[:alnum:]\/]+)$/
+ or die "strange test syslog socket";
+ -S $1 or die "test syslog socket is not a socket";
+ setlogsock(unix => $1);
+}
+openlog("ftp-upload", 'pid', $facility);
+ftp_syslog('info', "($log_style) Beginning upload processing run.");
+
+# make sure our directories all exist, or it's hopeless.
+# Use die instead of fatal - this error should "never" happen.
+for my $dir ($package_config_base, $incoming_dir, $incoming_tmp,
+ $destfinal, $desttmp) {
+ -d $dir || ftp_die("FATAL: configuration problem, $dir is not a directory");
+}
+# the chdir simplifies our filename parsing, so the base names don't
+# have any directory.
+chdir ($incoming_dir) || ftp_die("FATAL: chdir($incoming_dir) failed: $!");
+my @incoming = &scan_incoming ();
-sub main
-{
- # Initialize our syslogging
- if (IN_TEST_MODE) {
- $ENV{TEST_SYSLOG_SOCKET} =~ m/^([[:alnum:]\/]+)$/
- or die "strange test syslog socket";
- -S $1 or die "test syslog socket is not a socket";
- setlogsock(unix => $1);
- }
- openlog("ftp-upload", 'pid', $facility);
- ftp_syslog('info', "($log_style) Beginning upload processing run.");
-
- # make sure our directories all exist, or it's hopeless.
- # Use die instead of fatal - this error should "never" happen.
- for my $dir ($package_config_base, $incoming_dir, $incoming_tmp,
- $destfinal, $desttmp) {
- -d $dir || ftp_die("FATAL: configuration problem, $dir is not a directory");
- }
- # the chdir simplifies our filename parsing, so the base names don't
- # have any directory.
- chdir ($incoming_dir) || ftp_die("FATAL: chdir($incoming_dir) failed: $!");
- my @incoming = &scan_incoming ();
-
-
- # we've moved the files to work on to a new directory.
- chdir ($incoming_tmp) || ftp_die("FATAL: chdir($incoming_tmp) failed: $!");
-
- for my $files (@incoming) { # each list element is a hash reference.
- ftp_syslog('info',"($log_style) found directive: $files->{directive}\n");
- # if we die processing a triplet, the eval allows us to move
- # onto the next triplet.
- eval {
- # set up the %info variable
- my $retval = &read_directive_file ($files->{"directive"},$files->{"upload"},$files->{"directive_only"});
-
- if ($retval == 0) {
- # do the work
- &execute_commands($files,%info);
-
- # report success
- if (!$files->{"directive_only"}) {
- &success_upload($files->{"sig"}, $files->{"upload"},$files->{"directive"});
- } else {
- &success_directive($files->{directive});
- }
- }
- };
- ftp_warn ("eval failed: $@") if $@;
+# we've moved the files to work on to a new directory.
+chdir ($incoming_tmp) || ftp_die("FATAL: chdir($incoming_tmp) failed: $!");
- # clean up files if we abort while processing a triplet
- cleanup ($files->{"sig"}, $files->{"upload"}, $files->{"directive"}) if ($@);
- # clear out the current package that we just finished processing
- undef %info;
- }
- if ((scalar @incoming) == 0) {
- ftp_syslog('info', "($log_style) No files found for processing.");
- } else {
- ftp_syslog('info', "($log_style) Processing complete: " . (scalar @incoming) . " uploads processed.");
- system("/usr/local/bin/generate-ftpindex") unless IN_TEST_MODE;
- ftp_syslog('info', "($log_style) Updated ftpindex");
- }
+for my $files (@incoming) { # each list element is a hash reference.
+ ftp_syslog('info',"($log_style) found directive: $files->{directive}\n");
+ # if we die processing a triplet, the eval allows us to move
+ # onto the next triplet.
+ eval {
+ # set up the %info variable
+ my $retval = &read_directive_file ($files->{"directive"},$files->{"upload"},$files->{"directive_only"});
- # Clean up the incoming directory and the incoming tmp directory - remove files older than a day
- cleanup_dir($incoming_dir);
- cleanup_dir($incoming_tmp);
+ if ($retval == 0) {
+ # do the work
+ &execute_commands($files,%info);
- return 0;
+ # report success
+ if (!$files->{"directive_only"}) {
+ &success_upload($files->{"sig"}, $files->{"upload"},$files->{"directive"});
+ } else {
+ &success_directive($files->{directive});
+ }
+ }
+ };
+ ftp_warn ("eval failed: $@") if $@;
+
+ # clean up files if we abort while processing a triplet
+ cleanup ($files->{"sig"}, $files->{"upload"}, $files->{"directive"}) if ($@);
+ # clear out the current package that we just finished processing
+ undef %info;
+}
+if ((scalar @incoming) == 0) {
+ ftp_syslog('info', "($log_style) No files found for processing.");
+} else {
+ ftp_syslog('info', "($log_style) Processing complete: " . (scalar @incoming) . " uploads processed.");
+ system("/usr/local/bin/generate-ftpindex") unless IN_TEST_MODE;
+ ftp_syslog('info', "($log_style) Updated ftpindex");
}
+# Clean up the incoming directory and the incoming tmp directory - remove files older than a day
+cleanup_dir($incoming_dir);
+cleanup_dir($incoming_tmp);
+
+exit 0;
+
__END__