Skip to content

Commit

Permalink
Do not attempt to reverse cloud rename if file is local only (case 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
foodprocessor committed Jan 3, 2025
1 parent 6a084a7 commit cd72f50
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions component/file_cache/file_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,7 @@ func (fc *FileCache) RenameFile(options internal.RenameFileOptions) error {
defer dflock.Unlock()

err := fc.NextComponent().RenameFile(options)
localOnly := os.IsNotExist(err)
err = fc.validateStorageError(options.Src, err, "RenameFile", true)
if err != nil {
log.Err("FileCache::RenameFile : %s failed to rename file [%s]", options.Src, err.Error())
Expand All @@ -1420,16 +1421,19 @@ func (fc *FileCache) RenameFile(options internal.RenameFileOptions) error {
localRenameErr := fc.renameCachedFile(localSrcPath, localDstPath, sflock, dflock)
if localRenameErr != nil {
// renameCachedFile only returns an error when we are at risk for data loss
// we must reverse the rename operation to prevent data loss
err := fc.NextComponent().RenameFile(internal.RenameFileOptions{
Src: options.Dst,
Dst: options.Src,
})
err = fc.validateStorageError(options.Src, err, "RenameFile", true)
if err != nil {
log.Err("FileCache::RenameFile : %s failed to reverse cloud rename to avoid data loss! [%v]", options.Src, err)
if !localOnly {
// we must reverse the cloud rename operation to prevent data loss
err := fc.NextComponent().RenameFile(internal.RenameFileOptions{
Src: options.Dst,
Dst: options.Src,
})
err = fc.validateStorageError(options.Src, err, "RenameFile", false)
if err != nil {
log.Err("FileCache::RenameFile : %s failed to reverse cloud rename to avoid data loss! [%v]", options.Src, err)
}
localRenameErr = errors.Join(localRenameErr, err)
}
return errors.Join(localRenameErr, err)
return localRenameErr
}

// update any open handles to the file with its new name
Expand Down

0 comments on commit cd72f50

Please sign in to comment.