Skip to content

Commit

Permalink
Refactor 'putObject' for redundant Files.exists() check after writing…
Browse files Browse the repository at this point in the history
… tmpFile
  • Loading branch information
doulikecookiedough committed Oct 24, 2023
1 parent 39074e1 commit 5185d69
Showing 1 changed file with 3 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -993,31 +993,11 @@ protected ObjectInfo putObject(
);

// Move object
File permFile = objRealPath.toFile();
move(tmpFile, permFile, "object");
logFileHashStore.debug(
"FileHashStore.putObject - Moving object: " + tmpFile + ". Destination: " + objRealPath
"FileHashStore.putObject - Move object success, permanent address: " + objRealPath
);
if (Files.exists(objRealPath)) {
boolean deleteStatus = tmpFile.delete();
if (!deleteStatus) {
String errMsg =
"FileHashStore.putObject - Object is found to be a duplicate after writing"
+ " tmpFile. Did not move object and failed to delete tmpFile: " + tmpFile
.getName();
logFileHashStore.error(errMsg);
throw new IOException(errMsg);
}
String errMsg =
"FileHashStore.putObject - Did not move object, duplicate file found for pid: "
+ pid + ". Deleted tmpFile: " + tmpFile.getName();
logFileHashStore.info(errMsg);
throw new PidObjectExistsException(errMsg);
} else {
File permFile = objRealPath.toFile();
move(tmpFile, permFile, "object");
logFileHashStore.debug(
"FileHashStore.putObject - Move object success, permanent address: " + objRealPath
);
}

// Create ObjectInfo to return with pertinent data
return new ObjectInfo(objectCid, storedObjFileSize, hexDigests);
Expand Down

0 comments on commit 5185d69

Please sign in to comment.