diff options
| author | Chris Lu <chris.lu@gmail.com> | 2018-05-25 23:27:06 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2018-05-25 23:27:06 -0700 |
| commit | c34feca59c6ebfdf7ffd8b24b1c827a2f18f263b (patch) | |
| tree | 3d0d42531be4e9a7eda050394fb996d865100956 /weed/filer2/fullpath.go | |
| parent | 6de84c64c67eb0e1161ad1b627917d466d49e6c6 (diff) | |
| download | seaweedfs-c34feca59c6ebfdf7ffd8b24b1c827a2f18f263b.tar.xz seaweedfs-c34feca59c6ebfdf7ffd8b24b1c827a2f18f263b.zip | |
refactoring
Diffstat (limited to 'weed/filer2/fullpath.go')
| -rw-r--r-- | weed/filer2/fullpath.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/weed/filer2/fullpath.go b/weed/filer2/fullpath.go new file mode 100644 index 000000000..20e42e9b9 --- /dev/null +++ b/weed/filer2/fullpath.go @@ -0,0 +1,31 @@ +package filer2 + +import ( + "path/filepath" + "strings" +) + +type FullPath string + +func NewFullPath(dir, name string) FullPath { + if strings.HasSuffix(dir, "/") { + return FullPath(dir + name) + } + return FullPath(dir + "/" + 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 +} |
