Browse Source

Optimized smb WriteStream speed

Toby Chui 3 years ago
parent
commit
c34b7f56f2

+ 2 - 0
file_system.go

@@ -600,6 +600,7 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 		//The merge file location can be local or remote that support OpenFile.
 		out, err = fshAbs.OpenFile(mergeFileLocation, os.O_CREATE|os.O_WRONLY, 0755)
 	}
+	defer out.Close()
 
 	if err != nil {
 		systemWideLogger.PrintAndLog("File System", "Failed to open file:"+err.Error(), err)
@@ -2033,6 +2034,7 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
 					if srcFsh.RequireBuffer {
 						common.SendErrorResponse(w, "Incompatible File System Type: Try SHIFT + DELETE to delete file permanently")
 					} else {
+						systemWideLogger.PrintAndLog("File System", "Failed to move file to trash: "+err.Error(), err)
 						common.SendErrorResponse(w, "Failed to move file to trash")
 					}
 					return

+ 2 - 4
mod/filesystem/abstractions/smbfs/smbfs.go

@@ -134,7 +134,6 @@ func (a ServerMessageBlockFileSystemAbstraction) Remove(filename string) error {
 func (a ServerMessageBlockFileSystemAbstraction) RemoveAll(filename string) error {
 	filename = filterFilepath(filename)
 	filename = toWinPath(filename)
-	fmt.Println("REMOVING", filename)
 	return a.share.RemoveAll(filename)
 }
 func (a ServerMessageBlockFileSystemAbstraction) Rename(oldname, newname string) error {
@@ -234,7 +233,7 @@ func (a ServerMessageBlockFileSystemAbstraction) WriteStream(filename string, st
 		return err
 	}
 
-	p := make([]byte, 1024)
+	p := make([]byte, 32768)
 	for {
 		_, err := stream.Read(p)
 		if err != nil {
@@ -312,8 +311,7 @@ func filterFilepath(rawpath string) string {
 		return rawpath[1:]
 	} else if rawpath == "." || rawpath == "" {
 		return "/"
-	} else if rawpath[0:1] != "/" {
-		return "/" + rawpath
 	}
+
 	return rawpath
 }

+ 18 - 18
mod/filesystem/fileOpr.go

@@ -225,11 +225,11 @@ func ArozZipFileWithProgress(targetFshs []*FileSystemHandler, filelist []string,
 					return nil
 				}
 
-				file, err := fshAbs.ReadStream(path)
+				thisFile, err := fshAbs.ReadStream(path)
 				if err != nil {
 					return err
 				}
-				defer file.Close()
+				defer thisFile.Close()
 
 				relativePath := strings.ReplaceAll(filepath.ToSlash(path), filepath.ToSlash(filepath.Clean(srcpath))+"/", "")
 				if includeTopLevelFolder {
@@ -243,7 +243,7 @@ func ArozZipFileWithProgress(targetFshs []*FileSystemHandler, filelist []string,
 					return err
 				}
 
-				_, err = io.Copy(f, file)
+				_, err = io.Copy(f, thisFile)
 				if err != nil {
 					return err
 				}
@@ -260,11 +260,11 @@ func ArozZipFileWithProgress(targetFshs []*FileSystemHandler, filelist []string,
 		} else {
 			//This is a file
 			topLevelFolderName := filepath.Base(filepath.Dir(srcpath))
-			file, err := fshAbs.ReadStream(srcpath)
+			thisFile, err := fshAbs.ReadStream(srcpath)
 			if err != nil {
 				return err
 			}
-			defer file.Close()
+			defer thisFile.Close()
 			relativePath := filepath.Base(srcpath)
 			if includeTopLevelFolder {
 				relativePath = topLevelFolderName + "/" + relativePath
@@ -275,7 +275,7 @@ func ArozZipFileWithProgress(targetFshs []*FileSystemHandler, filelist []string,
 				return err
 			}
 
-			_, err = io.Copy(f, file)
+			_, err = io.Copy(f, thisFile)
 			if err != nil {
 				return err
 			}
@@ -334,11 +334,11 @@ func ArozZipFile(sourceFshs []*FileSystemHandler, filelist []string, outputFsh *
 						//This is hidden file / folder. Skip this
 						return nil
 					}
-					file, err := os.Open(path)
+					thisFile, err := os.Open(path)
 					if err != nil {
 						return err
 					}
-					defer file.Close()
+					defer thisFile.Close()
 
 					relativePath := strings.ReplaceAll(filepath.ToSlash(path), filepath.ToSlash(filepath.Clean(srcpath))+"/", "")
 					if includeTopLevelFolder {
@@ -352,7 +352,7 @@ func ArozZipFile(sourceFshs []*FileSystemHandler, filelist []string, outputFsh *
 						return err
 					}
 
-					_, err = io.Copy(f, file)
+					_, err = io.Copy(f, thisFile)
 					if err != nil {
 						return err
 					}
@@ -366,11 +366,11 @@ func ArozZipFile(sourceFshs []*FileSystemHandler, filelist []string, outputFsh *
 			} else {
 				//This is a file
 				topLevelFolderName := filepath.Base(filepath.Dir(srcpath))
-				file, err := os.Open(srcpath)
+				thisFile, err := os.Open(srcpath)
 				if err != nil {
 					return err
 				}
-				defer file.Close()
+				defer thisFile.Close()
 				relativePath := filepath.Base(srcpath)
 				if includeTopLevelFolder {
 					relativePath = topLevelFolderName + "/" + relativePath
@@ -380,7 +380,7 @@ func ArozZipFile(sourceFshs []*FileSystemHandler, filelist []string, outputFsh *
 					return err
 				}
 
-				_, err = io.Copy(f, file)
+				_, err = io.Copy(f, thisFile)
 				if err != nil {
 					return err
 				}
@@ -406,12 +406,12 @@ func ArozZipFile(sourceFshs []*FileSystemHandler, filelist []string, outputFsh *
 						return nil
 					}
 
-					file, err := fshAbs.ReadStream(path)
+					thisFile, err := fshAbs.ReadStream(path)
 					if err != nil {
 						fmt.Println(err)
 						return err
 					}
-					defer file.Close()
+					defer thisFile.Close()
 
 					relativePath := strings.ReplaceAll(filepath.ToSlash(path), filepath.ToSlash(filepath.Clean(srcpath))+"/", "")
 					if includeTopLevelFolder {
@@ -425,7 +425,7 @@ func ArozZipFile(sourceFshs []*FileSystemHandler, filelist []string, outputFsh *
 						return err
 					}
 
-					_, err = io.Copy(f, file)
+					_, err = io.Copy(f, thisFile)
 					if err != nil {
 						return err
 					}
@@ -439,11 +439,11 @@ func ArozZipFile(sourceFshs []*FileSystemHandler, filelist []string, outputFsh *
 			} else {
 				//This is a file
 				topLevelFolderName := filepath.Base(filepath.Dir(srcpath))
-				file, err := fshAbs.ReadStream(srcpath)
+				thisFile, err := fshAbs.ReadStream(srcpath)
 				if err != nil {
 					return err
 				}
-				defer file.Close()
+				defer thisFile.Close()
 				relativePath := filepath.Base(srcpath)
 				if includeTopLevelFolder {
 					relativePath = topLevelFolderName + "/" + relativePath
@@ -453,7 +453,7 @@ func ArozZipFile(sourceFshs []*FileSystemHandler, filelist []string, outputFsh *
 					return err
 				}
 
-				_, err = io.Copy(f, file)
+				_, err = io.Copy(f, thisFile)
 				if err != nil {
 					return err
 				}

+ 4 - 1
mod/filesystem/metadata/audio.go

@@ -37,7 +37,10 @@ func generateThumbnailForAudio(fsh *filesystem.FileSystemHandler, cacheFolder st
 		}
 
 		//Create an empty file
-		out, _ := fshAbs.Create(cacheFolder + filepath.Base(file) + ".jpg")
+		out, err := fshAbs.Create(cacheFolder + filepath.Base(file) + ".jpg")
+		if err != nil {
+			return "", err
+		}
 		defer out.Close()
 
 		b := img.Bounds()