[android] makeDirectoryAsync() succeeds, but still returns error "could not be created"
See original GitHub issueEnvironment
Environment: OS: macOS High Sierra 10.13.5 Node: 7.6.0 Yarn: 1.3.2 npm: 4.6.1 Watchman: 4.7.0 Xcode: Xcode 9.4 Build version 9F1027a Android Studio: 2.3 AI-162.4069837
Packages: (wanted => installed) expo: ^28.0.0 => 28.0.0 react: 16.3.1 => 16.3.1 react-native: https://github.com/expo/react-native/archive/sdk-28.0.0.tar.gz => 0.55.4
Have only seen the problem on Android so far. Standalone release build downloaded through Play store.
Steps to Reproduce
(Write your steps here:)
- Create a directory with makeDirectoryAsync()
Expected Behavior
Expect to receive no error.
Actual Behavior
makeDirectoryAsync() often returns “Error” … “could not be created”. However if I check getInfoAsync() after receiving the error, the directory is actually created.
The last Sentry report about this showed it was a Cubit X15 phone, Android 22.
Reproducible Demo
// Create any app folders that don't already exist
export const checkAndCreateFolder = async folder_path => {
const folder_info = await Expo.FileSystem.getInfoAsync(folder_path);
if (!Boolean(folder_info.exists)) {
// Create folder
try {
await FileSystem.makeDirectoryAsync(folder_path, {
intermediates: true
});
} catch (error) {
// Report folder creation error, include the folder existence before and now
const new_folder_info = await Expo.FileSystem.getInfoAsync(folder_path);
const debug = `checkAndCreateFolder: ${
error.message
} old:${JSON.stringify(folder_info)} new:${JSON.stringify(
new_folder_info
)}`;
console.log(debug);
Sentry.captureException(new Error(debug));
}
}
};
The Sentry reports show that before creation getInfoAsync() returned:
{"isDirectory":false,"exists":false}
And after makeDirectoryAsync() failed and returned “could not be created” getInfoAsync() shows it actually exists:
{"size":4096,"modificationTime":1532552616,"uri":"file:///data/data/com.test.test/files/ExperienceData/%2540test%252Ftest/subfolder","isDirectory":true,"exists":true}
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
I made a Snack to try to reproduce, but while doing so it became clear that this is probably a concurrency problem with multiple asynchronous calls the app is making to makeDirectoryAsync() in order to create the same folder.
So the error is probably “Directory already exists” (logging the error number in makeDirectoryAsync() would be handy).
Illustrated by this snack which simplifies it to just two consecutive calls to create the same directory: https://snack.expo.io/Hy1B_YgHQ
@kelvinlawson Could you please open an issue for the FileSystem module https://github.com/expo/expo-file-system/issues 💙