diff options
author | Slack Coder <slackcoder@server.ky> | 2022-04-23 09:46:41 -0500 |
---|---|---|
committer | Slack Coder <slackcoder@server.ky> | 2022-04-23 11:32:42 -0500 |
commit | 5d4066dd1e90fa704b67384327af72b3ec121102 (patch) | |
tree | 28d7c331840f87c6954c80e469477d679868ad72 /filesystem.go | |
parent | f79877dd20bbf5fa51c8c0df50101c2547b9e91d (diff) | |
download | pkgtools-go-5d4066dd1e90fa704b67384327af72b3ec121102.tar.xz |
installpkg: Avoid using /install on target dir
Use a temporary randomly named directory named like 'installpkg-2052825695'
for the package's metadata in its '/install' directory. It will help allow
running multiple instances on the same target root directory by removing
a point of conflict.
Attempt to place this directory in the host's default temporary directory. If
it does not exist, use the host's root path.
Diffstat (limited to 'filesystem.go')
-rw-r--r-- | filesystem.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/filesystem.go b/filesystem.go index c33df15..dec07f3 100644 --- a/filesystem.go +++ b/filesystem.go @@ -4,7 +4,9 @@ import ( "io/fs" "math" "os" + "path/filepath" "strconv" + "strings" "time" ) @@ -46,6 +48,19 @@ func IsDir(path string) (bool, error) { return info.IsDir(), nil } +func IsParentDir(parent, sub string) (bool, error) { + up := ".." + string(os.PathSeparator) + + rel, err := filepath.Rel(parent, sub) + if err != nil { + return false, err + } + if !strings.HasPrefix(rel, up) && rel != ".." { + return true, nil + } + return false, nil +} + func IsSymlink(path string) (bool, error) { info, err := os.Stat(path) if err != nil { |