func (sync *Unidirectional) syncDir(entry storage.DirectoryEntry) error { path := entry.Path() var ( targetEntry storage.Entry targetDirEntry storage.DirectoryEntry targetDir storage.Directory err error ok bool ) targetEntry, err = sync.to.Stat(path) if err != nil { return err } if targetDirEntry, ok = targetEntry.(storage.DirectoryEntry); !ok && targetEntry != nil { if err := targetEntry.Remove(); err != nil { return err } targetDirEntry = nil } if targetDirEntry != nil { return nil } sync.events <- &EventStartSyncing{entry: entry} targetDir, err = sync.to.Mkdir(path) if err != nil { return err } defer func() { sync.setLastErrorIfApplicable(targetDir.Close()) }() return nil }