jvilk / BrowserFS

BrowserFS is an in-browser filesystem that emulates the Node JS filesystem API and supports storing and retrieving files from various backends.
Other
3.07k stars 218 forks source link

mkdir under multiple hierarchy isn't working #327

Closed arunkumar413 closed 1 year ago

arunkumar413 commented 2 years ago
fs.mkdir('/home', 1, function () {
    console.log('directory created');
  });

  fs.mkdir('/src', 1, function () {
    console.log('src created');
  });

  fs.mkdir('./components', 1, function () {
    console.log('src created');
  });

  fs.mkdir('/components/test', function () {   // this isn't creating the `test` directory
    console.log('src created');
  });
arunkumar413 commented 2 years ago

Here is the code sandbox

https://stackblitz.com/edit/react-l4u5ao?file=src%2FApp.js

neimanpinchas commented 1 year ago

I guess the components isn't yet created, you must either

nest the callbacks

use fs.mkdirSync but use a backend that supports sync

james-pre commented 1 year ago

@arunkumar413 @neimanpinchas

The optional options argument can be an integer specifying mode (permission and sticky bits), or an object with a mode property and a recursive property indicating whether parent directories should be created. Calling fs.mkdir() when path is a directory that exists results in an error only when recursive is false.

When using fs.mkdir for nested directories you should set recursive to true in the options.