Skip to content

Commit

Permalink
Revert "resolveParentFolder with Files.createDirectories without conc…
Browse files Browse the repository at this point in the history
…urrent fix"

This reverts commit 212c386.
  • Loading branch information
TonyTangAndroid committed Sep 16, 2024
1 parent 5b77bd7 commit c2eae06
Showing 1 changed file with 4 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit c2eae06

Please sign in to comment.