Beispiel #1
0
func HandleCreate(ctx syncer.Context, l uri.Uri, r uri.Uri) error {
	if l.ModTime().Sub(r.ModTime()) < 0 {
		return ctx.Finish()
	}
	var err error
	for {
		err = r.Create(l.IsDir(), l.Mode())
		if err == nil {
			break
		}
		time.Sleep(time.Minute * 1)
	}
	ctx.EmitLog(syncer.TypeInfo, "create ", r.Uri())
	return nil
}
Beispiel #2
0
func HandleWrite(ctx syncer.Context, l uri.Uri, r uri.Uri) error {
	if l.ModTime().Sub(r.ModTime()) < 0 {
		return ctx.Finish()
	}
	var (
		reader io.ReadCloser
		writer io.WriteCloser
		err    error
	)

	for {
		reader, err = l.OpenRead()
		if err == nil {
			break
		}
		time.Sleep(time.Second * 20)
	}
	for {
		writer, err = r.OpenWrite()
		if err == nil {
			break
		}
		time.Sleep(time.Minute * 10)
	}
	defer reader.Close()
	defer writer.Close()
	_, err = io.Copy(writer, reader)
	if err != nil {
		ctx.EmitLog(syncer.TypeError, err)
	}
	ctx.EmitLog(syncer.TypeInfo, "write to ", r.Uri())
	return err
}
Beispiel #3
0
func HandleAddNewWatch(ctx syncer.Context, l uri.Uri, r uri.Uri) error {

	if filepath.Base(l.Abs()) == ".git" {
		return ctx.Finish()
	}
	if !l.IsDir() {
		return nil
	}
	err := ctx.AddWatch(l)
	if err != nil {
		ctx.EmitLog(syncer.TypeError, err)
	}

	return nil
}