beaker icon indicating copy to clipboard operation
beaker copied to clipboard

PathAlreadyExists

Open KyGost opened this issue 5 years ago • 2 comments

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

  1. 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.

KyGost avatar Sep 27 '20 12:09 KyGost

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.

pfrazee avatar Sep 27 '20 15:09 pfrazee

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);
        });
      }
    });
  });
(Pertinent bit:)
acceptedFiles.forEach(file => {
    beaker.hyperdrive.readFile('hyper://' + address + locationFromFile(file), 'json').then(result => {
      beaker.hyperdrive.writeFile('/cache/' + address + '/' + file + '.json', result, 'json');
});

KyGost avatar Sep 27 '20 16:09 KyGost