示例#1
0
// watchFolder installs inotify watcher for a folder, launches
// goroutine which receives changed items. It never exits.
func watchFolder(folder FolderConfiguration, stInput chan STEvent) {
	folderPath := expandTilde(folder.Path)
	ignorePatterns := getIgnorePatterns(folder.ID)
	fsInput := make(chan string)
	c := make(chan notify.EventInfo, maxFiles)
	if err := notify.Watch(filepath.Join(folderPath, "..."), c, notify.All); err != nil {
		if strings.Contains(err.Error(), "too many open files") || strings.Contains(err.Error(), "no space left on device") {
			msg := "Failed to install inotify handler for " + folder.ID + ". Please increase inotify limits, see http://bit.ly/1PxkdUC for more information."
			Warning.Println(msg, err)
			informError(msg)
		} else {
			Warning.Println("Failed to install inotify handlers", err)
			informError("Failed to install inotify handler for " + folder.ID + ": " + err.Error())
		}
		return
	}
	defer notify.Stop(c)
	go accumulateChanges(debounceTimeout, folder.ID, folderPath, dirVsFiles, stInput, fsInput, informChange)
	OK.Println("Watching " + folder.ID + ": " + folderPath)
	if folder.RescanIntervalS < 1800 && delayScan <= 0 {
		OK.Printf("The rescan interval of folder %s can be increased to 3600 (an hour) or even 86400 (a day) as changes should be observed immediately while syncthing-inotify is running.", folder.ID)
	}
	// will we ever get out of this loop?
	for {
		evPath := waitForEvent(c)
		Debug.Println("Change detected in: " + evPath + " (could still be ignored)")
		ev := relativePath(evPath, folderPath)
		if shouldIgnore(ignorePaths, ignorePatterns, ev) {
			continue
		}
		Trace.Println("Change detected in: " + evPath)
		fsInput <- ev
	}
}
示例#2
0
func watchFolder(folder FolderConfiguration, stInput chan STEvent) {
	folderPath := expandTilde(folder.Path)
	ignorePatterns := getIgnorePatterns(folder.ID)
	fsInput := make(chan string)
	c := make(chan notify.EventInfo, maxFiles)
	if err := notify.Watch(filepath.Join(folderPath, "..."), c, notify.All); err != nil {
		Warning.Println("Failed to install inotify handlers", err)
		informError("Failed to install inotify handler for " + folder.ID + ": " + err.Error())
		return
	}
	defer notify.Stop(c)
	go accumulateChanges(debounceTimeout, folder.ID, folderPath, dirVsFiles, stInput, fsInput, informChange)
	OK.Println("Watching " + folder.ID + ": " + folderPath)
	if folder.RescanIntervalS < 1800 && delayScan <= 0 {
		OK.Printf("The rescan interval of folder %s can be increased to 3600 (an hour) or even 86400 (a day) as changes should be observed immediately while syncthing-inotify is running.", folder.ID)
	}
	for {
		evPath := waitForEvent(c)
		Debug.Println("Change detected in: " + evPath + " (could still be ignored)")
		ev := relativePath(evPath, folderPath)
		if shouldIgnore(ignorePaths, ignorePatterns, ev) {
			continue
		}
		Trace.Println("Change detected in: " + evPath)
		fsInput <- ev
	}
}
示例#3
0
// watchFolder installs inotify watcher for a folder, launches
// goroutine which receives changed items. It never exits.
func watchFolder(folder FolderConfiguration, stInput chan STEvent) {
	folderPath, err := realPath(expandTilde(folder.Path))
	if err != nil {
		Warning.Println("Failed to install inotify handler for "+folder.Label+".", err)
		informError("Failed to install inotify handler for " + folder.Label + ": " + err.Error())
		return
	}
	ignores := ignore.New(false)
	Trace.Println("Getting ignore patterns for " + folder.Label)
	ignores.Load(filepath.Join(folderPath, ".stignore"))
	fsInput := make(chan string)
	c := make(chan notify.EventInfo, maxFiles)
	ignoreTest := func(absolutePath string) bool {
		relPath := relativePath(absolutePath, folderPath)
		return ignores.Match(relPath).IsIgnored()
	}
	notify.SetDoNotWatch(ignoreTest)
	if err := notify.Watch(filepath.Join(folderPath, "..."), c, notify.All); err != nil {
		if strings.Contains(err.Error(), "too many open files") || strings.Contains(err.Error(), "no space left on device") {
			msg := "Failed to install inotify handler for " + folder.Label + ". Please increase inotify limits, see http://bit.ly/1PxkdUC for more information."
			Warning.Println(msg, err)
			informError(msg)
			return
		} else {
			Warning.Println("Failed to install inotify handler for "+folder.Label+".", err)
			informError("Failed to install inotify handler for " + folder.Label + ": " + err.Error())
			return
		}
	}
	defer notify.Stop(c)
	go accumulateChanges(debounceTimeout, folder.ID, folderPath, dirVsFiles, stInput, fsInput, informChange)
	OK.Println("Watching " + folder.Label + ": " + folderPath)
	if folder.RescanIntervalS < 1800 && delayScan <= 0 {
		OK.Printf("The rescan interval of folder %s can be increased to 3600 (an hour) or even 86400 (a day) as changes should be observed immediately while syncthing-inotify is running.", folder.Label)
	}
	// will we ever get out of this loop?
	for {
		evAbsolutePath := waitForEvent(c)
		Debug.Println("Change detected in: " + evAbsolutePath + " (could still be ignored)")
		evRelPath := relativePath(evAbsolutePath, folderPath)
		if ignores.Match(evRelPath).IsIgnored() {
			Debug.Println("Ignoring", evAbsolutePath)
			continue
		}
		Trace.Println("Change detected in: " + evAbsolutePath)
		fsInput <- evRelPath
	}
}