PathAlreadyExists
Describe the Bug
When creating multiple files simultaneously using beaker.hyperdrive.writeFile, files after the first will fail with an uncaught error.
index.html:1 Uncaught (in promise) Error: Uncaught Error: PathAlreadyExists: Path ... already exists.
To Reproduce
- Simultaneously create multiple files in a directory where a directory does not yet exist.
Expected Behavior
Considering the purpose of the function, either the API should fail every time when a directory does not exist or, better yet, the API should eat the error and continue.
Screenshots
Presumed unecessary. If needed can supply.
Environment
- OS: Windows 10
- Beaker Version: 1.0.0-prerelease.7
Additional Context
Presumed unecessary. If needed can supply.
Can you share what the code looks like for this?
writeFile() creates parent directories as-needed. I suspect what's happening is that concurrent calls to writeFile() are attempting to create those parent dirs at the same time, thus the issue. Go ahead and share a snippet so I can be sure I'm right about this.
Thanks for filing, does look like a legit bug.
Here's the inelegant code:
acceptedFiles.forEach(file => {
beaker.hyperdrive.readFile('hyper://' + address + locationFromFile(file), 'json').then(result => {
beaker.hyperdrive.writeFile('/cache/' + address + '/' + file + '.json', result, 'json');
if(file = 'follows' && distance > 0) {
result.forEach(follow => {
if(follow.address != undefined && !crawled.includes(follow.address)) crawl(distance - 1, follow.address, false);
});
}
});
});
acceptedFiles.forEach(file => {
beaker.hyperdrive.readFile('hyper://' + address + locationFromFile(file), 'json').then(result => {
beaker.hyperdrive.writeFile('/cache/' + address + '/' + file + '.json', result, 'json');
});