Browse Source

Fixed file operation for keep and overwrite on windows path slash invalid issue

TC pushbot 5 4 years ago
parent
commit
ff2e62466b
4 changed files with 11 additions and 9 deletions
  1. 1 1
      file_system.go
  2. 8 8
      mod/filesystem/fileOpr.go
  3. 2 0
      mod/modules/module.go
  4. 0 0
      subservice/WsTTY/.disabled

+ 1 - 1
file_system.go

@@ -722,7 +722,7 @@ func system_fs_validateFileOpr(w http.ResponseWriter, r *http.Request) {
 	rdestFile, _ := userinfo.VirtualPathToRealPath(vdestFile)
 	for _, file := range sourceFiles {
 		rsrcFile, _ := userinfo.VirtualPathToRealPath(string(file))
-		if fileExists(rdestFile + filepath.Base(rsrcFile)) {
+		if fileExists(filepath.Join(rdestFile, filepath.Base(rsrcFile))) {
 			//File exists already.
 			vpath, _ := userinfo.RealPathToVirtualPath(rsrcFile)
 			duplicateFiles = append(duplicateFiles, vpath)

+ 8 - 8
mod/filesystem/fileOpr.go

@@ -390,7 +390,7 @@ func FileCopy(src string, dest string, mode string, progressUpdate func(int, str
 	//Check if the copy destination file already have an identical file
 	copiedFilename := filepath.Base(src)
 
-	if fileExists(dest + filepath.Base(src)) {
+	if fileExists(filepath.Join(dest, filepath.Base(src))) {
 		if mode == "" {
 			//Do not specific file exists principle
 			return errors.New("Destination file already exists.")
@@ -401,7 +401,7 @@ func FileCopy(src string, dest string, mode string, progressUpdate func(int, str
 		} else if mode == "overwrite" {
 			//Continue with the following code
 			//Check if the copy and paste dest are identical
-			if src == (dest + filepath.Base(src)) {
+			if filepath.ToSlash(filepath.Clean(src)) == filepath.ToSlash(filepath.Clean(filepath.Join(dest, filepath.Base(src)))) {
 				//Source and target identical. Cannot overwrite.
 				return errors.New("Source and destination paths are identical.")
 
@@ -412,7 +412,7 @@ func FileCopy(src string, dest string, mode string, progressUpdate func(int, str
 			newFilename := strings.TrimSuffix(filepath.Base(src), filepath.Ext(src)) + " - Copy" + filepath.Ext(src)
 			//Check if the newFilename already exists. If yes, continue adding suffix
 			duplicateCounter := 0
-			for fileExists(dest + newFilename) {
+			for fileExists(filepath.Join(dest, newFilename)) {
 				duplicateCounter++
 				newFilename = strings.TrimSuffix(filepath.Base(src), filepath.Ext(src)) + " - Copy(" + strconv.Itoa(duplicateCounter) + ")" + filepath.Ext(src)
 				if duplicateCounter > 1024 {
@@ -439,7 +439,7 @@ func FileCopy(src string, dest string, mode string, progressUpdate func(int, str
 	if IsDir(src) {
 		//Source file is directory. CopyFolder
 
-		realDest := dest + copiedFilename
+		realDest := filepath.Join(dest, copiedFilename)
 
 		//err := dircpy.Copy(src, realDest)
 
@@ -451,7 +451,7 @@ func FileCopy(src string, dest string, mode string, progressUpdate func(int, str
 
 	} else {
 		//Source is file only. Copy file.
-		realDest := dest + copiedFilename
+		realDest := filepath.Join(dest, copiedFilename)
 		source, err := os.Open(src)
 		if err != nil {
 			return err
@@ -502,7 +502,7 @@ func FileMove(src string, dest string, mode string, fastMove bool, progressUpdat
 	//Check if the target file already exists.
 	movedFilename := filepath.Base(src)
 
-	if fileExists(dest + filepath.Base(src)) {
+	if fileExists(filepath.Join(dest, filepath.Base(src))) {
 		//Handle cases where file already exists
 		if mode == "" {
 			//Do not specific file exists principle
@@ -513,7 +513,7 @@ func FileMove(src string, dest string, mode string, fastMove bool, progressUpdat
 		} else if mode == "overwrite" {
 			//Continue with the following code
 			//Check if the copy and paste dest are identical
-			if src == (dest + filepath.Base(src)) {
+			if filepath.ToSlash(filepath.Clean(src)) == filepath.ToSlash(filepath.Clean(filepath.Join(dest, filepath.Base(src)))) {
 				//Source and target identical. Cannot overwrite.
 				return errors.New("Source and destination paths are identical.")
 			}
@@ -523,7 +523,7 @@ func FileMove(src string, dest string, mode string, fastMove bool, progressUpdat
 			newFilename := strings.TrimSuffix(filepath.Base(src), filepath.Ext(src)) + " - Copy" + filepath.Ext(src)
 			//Check if the newFilename already exists. If yes, continue adding suffix
 			duplicateCounter := 0
-			for fileExists(dest + newFilename) {
+			for fileExists(filepath.Join(dest, newFilename)) {
 				duplicateCounter++
 				newFilename = strings.TrimSuffix(filepath.Base(src), filepath.Ext(src)) + " - Copy(" + strconv.Itoa(duplicateCounter) + ")" + filepath.Ext(src)
 				if duplicateCounter > 1024 {

+ 2 - 0
mod/modules/module.go

@@ -78,6 +78,8 @@ func (m *ModuleHandler) HandleDefaultLauncher(w http.ResponseWriter, r *http.Req
 	ext, _ := mv(r, "ext", false)
 	moduleName, _ := mv(r, "module", false)
 
+	ext = strings.ToLower(ext)
+
 	//Check if the default folder exists.
 	if opr == "get" {
 		//Get the opener for this file type

+ 0 - 0
subservice/WsTTY/.disabled