Esempio n. 1
0
File: veb.go Progetto: spydez/veb
// Calculates checksums of item in files chan, then puts file stats & xsum
// of changed files out on the changed chan.
// Does not look at file stats to determine change. This is purely about xsums.
func verifyHandler(root string, files, changed chan veb.IndexEntry, done chan int, log *veb.Log) {
	for f := range files {
		// save off old xsum for comparison
		oldXsum := f.Xsum

		// get file size & such
		err := veb.SetStats(root, &f)
		if err != nil {
			log.Err().Println("couldn't get stats:", err)
		}

		// calculate checksum hash
		err = veb.Xsum(&f, log)
		if err != nil {
			log.Err().Println("checksum for verify failed:", err)
		}

		// see if it changed...
		if !bytes.Equal(f.Xsum, oldXsum) {
			changed <- f
		}
	}
	done <- 1
}
Esempio n. 2
0
File: veb.go Progetto: spydez/veb
// Saves all updated/new files to index, so they are available for push/pull.
// Saves new file stats & current checksum of the file shown as new/changed.
func Commit(index *veb.Index, log *veb.Log) error {
	defer log.Un(log.Trace(COMMIT))
	var timer veb.Timer
	timer.Start()

	// check for changes
	files := make(chan veb.IndexEntry, CHAN_SIZE)
	go index.Check(files)

	// start handler pool working on files
	updates := make(chan veb.IndexEntry, CHAN_SIZE)
	done := make(chan int, MAX_HANDLERS)
	for i := 0; i < MAX_HANDLERS; i++ {
		go func() {
			for f := range files {
				// calculate checksum hash
				err := veb.Xsum(&f, log)
				if err != nil {
					log.Err().Println("checksum for verify failed:", err)
				}

				updates <- f
			}
			done <- 1
		}()
	}

	// done listener
	go func() {
		for i := 0; i < MAX_HANDLERS; i++ {
			<-done
		}
		close(updates)
	}()

	// update index
	var retVal error = nil
	numCommits := 0
	numErrors := 0
	first := true
	for f := range updates {
		err := index.Update(&f)
		if err != nil {
			log.Err().Println("index update failed:", err)
			fmt.Println("Error: Couldn't commit", f.Path, ":", err)
			retVal = fmt.Errorf("veb commit failed")
			numErrors++
		} else {
			if first {
				fmt.Println("----------------")
				fmt.Println("Committed files:")
				fmt.Println("----------------")
				first = false
			}
			fmt.Println(INDENT_F, f.Path)
			numCommits++
		}
	}

	// save index once everything's done
	index.Save()

	// info
	timer.Stop()
	fmt.Println("\nsummary:", numCommits, "commits,", numErrors,
		"errors in", timer.Duration())
	log.Info().Printf("%s (%d commits, %d errors) took %v\n",
		COMMIT, numCommits, numErrors, timer.Duration())
	return retVal
}