本文整理匯總了Golang中tmsu/storage.Storage.UpdateFile方法的典型用法代碼示例。如果您正苦於以下問題:Golang Storage.UpdateFile方法的具體用法?Golang Storage.UpdateFile怎麽用?Golang Storage.UpdateFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tmsu/storage.Storage
的用法示例。
在下文中一共展示了Storage.UpdateFile方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: repairModified
func (command RepairCommand) repairModified(store *storage.Storage, modified fileIdAndInfoMap) error {
if command.verbose {
log.Info("repairing modified files")
}
for path, fileIdAndStat := range modified {
fileId := fileIdAndStat.fileId
stat := fileIdAndStat.stat
log.Infof("%v: modified", path)
fingerprint, err := fingerprint.Create(path)
if err != nil {
return fmt.Errorf("%v: could not create fingerprint: %v", path, err)
}
if !command.pretend {
_, err := store.UpdateFile(fileId, path, fingerprint, stat.ModTime(), stat.Size(), stat.IsDir())
if err != nil {
return fmt.Errorf("%v: could not update file in database: %v", path, err)
}
}
}
return nil
}
示例2: repairModified
func repairModified(store *storage.Storage, modified fileIdAndInfoMap, pretend bool, fingerprintAlgorithm string) error {
log.Infof(2, "repairing modified files")
for path, fileIdAndStat := range modified {
fileId := fileIdAndStat.fileId
stat := fileIdAndStat.stat
log.Infof(1, "%v: modified", path)
fingerprint, err := fingerprint.Create(path, fingerprintAlgorithm)
if err != nil {
return fmt.Errorf("%v: could not create fingerprint: %v", path, err)
}
if !pretend {
_, err := store.UpdateFile(fileId, path, fingerprint, stat.ModTime(), stat.Size(), stat.IsDir())
if err != nil {
return fmt.Errorf("%v: could not update file in database: %v", path, err)
}
}
}
return nil
}
示例3: repairMoved
func (command RepairCommand) repairMoved(store *storage.Storage, missing databaseFileMap, untagged fileInfoMap) error {
if command.verbose {
log.Info("repairing moved files")
}
moved := make([]string, 0, 10)
for path, dbFile := range missing {
if command.verbose {
log.Infof("%v: searching for new location", path)
}
for candidatePath, stat := range untagged {
if stat.Size() == dbFile.Size {
fingerprint, err := fingerprint.Create(candidatePath)
if err != nil {
return fmt.Errorf("%v: could not create fingerprint: %v", path, err)
}
if fingerprint == dbFile.Fingerprint {
log.Infof("%v: moved to %v", path, candidatePath)
moved = append(moved, path)
if !command.pretend {
_, err := store.UpdateFile(dbFile.Id, candidatePath, dbFile.Fingerprint, stat.ModTime(), dbFile.Size, dbFile.IsDir)
if err != nil {
return fmt.Errorf("%v: could not update file in database: %v", path, err)
}
}
delete(untagged, candidatePath)
break
}
}
}
}
for _, path := range moved {
delete(missing, path)
}
return nil
}