diff options
-rw-r--r-- | cmd/installpkg/main.go | 2 | ||||
-rw-r--r-- | filesystem.go | 11 | ||||
-rw-r--r-- | installpkg.go | 10 |
3 files changed, 21 insertions, 2 deletions
diff --git a/cmd/installpkg/main.go b/cmd/installpkg/main.go index a1561e1..5cc4955 100644 --- a/cmd/installpkg/main.go +++ b/cmd/installpkg/main.go @@ -49,7 +49,7 @@ func ParseFlags() *pkgtools.InstallPkgFlags { flags.SetEnvValues() getopt.FlagLong(&flags.Root, "root", 0, "/mnt (install someplace else, like /mnt)") - //getopt.FlagLong(&flags.NoOverwrite, "no-overwrite", 0, "When extracting the package, do not overwrite existing files. Usually, this option should not be used. It exists so that upgradepkg can use it for the second installation pass. The first pass has already overwritten the previous package's files, and this will catch the few corner cases without generating unnecessary writes.") + getopt.FlagLong(&flags.NoOverwrite, "no-overwrite", 0, "When extracting the package, do not overwrite existing files. Usually, this option should not be used. It exists so that upgradepkg can use it for the second installation pass. The first pass has already overwritten the previous package's files, and this will catch the few corner cases without generating unnecessary writes.") getopt.Parse() return &flags diff --git a/filesystem.go b/filesystem.go index dec07f3..f744714 100644 --- a/filesystem.go +++ b/filesystem.go @@ -32,6 +32,17 @@ func HumanReadableSize(size int64) string { return ret } +func IsExist(path string) (bool, error) { + _, err := os.Stat(path) + if os.IsNotExist(err) { + return false, nil + } + if err != nil { + return false, err + } + return true, nil +} + func IsFile(path string) (bool, error) { info, err := os.Stat(path) if err != nil { diff --git a/installpkg.go b/installpkg.go index 82532a9..a0749bd 100644 --- a/installpkg.go +++ b/installpkg.go @@ -315,7 +315,15 @@ func extractSlackwarePkg(flags *InstallPkgFlags, fp string) error { } else if err != nil { return errors.Wrap(err, "installing package") } - + if flags.NoOverwrite { + ok, err := IsExist(filepath.Join(flags.Root, h.Name)) + if err != nil { + return err + } + if ok { + return nil + } + } return toRoot.FilterTar(h, r) }), ) |