From 749e55c738bf702b5f1265f85018c450a7b4e3b4 Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Mon, 8 Nov 2021 13:35:46 -0500 Subject: caddycmd: Add `--keep-backup` to upgrade commands (#4387) * caddycmd: Add `--skip-cleanup` to upgrade commands This is a partial fix for https://github.com/caddyserver/caddy/issues/4057, making it possible to retain the old build of Caddy, in case something went wrong. * caddycmd: Fix duplicate error message The error message "download succeeded, but unable to execute" was repeated, because it was both in the `listModules`/`showVersion` functions and in the calling `upgradeBuild` function. Oversight when this was refactored. * caddycmd: Implement fix for performing cleanup on Windows Without this, the cleanup operation would fail with an error message like this: upgrade: download succeeded, but unable to clean up backup binary: remove C:\caddy\caddy.exe.tmp: Access is denied. * caddycmd: Rename to `--keep-backup`, simplify build constraints --- cmd/commands.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'cmd/commands.go') diff --git a/cmd/commands.go b/cmd/commands.go index f562430..1e2c40d 100644 --- a/cmd/commands.go +++ b/cmd/commands.go @@ -296,6 +296,11 @@ is always printed to stdout.`, Long: ` Downloads an updated Caddy binary with the same modules/plugins at the latest versions. EXPERIMENTAL: May be changed or removed.`, + Flags: func() *flag.FlagSet { + fs := flag.NewFlagSet("upgrade", flag.ExitOnError) + fs.Bool("keep-backup", false, "Keep the backed up binary, instead of deleting it") + return fs + }(), }) RegisterCommand(Command{ @@ -308,6 +313,11 @@ Downloads an updated Caddy binary with the specified packages (module/plugin) added. Retains existing packages. Returns an error if the any of packages are already included. EXPERIMENTAL: May be changed or removed. `, + Flags: func() *flag.FlagSet { + fs := flag.NewFlagSet("add-package", flag.ExitOnError) + fs.Bool("keep-backup", false, "Keep the backed up binary, instead of deleting it") + return fs + }(), }) RegisterCommand(Command{ @@ -320,6 +330,11 @@ Downloads an updated Caddy binaries without the specified packages (module/plugi Returns an error if any of the packages are not included. EXPERIMENTAL: May be changed or removed. `, + Flags: func() *flag.FlagSet { + fs := flag.NewFlagSet("remove-package", flag.ExitOnError) + fs.Bool("keep-backup", false, "Keep the backed up binary, instead of deleting it") + return fs + }(), }) } -- cgit v1.2.3