Filesystem (Web): Current directory does already exist
Bug Report
In our Sentry logs I increasingly see the error ‘Current directory does already exist.’ It is triggered when writing files where a path is specified. The recursive creation of directories is active.
https://github.com/ionic-team/capacitor-plugins/blob/aaa8658eb65b6c95ae231a3ed1547f3f78cd2cac/filesystem/src/web.ts#L316
Plugin(s)
@capacitor/filesystem 6.0.1
Capacitor Version
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 6.1.2
@capacitor/core: 6.1.2
@capacitor/android: 6.1.2
@capacitor/ios: 6.1.2
Installed Dependencies:
@capacitor/cli: 6.1.2
@capacitor/core: 6.1.2
@capacitor/ios: 6.1.2
@capacitor/android: 6.1.2
[success] iOS looking great! 👌
[success] Android looking great! 👌
Platform(s)
- Web
| Browser Version | Usage Percentage | Users |
|---|---|---|
| Chrome 126.0.0 | 10.65% | 103 |
| Chrome 127.0.0 | 9.93% | 96 |
| Edge 128.0.0 | 9.72% | 94 |
| Edge 126.0.0 | 7.76% | 75 |
| Edge 127.0.0 | 6.62% | 64 |
| Edge 129.0.0 | 5.89% | 57 |
| Firefox 130.0 | 5.38% | 52 |
| Firefox 129.0 | 5.38% | 52 |
| Mobile Safari 17.5 | 4.55% | 44 |
| Chrome 128.0.0 | 4.45% | 43 |
| Chrome 129.0.0 | 2.90% | 28 |
| Safari 17.5 | 2.48% | 24 |
| Operating System | Usage Percentage | Count |
|---|---|---|
| Windows >=10 | 66.84% | 635 |
| Android 10 | 11.16% | 106 |
| Mac OS X >=10.15.7 | 10.95% | 104 |
| iOS 17.5.1 | 4.95% | 47 |
| iOS 17.5 | 1.47% | 14 |
Code Reproduction
import { Directory, Filesystem } from '@capacitor/filesystem';
async function writeFile(file: string): Promise<void> {
for (let i = 0; i < 100; i++) {
const fileName = `${file}_${i}.txt`;
const { uri } = await Filesystem.writeFile({
path: `/my/file/in/directory/${fileName}`,
directory: Directory.Cache,
recursive: true,
data: new Blob(["test"], { type: 'text/plain' }),
});
console.log(`File written to: ${uri}`);
}
}
writeFile('exampleFile').catch(console.error);
Current Behavior
I write multiple files in parallel to a new directory with recursive set to true. This appears to call mkdir internally which in some cases errors because the directory was just created.
Expected Behavior
Writing with recursive should call mkdir with a try/catch or else allow mkdir to fail gracefully when the directory already exists.
Additional Context
https://github.com/ionic-team/capacitor-plugins/issues/1358
This issue needs more information before it can be addressed. In particular, the reporter needs to provide a minimal sample app that demonstrates the issue. If no sample app is provided within 15 days, the issue will be closed.
Please see the Contributing Guide for how to create a Sample App.
Thanks! Ionitron 💙
It looks like this issue didn't get the information it needed, so I'll close it for now. If I made a mistake, sorry! I am just a bot.
Have a great day! Ionitron 💙
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.