예제 #1
0
func ShouldIgnore(uri string) bool {

	GetIgnoredFiles()

	dotDirURI := filesystem.GetDotDirURI()

	_, fileName := filepath.Split(uri)

	return strings.HasPrefix(uri, dotDirURI) && ignoredFiles[fileName]
}
예제 #2
0
func loadDotIgnore() {

	dotDirURI := filesystem.GetDotDirURI()
	dotIgnoreUri := filepath.Join(dotDirURI, ".dotignore")

	dotIgnoreFile, err := os.Open(dotIgnoreUri)
	if err != nil {
		return
	}
	defer dotIgnoreFile.Close()

	scanner := bufio.NewScanner(dotIgnoreFile)
	for scanner.Scan() {
		line := scanner.Text()
		if strings.HasPrefix(line, "#") {
			continue
		}
		ignoredFiles[line] = true
	}
}
예제 #3
0
파일: main.go 프로젝트: drpotato/dotdot
func main() {

	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		log.Fatal(err)
	}
	defer watcher.Close()

	done := make(chan bool)

	go func() {
		for {
			select {
			case event := <-watcher.Events:
				if dotignore.ShouldIgnore(event.Name) {
					continue
				}
				switch event.Op {
				case fsnotify.Create:
					log.Println("dotfile added:", event.Name)
					err = filesystem.LinkDotFile(event.Name)
				case fsnotify.Remove:
					log.Println("dotfile removed:", event.Name)
					err = filesystem.UnLinkDotFile(event.Name)
				case fsnotify.Chmod:
					log.Println("irrelevant operation:", event)
				case fsnotify.Rename:
					log.Println("irrelevant operation:", event)
				case fsnotify.Write:
					log.Println("irrelevant operation:", event)
				}
			case err := <-watcher.Errors:
				log.Println("error:", err)
			}
		}
	}()

	dotDir := filesystem.GetDotDirURI()

	files, err := ioutil.ReadDir(dotDir)
	if err != nil {
		log.Fatal(err)
	}
	for _, file := range files {
		if dotignore.ShouldIgnore(file.Name()) {
			continue
		}
		err = filesystem.LinkDotFile(file.Name())
		if err != nil {
			log.Print(err)
		}
	}

	err = watcher.Add(dotDir)
	if err != nil {
		log.Fatal(err)
	}

	log.Println("watching", dotDir)

	<-done
}