Skip to content

Commit

Permalink
Allow override target files again to be sure.
Browse files Browse the repository at this point in the history
  • Loading branch information
EmileSonneveld committed Nov 6, 2024
1 parent 63a39b5 commit 6a9bc4b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,20 @@ object CreoS3Utils {
}
}

def moveOverwriteWithRetries(oldPath: Path, newPath: Path): Unit = {
def moveOverwriteWithRetries(oldPath: String, newPath: String): Unit = {
var try_count = 1
breakable {
while (true) {
try {
if (assetExists(newPath.toString)) {
if (assetExists(newPath)) {
// It might be a partial result of a previous failing task.
logger.info(f"Will replace $newPath. (try $try_count)")
assetDelete(newPath)
}
Files.deleteIfExists(newPath)
Files.move(oldPath, newPath)
moveAsset(oldPath, newPath)
break
} catch {
case e: FileAlreadyExistsException =>
case e: Exception =>
// Here if another executor wrote the file between the delete and the move statement.
try_count += 1
if (try_count > 5) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ package object geotiff {
if (!CreoS3Utils.isS3(parentDirectory.toString)) {
Files.createDirectories(destinationPath.getParent)
}
CreoS3Utils.moveAsset(absoluteFilePath, destinationPath.toString)
CreoS3Utils.moveOverwriteWithRetries(absoluteFilePath, destinationPath.toString)
destinationPath
}

Expand Down Expand Up @@ -923,7 +923,7 @@ package object geotiff {
CreoS3Utils.uploadToS3(tempFile, correctS3Path)
} else {
// Retry should not be needed at this point, but it is almost free to keep it.
CreoS3Utils.moveOverwriteWithRetries(tempFile, Path.of(path))
CreoS3Utils.moveOverwriteWithRetries(tempFile.toString, path)
path
}
}
Expand Down

0 comments on commit 6a9bc4b

Please sign in to comment.