jprichardson / node-fs-extra

Node.js: extra methods for the fs object like copy(), remove(), mkdirs()
MIT License
9.44k stars 776 forks source link

Race condition in mkdir call #967

Closed mistersender closed 1 year ago

mistersender commented 1 year ago

I ran into an issue while using storybook recently, wherein it is copying static files into a directory using fs-extra. For my particular project, I had a couple of static file locations and were copying the multiple sources to a single destination. Ran into an issue that I think comes down to a race condition of sorts, where fs-extra believes the directory to not exist, even though it does because it just created it, and it therefore throws an error on the mkdir call. Here is the offending line: https://github.com/jprichardson/node-fs-extra/blob/master/lib/copy/copy.js#L157

error thrown:

[Error: EEXIST: file already exists, mkdir '/thefilelocation'] {
  errno: -17,
  code: 'EEXIST',
  syscall: 'mkdir',
  path: '/thefilelocation'
}

would something like this do the trick? if (err && !(err.code === 'EEXIST' && opts.overwrite))

i'm nervous to change such a broad implementation for my one use case!

RyanZim commented 1 year ago

Known bug in storybook's usage; see https://github.com/jprichardson/node-fs-extra/issues/964 for details. I believe it's been fixed, but not sure on the storybook fix release status.

mistersender commented 1 year ago

ah, excellent- thank you!