فهرست منبع

Added linux path support

Toby Chui 3 سال پیش
والد
کامیت
910ca5cd89
1فایلهای تغییر یافته به همراه5 افزوده شده و 1 حذف شده
  1. 5 1
      mod/filesystem/static.go

+ 5 - 1
mod/filesystem/static.go

@@ -348,12 +348,16 @@ func UnderTheSameRoot(srcAbs string, destAbs string) (bool, error) {
 	return false, nil
 }
 
-//Get the physical root of a given filepath, e.g. C:\ or /home/
+//Get the physical root of a given filepath, e.g. C: or /home
 func GetPhysicalRootFromPath(filename string) (string, error) {
 	filename, err := filepath.Abs(filename)
 	if err != nil {
 		return "", err
 	}
+	if filename[:1] == "/" {
+		//Handle cases like /home/pi/foo.txt => return home
+		filename = filename[1:]
+	}
 	filename = strings.TrimSpace(filename)
 	if filename == "" {
 		return "", nil