itinance / itinance/react-native-fs

RNFS.writeFile() -> ENOENT: open failed: EEXIST (File exists) - if file is deleted manually

Open
#1,078 16 comments 7 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

On a real Android device, `RNFS.writeFile()` fails saying `ENOENT: open failed: EEXIST (File exists)`, while `RNFS.exists()` returns `false`. This occurs after the file was created by the app, and then deleted manually from the file system. This problem does NOT occur on an Android emulator.

**Scenario to reproduce:**
ON A REAL DEVICE:
1. Use RNFS.writeFile() to create a file
2. Using a file access software, e.g. Google Files, delete the created file (above).
3. Try to re-create the file again using RNFS.writeFile()
4. You get an error `ENOENT: open failed: EEXIST (File exists)`, while it has been deleted, and the result of `RNFS.exists()` confirms that it is not there?!

**Device Infomation:**
```
Samsung Galaxy S10+
Android Version: 11
One UI Version: 3.1
Google Play system update: 1 August 2021
Kernel version: 4.14.113.22340597
#1 Wed Dec 1 11:14:06 KST 2021
```

**Code:**
```javascript
try {
const fileExists = await RNFS.exists(fullPath);
console.log("fileExists:", fileExists, "fullPath:", fullPath, ); // fileExists: false - fullPath: /storage/emulated/0/Download/myFileName.csv

if (fileExists) {
// Execution never reaches this point
console.log("inside if statement", );
await RNFS.unlink(fullPath);
console.log("file deleted");
}

// The following statement triggers the catch (below)
await RNFS.writeFile(fullPath, fileContents, "utf8");

// execution never reaches this point
console.log("file Written");
}
catch (err) {
console.error("err:", err ); // err: [Error: ENOENT: open failed: EEXIST (File exists), open '/storage/emulated/0/Download/myFileName.csv']
}
```

**Versions:**
```
"react-native": "0.66.4",
"react-native-fs": "^2.18.0",
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.