diff --git a/pkg/utils/FileReceiver.go b/pkg/utils/FileReceiver.go index a9b77c6..fc4e075 100644 --- a/pkg/utils/FileReceiver.go +++ b/pkg/utils/FileReceiver.go @@ -11,21 +11,30 @@ func ReceiveFile(path string, fileSize int, reader *bufio.Reader) bool { if fileErr != nil { return false } + defer file.Close() // Params buffer := make([]byte, 1024) currentSize := 0 + b, done := copyFile(currentSize, fileSize, reader, buffer, file) + if done { + return b + } + return true +} + +func copyFile(currentSize int, fileSize int, reader *bufio.Reader, buffer []byte, file *os.File) (bool, bool) { // Retrieving file for currentSize < fileSize { length, err := reader.Read(buffer) if err != nil { - return false + return false, true } _, err = file.WriteAt(buffer, int64(currentSize)) if err != nil { - return false + return false, true } currentSize += length check := fileSize - currentSize @@ -33,5 +42,13 @@ func ReceiveFile(path string, fileSize int, reader *bufio.Reader) bool { buffer = make([]byte, check) } } - return true + return false, false +} + +func fileExists(filename string) bool { + info, err := os.Stat(filename) + if os.IsNotExist(err) { + return false + } + return !info.IsDir() } diff --git a/resources/AppConfig.json b/resources/AppConfig.json index e4f2a33..c548bda 100644 --- a/resources/AppConfig.json +++ b/resources/AppConfig.json @@ -4,5 +4,5 @@ "multicastSecond" : 10, "domain" : "lightcontainerSB01", "unicastPort" : 58000, - "storagePath" : "C:\\Users\\ledou\\Documents\\sbe" + "storagePath" : "/home/benjamin/sbe" } \ No newline at end of file