Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

mount: resolve home directory

Chris Lubefb396892de
diff --git a/weed/command/mount_std.go b/weed/command/mount_std.go
index 7520de7849..56df740c47 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 ff725830bb..70135180d8 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
+}