diff options
| author | yourchanges <yourchanges@gmail.com> | 2020-07-17 19:49:16 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-17 19:49:16 +0800 |
| commit | 64df5207db14ccf7e7915561b5c9b8f3dab53c6e (patch) | |
| tree | df4a05999d67abb7c4765d39eddc01318521169b /weed/util/file_util.go | |
| parent | 8c318470dd95b3fc24d39dc3cf253cc17b03ab39 (diff) | |
| parent | f43146b237bc5bbfb7033f6e427b5299554c0824 (diff) | |
| download | seaweedfs-64df5207db14ccf7e7915561b5c9b8f3dab53c6e.tar.xz seaweedfs-64df5207db14ccf7e7915561b5c9b8f3dab53c6e.zip | |
Merge pull request #2 from chrislusf/master
merge
Diffstat (limited to 'weed/util/file_util.go')
| -rw-r--r-- | weed/util/file_util.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/weed/util/file_util.go b/weed/util/file_util.go index ff725830b..70135180d 100644 --- a/weed/util/file_util.go +++ b/weed/util/file_util.go @@ -3,6 +3,9 @@ package util import ( "errors" "os" + "os/user" + "path/filepath" + "strings" "time" "github.com/chrislusf/seaweedfs/weed/glog" @@ -63,3 +66,20 @@ func CheckFile(filename string) (exists, canRead, canWrite bool, modTime time.Ti fileSize = fi.Size() return } + +func ResolvePath(path string) string { + + usr, _ := user.Current() + dir := usr.HomeDir + + if path == "~" { + // In case of "~", which won't be caught by the "else if" + path = dir + } else if strings.HasPrefix(path, "~/") { + // Use strings.HasPrefix so we don't match paths like + // "/something/~/something/" + path = filepath.Join(dir, path[2:]) + } + + return path +} |
