diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-07-16 22:38:55 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-07-16 22:38:55 -0700 |
| commit | befb396892deb7e5fdaefaf2f952bd744cc08ace (patch) | |
| tree | df1505ea4ca6359ed8c04e7da2b5df4b4d040119 /weed | |
| parent | 54445b207ddf6de5db128d307ec7a8554e529946 (diff) | |
| download | seaweedfs-befb396892deb7e5fdaefaf2f952bd744cc08ace.tar.xz seaweedfs-befb396892deb7e5fdaefaf2f952bd744cc08ace.zip | |
mount: resolve home directory
fix https://github.com/chrislusf/seaweedfs/issues/1391
Diffstat (limited to 'weed')
| -rw-r--r-- | weed/command/mount_std.go | 2 | ||||
| -rw-r--r-- | weed/util/file_util.go | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/weed/command/mount_std.go b/weed/command/mount_std.go index 7520de784..56df740c4 100644 --- a/weed/command/mount_std.go +++ b/weed/command/mount_std.go @@ -69,7 +69,7 @@ func RunMount(option *MountOptions, umask os.FileMode) bool { } filerMountRootPath := *option.filerMountRootPath - dir := *option.dir + dir := util.ResolvePath(*option.dir) chunkSizeLimitMB := *mountOptions.chunkSizeLimitMB util.LoadConfiguration("security", false) 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 +} |
