Exemple #1
0
func ExampleCopyFile() {
	s := "This is a test of the util.CopyFile() function."
	t1 := path.Join(path.Dir(os.Args[0]), "test1.txt")
	t2 := path.Join(path.Dir(os.Args[0]), "test2.txt")
	err := ioutil.WriteFile(t1, []byte(s), os.FileMode(0666))
	if err != nil {
		log.Fatal(err)
	}
	err = util.CopyFile(t2, t1)
	if err != nil {
		log.Fatal(err)
	}
	b, err := ioutil.ReadFile(t2)
	if err != nil {
		log.Fatal(err)
	}
	err = os.Remove(t1)
	if err != nil {
		log.Fatal(err)
	}
	err = os.Remove(t2)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s\n", string(b))
	// Output: This is a test of the util.CopyFile() function.
}
Exemple #2
0
func (this *FsStore) PersistOffset(fileName string, offset int64) {
	//persist worker's offset
	path := fileName + ".tmp"
	fout, error := os.Create(path)
	if error != nil {
		log.Error(path, error)
		return
	}

	defer fout.Close()
	log.Debug("saved offset:", fileName, ":", offset)
	fout.Write([]byte(strconv.FormatInt(offset, 10)))
	util.CopyFile(path, fileName)
}