bare-fs 4.4.5 → 4.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +30 -25
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -737,31 +737,36 @@ async function mkdir(filepath, opts, cb) {
737
737
  filepath = toNamespacedPath(filepath)
738
738
 
739
739
  if (opts.recursive) {
740
+ let err = null
740
741
  try {
741
- await mkdir(filepath, { mode })
742
- } catch (err) {
743
- if (err.code !== 'ENOENT' && (await stat(filepath)).isDirectory()) {
744
- return ok(cb)
745
- }
746
-
747
- while (filepath.endsWith(path.sep)) filepath = filepath.slice(0, -1)
748
- const i = filepath.lastIndexOf(path.sep)
749
- if (i <= 0) return fail(err, cb)
750
-
751
- await mkdir(filepath.slice(0, i), { mode, recursive: true })
752
-
753
742
  try {
754
743
  await mkdir(filepath, { mode })
755
744
  } catch (err) {
756
- if ((await stat(filepath)).isDirectory()) {
745
+ if (err.code !== 'ENOENT' && (await stat(filepath)).isDirectory()) {
757
746
  return ok(cb)
758
747
  }
759
748
 
760
- return fail(err, cb)
749
+ while (filepath.endsWith(path.sep)) filepath = filepath.slice(0, -1)
750
+ const i = filepath.lastIndexOf(path.sep)
751
+ if (i <= 0) return fail(err, cb)
752
+
753
+ await mkdir(filepath.slice(0, i), { mode, recursive: true })
754
+
755
+ try {
756
+ await mkdir(filepath, { mode })
757
+ } catch (err) {
758
+ if ((await stat(filepath)).isDirectory()) {
759
+ return ok(cb)
760
+ }
761
+
762
+ return fail(err, cb)
763
+ }
761
764
  }
765
+ } catch (e) {
766
+ err = e
762
767
  }
763
768
 
764
- return ok(cb)
769
+ return done(err, cb)
765
770
  }
766
771
 
767
772
  using req = FileRequest.borrow()
@@ -878,6 +883,7 @@ async function rm(filepath, opts, cb) {
878
883
 
879
884
  filepath = toNamespacedPath(filepath)
880
885
 
886
+ let err = null
881
887
  try {
882
888
  const st = await lstat(filepath)
883
889
 
@@ -897,21 +903,20 @@ async function rm(filepath, opts, cb) {
897
903
  await rmdir(filepath)
898
904
  }
899
905
  } else {
900
- fail(
901
- new FileError('is a directory', {
902
- operation: 'rm',
903
- code: 'EISDIR',
904
- path: filepath
905
- }),
906
- cb
907
- )
906
+ throw new FileError('is a directory', {
907
+ operation: 'rm',
908
+ code: 'EISDIR',
909
+ path: filepath
910
+ })
908
911
  }
909
912
  } else {
910
913
  await unlink(filepath)
911
914
  }
912
- } catch (err) {
913
- if (err.code !== 'ENOENT' || !opts.force) fail(err, cb)
915
+ } catch (e) {
916
+ if (e.code !== 'ENOENT' || !opts.force) err = e
914
917
  }
918
+
919
+ return done(err, cb)
915
920
  }
916
921
 
917
922
  function rmSync(filepath, opts) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-fs",
3
- "version": "4.4.5",
3
+ "version": "4.4.6",
4
4
  "description": "Native file system operations for Javascript",
5
5
  "exports": {
6
6
  "./package": "./package.json",