Toby Chui 3 жил өмнө
parent
commit
b02ce5ae20

+ 15 - 12
file_system.go

@@ -1391,7 +1391,8 @@ func system_fs_handleWebSocketOpr(w http.ResponseWriter, r *http.Request) {
 			}
 
 			if operation == "move" {
-				err := fs.FileMove(rsrcFile, rdestFile, existsOpr, false, func(progress int, currentFile string) {
+				underSameRoot, _ := fs.UnderTheSameRoot(rsrcFile, rdestFile)
+				err := fs.FileMove(rsrcFile, rdestFile, existsOpr, underSameRoot, func(progress int, currentFile string) {
 					//Multply child progress to parent progress
 					blockRatio := float64(100) / float64(len(sourceFiles))
 					overallRatio := blockRatio*float64(i) + blockRatio*(float64(progress)/float64(100))
@@ -1660,23 +1661,25 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
 				//Check if use fast move instead
 				//Check if the source and destination folder are under the same root. If yes, use os.Rename for faster move operations
 
-				underSameRoot := false
 				//Check if the two files are under the same user root path
 
 				srcAbs, _ := filepath.Abs(rsrcFile)
 				destAbs, _ := filepath.Abs(rdestFile)
 
 				//Check other storage path and see if they are under the same root
-				for _, rootPath := range userinfo.GetAllFileSystemHandler() {
-					thisRoot := rootPath.Path
-					thisRootAbs, err := filepath.Abs(thisRoot)
-					if err != nil {
-						continue
-					}
-					if strings.Contains(srcAbs, thisRootAbs) && strings.Contains(destAbs, thisRootAbs) {
-						underSameRoot = true
-					}
-				}
+				/*
+					for _, rootPath := range userinfo.GetAllFileSystemHandler() {
+						thisRoot := rootPath.Path
+						thisRootAbs, err := filepath.Abs(thisRoot)
+						if err != nil {
+							continue
+						}
+						if strings.Contains(srcAbs, thisRootAbs) && strings.Contains(destAbs, thisRootAbs) {
+							underSameRoot = true
+						}
+					}*/
+
+				underSameRoot, _ := fs.UnderTheSameRoot(srcAbs, destAbs)
 
 				//Updates 19-10-2020: Added ownership management to file move and copy
 				userinfo.RemoveOwnershipFromFile(rsrcFile)

+ 46 - 45
mod/filesystem/fileOpr.go

@@ -530,61 +530,62 @@ func FileMove(src string, dest string, mode string, fastMove bool, progressUpdat
 		//Ready to move with the quick rename method
 		realDest := dest + movedFilename
 		err := os.Rename(src, realDest)
-		if err != nil {
-			log.Println(err)
-			return errors.New("File Move Failed")
+		if err == nil {
+			//Fast move success
+			return nil
 		}
 
-	} else {
-		//Ready to move. Check if both folder are located in the same root devices. If not, use copy and delete method.
-		if IsDir(src) {
-			//Source file is directory. CopyFolder
-			realDest := dest + movedFilename
-			//err := dircpy.Copy(src, realDest)
+		//Fast move failed. Back to the original copy and move method
+	}
 
-			err := dirCopy(src, realDest, progressUpdate)
-			if err != nil {
-				return err
-			} else {
-				//Move completed. Remove source file.
-				os.RemoveAll(src)
-				return nil
-			}
+	//Ready to move. Check if both folder are located in the same root devices. If not, use copy and delete method.
+	if IsDir(src) {
+		//Source file is directory. CopyFolder
+		realDest := dest + movedFilename
+		//err := dircpy.Copy(src, realDest)
 
+		err := dirCopy(src, realDest, progressUpdate)
+		if err != nil {
+			return err
 		} else {
-			//Source is file only. Copy file.
-			realDest := dest + movedFilename
-			/*
-				Updates 20-10-2020, replaced io.Copy to BufferedLargeFileCopy
-				Legacy code removed.
-			*/
+			//Move completed. Remove source file.
+			os.RemoveAll(src)
+			return nil
+		}
 
-			//Update the progress
-			if progressUpdate != nil {
-				progressUpdate(100, filepath.Base(src))
-			}
+	} else {
+		//Source is file only. Copy file.
+		realDest := dest + movedFilename
+		/*
+			Updates 20-10-2020, replaced io.Copy to BufferedLargeFileCopy
+			Legacy code removed.
+		*/
 
-			err := BufferedLargeFileCopy(src, realDest, 8192)
-			if err != nil {
-				log.Println("BLFC error: ", err.Error())
-				return err
-			}
+		//Update the progress
+		if progressUpdate != nil {
+			progressUpdate(100, filepath.Base(src))
+		}
 
-			//Delete the source file after copy
-			err = os.Remove(src)
-			counter := 0
-			for err != nil {
-				//Sometime Windows need this to prevent windows caching bring problems to file remove
-				time.Sleep(1 * time.Second)
-				os.Remove(src)
-				counter++
-				log.Println("Retrying to remove file: " + src)
-				if counter > 10 {
-					return errors.New("Source file remove failed.")
-				}
-			}
+		err := BufferedLargeFileCopy(src, realDest, 8192)
+		if err != nil {
+			log.Println("BLFC error: ", err.Error())
+			return err
+		}
 
+		//Delete the source file after copy
+		err = os.Remove(src)
+		counter := 0
+		for err != nil {
+			//Sometime Windows need this to prevent windows caching bring problems to file remove
+			time.Sleep(1 * time.Second)
+			os.Remove(src)
+			counter++
+			log.Println("Retrying to remove file: " + src)
+			if counter > 10 {
+				return errors.New("Source file remove failed.")
+			}
 		}
+
 	}
 
 	return nil

+ 34 - 0
mod/filesystem/static.go

@@ -328,3 +328,37 @@ func GetModTime(filepath string) (int64, error) {
 	f.Close()
 	return statinfo.ModTime().Unix(), nil
 }
+
+func UnderTheSameRoot(srcAbs string, destAbs string) (bool, error) {
+	srcRoot, err := GetPhysicalRootFromPath(srcAbs)
+	if err != nil {
+		return false, err
+	}
+	destRoot, err := GetPhysicalRootFromPath(destAbs)
+	if err != nil {
+		return false, err
+	}
+	if srcRoot != "" && destRoot != "" {
+		if srcRoot == destRoot {
+			//apply fast move
+			return true, nil
+		}
+	}
+
+	return false, nil
+}
+
+//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
+	}
+	filename = strings.TrimSpace(filename)
+	if filename == "" {
+		return "", nil
+	}
+	filename = filepath.ToSlash(filepath.Clean(filename))
+	pathChunks := strings.Split(filename, "/")
+	return pathChunks[0], nil
+}

+ 3 - 3
web/SystemAO/file_system/file_explorer.html

@@ -1567,9 +1567,9 @@
                                     $("#folderList").show();
                                     $("#folderList").html(`<div class="ts basic segment ${currentTheme}">
                                         <div class="ts header">
-                                            <i class="remove icon ${currentTheme}"></i> <span class="${currentTheme}">This Folder Cannot Be Opened</span>
-                                            <div class="sub header ${currentTheme}" style="margin-top:12px;">The server return the following error message: <br><code>${data.error.toUpperCase()}</code><br>
-                                                ${ao_module_utils.timeConverter(Date.now()/1000)}</div>
+                                            <i class="remove icon ${currentTheme}"></i> <span class="${currentTheme}">${applocale.getString("message/folderCannotOpen","This Folder Cannot Be Opened")}</span>
+                                            <div class="sub header ${currentTheme}" style="margin-top:12px;">${applocale.getString("message/folderCannotOpen/codedesc","The server return the following error message:")} <br><code>${data.error.toUpperCase()}</code><br>
+                                                ${new Date().toLocaleString(undefined, {year: 'numeric', month: '2-digit', day: '2-digit', weekday:"long", hour: '2-digit', hour12: false, minute:'2-digit', second:'2-digit'})}</div>
                                         </div>
                                     </div>`);
                                     $("#fileList").hide();

+ 3 - 0
web/SystemAO/locale/file_explorer.json

@@ -158,6 +158,9 @@
                 "message/noMatchResultsDesc":"伺服器找不到與此關鍵字匹配的檔案",
                 "message/noMatchResultsInst":"請檢查你的關鍵字或通配符是否正確。",
 
+                "message/folderCannotOpen":"無法開啟此資料夾",
+                "message/folderCannotOpen/codedesc":"伺服器端回傳以下錯誤訊息: ",
+
                 "message/destIdentical": "檔案來源及目的地相同",
                 "message/decodeFilelistFail": "載案置入失敗:無法讀取檔案列表",
                 "message/uploadFailed": "載案上載失敗:檔案太大或目標儲存裝置已滿",