aboutsummaryrefslogtreecommitdiff
path: root/weed/util/fullpath.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-03-23 00:01:34 -0700
committerChris Lu <chris.lu@gmail.com>2020-03-23 00:01:34 -0700
commitc0f0fdb3baeb6e9852c6876b23c1404b2c5e833d (patch)
treeb52ffd7ac51e5c0472f0d0e2a8f5b1338cbf270c /weed/util/fullpath.go
parentfbca6b29bd48eeed54511a9b53b937597eee5d19 (diff)
downloadseaweedfs-c0f0fdb3baeb6e9852c6876b23c1404b2c5e833d.tar.xz
seaweedfs-c0f0fdb3baeb6e9852c6876b23c1404b2c5e833d.zip
refactoring
Diffstat (limited to 'weed/util/fullpath.go')
-rw-r--r--weed/util/fullpath.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/weed/util/fullpath.go b/weed/util/fullpath.go
new file mode 100644
index 000000000..4a2e2854f
--- /dev/null
+++ b/weed/util/fullpath.go
@@ -0,0 +1,40 @@
+package util
+
+import (
+ "path/filepath"
+ "strings"
+)
+
+type FullPath string
+
+func NewFullPath(dir, name string) FullPath {
+ return FullPath(dir).Child(name)
+}
+
+func (fp FullPath) DirAndName() (string, string) {
+ dir, name := filepath.Split(string(fp))
+ if dir == "/" {
+ return dir, name
+ }
+ if len(dir) < 1 {
+ return "/", ""
+ }
+ return dir[:len(dir)-1], name
+}
+
+func (fp FullPath) Name() string {
+ _, name := filepath.Split(string(fp))
+ return name
+}
+
+func (fp FullPath) Child(name string) FullPath {
+ dir := string(fp)
+ if strings.HasSuffix(dir, "/") {
+ return FullPath(dir + name)
+ }
+ return FullPath(dir + "/" + name)
+}
+
+func (fp FullPath) AsInode() uint64 {
+ return uint64(HashStringToLong(string(fp)))
+}