func (p *SyncPair) handleCreate(lName uri.Uri) { rName, err := p.ToRight(lName) if err != nil { logger.Error(err.Error()) return } if !lName.ModTime().After(rName.ModTime()) { return } for { err := rName.Create(lName.IsDir(), lName.Mode()) if err == nil { break } else { time.Sleep(time.Second * 1) } } if rName.IsDir() { return } //first time copy file. lFd, rFd := copyFile(rName, lName) defer lFd.Close() defer rFd.Close() logger.Info("Sync succesfully: " + lName.Abs() + " ==> " + rName.Abs()) }
func (p *SyncPair) handleRemove(lName uri.Uri) { fmt.Println(lName.Abs(), "removed") rName, err := p.ToRight(lName) if err != nil { logger.Error(err.Error()) return } if !rName.Exist() { return } for { err := rName.Remove() if err != nil { fmt.Println(err.Error()) time.Sleep(time.Second * 1) } else { break } } fmt.Println(rName.Abs(), "removed") err = p.watcher.Remove(lName.Abs()) if err != nil { logger.Warn(err.Error()) } logger.Info("Remove successfully: " + rName.Abs()) return }
func (p *SyncPair) WatchLeft(left uri.Uri) error { for { err := p.watcher.Add(left.Abs()) if err != nil { err = p.watcher.Add(left.Abs()) } else { break } } return nil }
func (p *SyncPair) handleWrite(lFile uri.Uri) { var err error rFile, err := p.ToRight(lFile) if err != nil { logger.Error(err.Error()) return } lFd, rFd := copyFile(rFile, lFile) defer lFd.Close() defer rFd.Close() logger.Info("Sync file succesfully: " + lFile.Abs() + " ==> " + rFile.Abs()) }
func (p *SyncPair) handleRename(lName uri.Uri) { fmt.Println(lName.Abs(), "rename") }