aboutsummaryrefslogtreecommitdiffsponsor
diff options
context:
space:
mode:
authorSlack Coder <slackcoder@server.ky>2022-04-13 09:18:41 -0500
committerSlack Coder <slackcoder@server.ky>2022-04-13 09:18:41 -0500
commitae90b7b85a69ccaf4cfa344cd979bac61afcf48b (patch)
tree4a9980ee99f9a147363eb3aff82011ab15e63559
parent7d19508c417a854f357609c07e550fca0a09c8eb (diff)
downloadpkgtools-go-ae90b7b85a69ccaf4cfa344cd979bac61afcf48b.tar.xz
installpkg: avoid modifying /install if it exists
Avoid modifying and removing the /install directory if it already exists on the system by exiting early.
-rw-r--r--installpkg.go7
1 files changed, 6 insertions, 1 deletions
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