fix: trailing spaces in watch folders, improve root folder matching, and log walk errors
This commit is contained in:
@@ -78,6 +78,7 @@ func (m *Manager) Reload() {
|
|||||||
// Walk the directory to add all subdirectories to watcher and scan existing files
|
// Walk the directory to add all subdirectories to watcher and scan existing files
|
||||||
filepath.Walk(f.FolderPath, func(path string, info os.FileInfo, err error) error {
|
filepath.Walk(f.FolderPath, func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("Error accessing path %s during scan: %v", path, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
@@ -198,8 +199,18 @@ func (m *Manager) processFile(filePath string) {
|
|||||||
}
|
}
|
||||||
// Check if filePath is inside f.FolderPath
|
// Check if filePath is inside f.FolderPath
|
||||||
cleanPath := filepath.Clean(filePath)
|
cleanPath := filepath.Clean(filePath)
|
||||||
folderPath := filepath.Clean(f.FolderPath)
|
folderPath := filepath.Clean(strings.TrimSpace(f.FolderPath))
|
||||||
if strings.HasPrefix(cleanPath, folderPath+string(os.PathSeparator)) || cleanPath == folderPath || filepath.Dir(cleanPath) == folderPath {
|
|
||||||
|
var isMatch bool
|
||||||
|
if cleanPath == folderPath {
|
||||||
|
isMatch = true
|
||||||
|
} else if folderPath == string(os.PathSeparator) {
|
||||||
|
isMatch = strings.HasPrefix(cleanPath, folderPath)
|
||||||
|
} else {
|
||||||
|
isMatch = strings.HasPrefix(cleanPath, folderPath+string(os.PathSeparator))
|
||||||
|
}
|
||||||
|
|
||||||
|
if isMatch {
|
||||||
match = f
|
match = f
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ func (s *Server) handleAddWatchFolder(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
f.FolderPath = strings.TrimSpace(f.FolderPath)
|
||||||
f.Enabled = true
|
f.Enabled = true
|
||||||
if err := db.AddWatchFolder(f); err != nil {
|
if err := db.AddWatchFolder(f); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
|||||||
Reference in New Issue
Block a user