in simplestore/src/main/java/com/uber/simplestore/impl/AtomicFile.java [216:231]
private static void rename(File source, File target) {
// We used to delete the target file before rename, but that isn't atomic, and the rename()
// syscall should atomically replace the target file. However in the case where the target
// file is a directory, a simple rename() won't work. We need to delete the file in this
// case because there are callers who erroneously called mBaseName.mkdirs() (instead of
// mBaseName.getParentFile().mkdirs()) before creating the AtomicFile, and it worked
// regardless, so this deletion became some kind of API.
if (target.isDirectory()) {
if (!target.delete()) {
Log.e(LOG_TAG, "Failed to delete file which is a directory " + target);
}
}
if (!source.renameTo(target)) {
Log.e(LOG_TAG, "Failed to rename " + source + " to " + target);
}
}