From c2eae06bfa8235288ada095f11b534ff570b9250 Mon Sep 17 00:00:00 2001 From: Tony Tang Date: Mon, 16 Sep 2024 09:17:56 -0700 Subject: [PATCH] Revert "resolveParentFolder with Files.createDirectories without concurrent fix" This reverts commit 212c3865d8837ab417d8fd6880b8efb6c335bbfc. --- .../com/uber/simplestore/impl/AtomicFile.java | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/simplestore/src/main/java/com/uber/simplestore/impl/AtomicFile.java b/simplestore/src/main/java/com/uber/simplestore/impl/AtomicFile.java index 4dd4c50..2273d7a 100644 --- a/simplestore/src/main/java/com/uber/simplestore/impl/AtomicFile.java +++ b/simplestore/src/main/java/com/uber/simplestore/impl/AtomicFile.java @@ -21,9 +21,6 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - import org.jetbrains.annotations.Nullable; /* @@ -96,7 +93,10 @@ public FileOutputStream startWrite() throws IOException { try { return new FileOutputStream(mNewName); } catch (FileNotFoundException e) { - resolveParentFolder(e); + File parent = mNewName.getParentFile(); + if (!parent.mkdirs()) { + throw new IOException("Failed to create directory for " + mNewName); + } try { return new FileOutputStream(mNewName); } catch (FileNotFoundException e2) { @@ -105,22 +105,6 @@ public FileOutputStream startWrite() throws IOException { } } - private void resolveParentFolder(FileNotFoundException rawError) throws IOException { - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - Path parentPath = mNewName.toPath().getParent(); - if (parentPath != null && !Files.exists(parentPath)) { - Files.createDirectories(parentPath); - } else { - throw rawError; - } - } else { - File parent = mNewName.getParentFile(); - if (!parent.mkdirs()) { - throw rawError; - } - } - } - /** * Call when you have successfully finished writing to the stream returned by {@link * #startWrite()}. This will close, sync, and commit the new data. The next attempt to read the