func (sync *Unidirectional) tempFileNameFor(entry storage.Entry) string { hash := sha1.New() _, _ = hash.Write([]byte(entry.Path())) _, _ = hash.Write([]byte(time.Now().String())) randomBytes := make([]byte, 32) for i := 0; i < 32; i++ { randomBytes[i] = byte(sync.rng.Int()) } _, _ = hash.Write(randomBytes) buffer := hash.Sum(make([]byte, 0, hash.Size())) return "csync_temp_" + hex.EncodeToString(buffer) }
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 }