aboutsummaryrefslogtreecommitdiffsponsor
path: root/filesystem.go
diff options
context:
space:
mode:
Diffstat (limited to 'filesystem.go')
-rw-r--r--filesystem.go15
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 {