From ae90b7b85a69ccaf4cfa344cd979bac61afcf48b Mon Sep 17 00:00:00 2001 From: Slack Coder Date: Wed, 13 Apr 2022 09:18:41 -0500 Subject: installpkg: avoid modifying /install if it exists Avoid modifying and removing the /install directory if it already exists on the system by exiting early. --- installpkg.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/installpkg.go b/installpkg.go index 7933960..a6e327e 100644 --- a/installpkg.go +++ b/installpkg.go @@ -295,6 +295,12 @@ func InstallPkg(flags *InstallPkgFlags, pkgs ...string) error { return err } + installPath := path.Join(flags.Root, PackageInstallPath) + fmt.Println(installPath) + if _, err := os.Stat(installPath); !errors.Is(err, os.ErrNotExist) { + return errors.Errorf("The '%s' directory exists and would be used by installpkg and removed. Please consider renaming the directory or using Slackware's installpkg.", installPath) + } + for _, pkg := range pkgs { fmt.Printf("installing %s\n", PackageBase(pkg)) err = writeToDatabase(flags.Root, pkg) @@ -336,7 +342,6 @@ func InstallPkg(flags *InstallPkgFlags, pkgs ...string) error { fmt.Fprintln(os.Stderr, errors.Wrap(err, "running install script")) } - installPath := path.Join(flags.Root, PackageInstallPath) err = os.RemoveAll(installPath) if err != nil { return err -- cgit v1.2.3