diff --git a/src/watcher.go b/src/watcher.go index af839f4..fd1d982 100644 --- a/src/watcher.go +++ b/src/watcher.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "strings" + "time" "github.com/fsnotify/fsnotify" ) @@ -50,6 +51,26 @@ func watchFolder() { } func processWatchedFile(filePath string) { + for { + initialSize, err := getFileSize(filePath) + if err != nil { + logger.LogError("Watcher", fmt.Sprintf("Error getting file size: %v", err)) + return + } + + time.Sleep(1 * time.Second) + + currentSize, err := getFileSize(filePath) + if err != nil { + logger.LogError("Watcher", fmt.Sprintf("Error getting file size: %v", err)) + return + } + + if initialSize == currentSize { + break + } + } + file, err := os.Open(filePath) if err != nil { logger.LogError("Watcher", fmt.Sprintf("Error opening file: %v", err)) @@ -83,3 +104,11 @@ func processWatchedFile(filePath string) { go processItems(filepath.Base(tempFile.Name()), items) } + +func getFileSize(filePath string) (int64, error) { + fileInfo, err := os.Stat(filePath) + if err != nil { + return 0, err + } + return fileInfo.Size(), nil +}