aboutsummaryrefslogtreecommitdiff
path: root/weed/util/file_util.go
diff options
context:
space:
mode:
authorhilimd <68371223+hilimd@users.noreply.github.com>2020-07-20 15:35:47 +0800
committerGitHub <noreply@github.com>2020-07-20 15:35:47 +0800
commit5850bb733936399babbe2d77f4b27cac312e2798 (patch)
tree3966daffbb7b2633906f883e3047511772a4fdcf /weed/util/file_util.go
parentb1616e93474246a624370ad18da98b8371c09ece (diff)
parentf90d2c93c9e34997a8e76aeefb438ec06b1cd093 (diff)
downloadseaweedfs-5850bb733936399babbe2d77f4b27cac312e2798.tar.xz
seaweedfs-5850bb733936399babbe2d77f4b27cac312e2798.zip
Merge pull request #2 from chrislusf/master
sync
Diffstat (limited to 'weed/util/file_util.go')
-rw-r--r--weed/util/file_util.go20
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
+}