From d5765dc9bb84323b41f84ec73f4c4ccc3dd1dd30 Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Mon, 3 Apr 2023 21:12:00 -0500 Subject: [PATCH] Fix misunderstanding in FTP index builder --- gatekeeper.pl | 14 +++++++++++++- make-ftpindex.sh | 20 ++++++++++---------- testsuite/gatekeeper.all/20_config.exp | 11 +++++++---- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/gatekeeper.pl b/gatekeeper.pl index 9cfd6ff..956d1a8 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -321,6 +321,7 @@ BEGIN { my $c_Email_InternalBox; # CONF_Email_InternalArchive my $c_Package_Config; # CONF_DIR_ConfigBase my $c_Package_State; # CONF_DIR_State + my $c_dir_FTPRoot; # CONF_DIR_FTPRoot my $c_dir_Inbox; # CONF_DIR_Inbox my $c_dir_Scratch; # CONF_DIR_Scratch my $c_dir_Stage; # CONF_DIR_Staging @@ -352,6 +353,7 @@ BEGIN { $c_Package_Config =File::Spec->catdir($base, 'packages'); $c_Package_State = File::Spec->catdir($base, 'state'); + $c_dir_FTPRoot = $base; $c_dir_Inbox = File::Spec->catdir($base, 'inbox'); $c_dir_Scratch = File::Spec->catdir($base, 'scratch'); $c_dir_Stage = File::Spec->catdir($base, 'stage'); @@ -412,6 +414,14 @@ BEGIN { $c_Package_Config = $ZoneConfig{pkgconfdir}; $c_Package_State = $ZoneConfig{pkgstatedir}; + if ($ZoneConfig{ftprootdir}) { + $c_dir_FTPRoot = $ZoneConfig{ftprootdir}; + } else { + my @dirs = File::Spec->splitdir($ZoneConfig{publicdir}); + pop @dirs; + $c_dir_FTPRoot = File::Spec->catdir(@dirs); + } + $c_dir_Inbox = $ZoneConfig{inboxdir}; $c_dir_Scratch = $ZoneConfig{scratchdir}; $c_dir_Stage = $ZoneConfig{stagedir}; @@ -429,6 +439,7 @@ BEGIN { foreach my $item ([tag => $c_Zone_Tag], [logtag => $c_Log_Tag], [pkgconfdir => $c_Package_Config], [pkgstatedir => $c_Package_State], + [ftprootdir => $c_dir_FTPRoot], [inboxdir => $c_dir_Inbox], [scratchdir => $c_dir_Scratch], [stagedir => $c_dir_Stage], @@ -496,6 +507,7 @@ BEGIN { constant->import(CONF_DIR_ConfigBase => $c_Package_Config); constant->import(CONF_DIR_State => $c_Package_State); + constant->import(CONF_DIR_FTPRoot => $c_dir_FTPRoot); constant->import(CONF_DIR_Inbox => $c_dir_Inbox); constant->import(CONF_DIR_Scratch => $c_dir_Scratch); constant->import(CONF_DIR_Staging => $c_dir_Stage); @@ -3262,7 +3274,7 @@ if ((scalar @packets) == 0) { } else { ftp_syslog info => "Processing complete: " .(scalar @packets)." uploads processed."; - system FTPINDEX_TOOL, CONF_DIR_Public, CONF_DIR_Staging + system FTPINDEX_TOOL, CONF_DIR_FTPRoot, CONF_DIR_Staging unless IN_TEST_MODE; ftp_syslog info => "Updated ftpindex"; } diff --git a/make-ftpindex.sh b/make-ftpindex.sh index 5771285..13336f8 100755 --- a/make-ftpindex.sh +++ b/make-ftpindex.sh @@ -37,7 +37,7 @@ version () { echo "$Version_Notice" | awk '/^$/ { next } } usage () { - echo usage: "$0" ' []' + echo usage: "$0" ' []' } help () { @@ -67,11 +67,11 @@ do --help) help ;; --version) version ;; *) - if test x${PublicDir:+y} = x; then - PublicDir=$1 + if test x${FTPRoot:+y} = x; then + FTPRoot=$1 elif test x${StageDir:+y} = x; then StageDir=$1 - elif test x${PublicDir:+y}${StageDir:+y} = xyy; then + elif test x${FTPRoot:+y}${StageDir:+y} = xyy; then usage exit 2 fi @@ -82,27 +82,27 @@ done : "${StageDir:=${TMPDIR:-/tmp}}" -if test x"$PublicDir" = x || test ! -d "$PublicDir" || test ! -d "$StageDir" +if test x"$FTPRoot" = x || test ! -d "$FTPRoot" || test ! -d "$StageDir" then - test -d "$PublicDir" || echo directory "'$PublicDir'" does not exist + test -d "$FTPRoot" || echo directory "'$FTPRoot'" does not exist test -d "$StageDir" || echo directory "'$StageDir'" does not exist usage exit 2 fi -cd "$PublicDir" || error cannot move to directory "'$PublicDir'" +cd "$FTPRoot" || error cannot move to directory "'$FTPRoot'" find . | gzip -9 -c > "${StageDir}"/find.txt.gz tree -aJsD --timefmt %s | gzip -9 -c > "${StageDir}"/tree.json.gz -cd .. || error cannot move to parent of "'$PublicDir'" +cd .. || error cannot move to parent of "'$FTPRoot'" # shellcheck disable=SC2012 # for obvious reasons... -ls -lrRt "$(basename "$PublicDir")" | gzip -9 -c > "${StageDir}"/ls-lrRt.txt.gz +ls -lrRt "$(basename "$FTPRoot")" | gzip -9 -c > "${StageDir}"/ls-lrRt.txt.gz if $DryRun; then exit 0; fi mv -f "${StageDir}"/ls-lrRt.txt.gz \ "${StageDir}"/find.txt.gz \ "${StageDir}"/tree.json.gz \ - "${PublicDir}" + "${FTPRoot}" # EOF diff --git a/testsuite/gatekeeper.all/20_config.exp b/testsuite/gatekeeper.all/20_config.exp index ad14950..305fbc7 100644 --- a/testsuite/gatekeeper.all/20_config.exp +++ b/testsuite/gatekeeper.all/20_config.exp @@ -220,7 +220,7 @@ pkgstatedir = /srv/gatetest/state-foo inboxdir = /srv/gatetest/inbox-foo scratchdir = /srv/gatetest/scratch-foo stagedir = /srv/gatetest/stage-foo -publicdir = /srv/gatetest/pub-foo +publicdir = /srv/gatetest/ftp/pub-foo archivedir = /srv/gatetest/archive-foo [zone.bar] @@ -228,10 +228,11 @@ archivedir = /srv/gatetest/archive-foo # logtag defaults to capitalized zone name pkgconfdir = /srv/gatetest/config-bar pkgstatedir = /srv/gatetest/state-bar +ftprootdir = /srv/gatetest/ftp inboxdir = /srv/gatetest/inbox-bar scratchdir = /srv/gatetest/scratch-bar stagedir = /srv/gatetest/stage-bar -publicdir = /srv/gatetest/pub-bar +publicdir = /srv/gatetest/ftp/dist/pub-bar archivedir = /srv/gatetest/archive-bar } @@ -244,10 +245,11 @@ do_configuration_test "parse zone configuration: foo" zone.conf \ {tag = foo-test[\r\n]+logtag = FooTest[\r\n]+} {pkgconfdir = /srv/gatetest/config-foo} {pkgstatedir = /srv/gatetest/state-foo} + {ftprootdir = /srv/gatetest/ftp} {inboxdir = /srv/gatetest/inbox-foo} {scratchdir = /srv/gatetest/scratch-foo} {stagedir = /srv/gatetest/stage-foo} - {publicdir = /srv/gatetest/pub-foo} + {publicdir = /srv/gatetest/ftp/pub-foo} {archivedir = /srv/gatetest/archive-foo} } } @@ -260,10 +262,11 @@ do_configuration_test "parse zone configuration: bar" zone.conf \ {tag = bar[\r\n]+logtag = Bar[\r\n]+} {pkgconfdir = /srv/gatetest/config-bar} {pkgstatedir = /srv/gatetest/state-bar} + {ftprootdir = /srv/gatetest/ftp} {inboxdir = /srv/gatetest/inbox-bar} {scratchdir = /srv/gatetest/scratch-bar} {stagedir = /srv/gatetest/stage-bar} - {publicdir = /srv/gatetest/pub-bar} + {publicdir = /srv/gatetest/ftp/dist/pub-bar} {archivedir = /srv/gatetest/archive-bar} } } -- 2.25.1