Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs.mkdir, fs.mkdtemp(Sync) return ENOENT for the documentation example (Windows, run from git bash) #14960

Closed
lll000111 opened this issue Aug 21, 2017 · 3 comments
Labels
fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform.

Comments

@lll000111
Copy link

lll000111 commented Aug 21, 2017

  • Version: v8.4.0
  • Platform: Windows 10
  • Subsystem: git for Windows bash

The problem does not occur when node is started from a Windows shell - so it may be a git bash bug in the end?

Originally reported as flow-upgrade issue: facebook/flow#4647 (comment)

Code taken from https://nodejs.org/dist/latest-v8.x/docs/api/fs.html#fs_fs_mkdtemp_prefix_options_callback

fs.mkdtemp('/tmp/foo-', (err, folder) => {
  if (err) throw err;
  console.log(folder);
  // Prints: /tmp/foo-itXde2
});

When I run this from the node console started in the git for Windows bash I get

> fs.mkdtemp('/tmp/foo-', (err, folder) => {
...   if (err) throw err;
...   console.log(folder);
...   // Prints: /tmp/foo-itXde2
... });
undefined
> Error: ENOENT: no such file or directory, mkdtemp '/tmp/foo-XXXXXX'

/tmp exists and is accessible and writable, I can run mkdir /tmp/foo _from the bash command line.

The problem becomes visible in the full error message:

> { Error: ENOENT: no such file or directory, mkdir 'C:\tmp\FOO'
  errno: -4058,
  code: 'ENOENT',
  syscall: 'mkdir',
  path: 'C:\\tmp\\FOO' }

Highlight: path: 'C:\\tmp\\FOO'

@lll000111
Copy link
Author

lll000111 commented Aug 21, 2017

Update, actually the path translation issue is not so clear, I only get the "C" drive absolute path from mkdir but mkdtemp shows the correct path (still shows the exact same behavior though, both the problem and the workaround):

$ node
> fs.mkdir('/tmp/FOO', err => console.error(err))
undefined
> { Error: ENOENT: no such file or directory, mkdir 'C:\tmp\FOO'
  errno: -4058,
  code: 'ENOENT',
  syscall: 'mkdir',
  path: 'C:\\tmp\\FOO' }

> fs.mkdtemp('/tmp/FOO', err => console.error(err))
undefined
> { Error: ENOENT: no such file or directory, mkdtemp '/tmp/FOOXXXXXX'
  errno: -4058,
  code: 'ENOENT',
  syscall: 'mkdtemp',
  path: '/tmp/FOOXXXXXX' }

By the way, if I create C:\tmp (outside node) all those commands work:

me@me-MAINPC MINGW64 ~/Projects/one (master)
$ mkdir /C/tmp

me@me-MAINPC MINGW64 ~/Projects/one (master)
$ node
> fs.mkdir('/tmp/FOO', err => console.error(err))
undefined
> null

> fs.mkdtemp('/tmp/FOO', err => console.error(err))
undefined
> null

@bzoz
Copy link
Contributor

bzoz commented Aug 21, 2017

/tmp/... will be resolved to C:\tmp\... on Windows. If C:\tmp is not present you will get ENOENT, just like with fs.mkdtemp('/nonexisting/...') on Linux.

You should probably use platform specific temp folder, something like:

const tempFolder = process.platform === 'win32' ? process.env['TEMP'] : '/tmp';
fs.mkdtemp(path.join(tempFolder, 'foo-'), ...);

@mscdex mscdex added fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform. labels Aug 21, 2017
@bzoz
Copy link
Contributor

bzoz commented Aug 24, 2017

@lll000111 do you still have issue with mkdtemp?

bzoz added a commit to JaneaSystems/node that referenced this issue Sep 14, 2017
jasnell pushed a commit that referenced this issue Sep 20, 2017
PR-URL: #15408
Fixes: #14960
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Qard pushed a commit to Qard/ayo that referenced this issue Sep 21, 2017
PR-URL: nodejs/node#15408
Fixes: nodejs/node#14960
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Qard pushed a commit to Qard/ayo that referenced this issue Sep 21, 2017
PR-URL: nodejs/node#15408
Fixes: nodejs/node#14960
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
MylesBorins pushed a commit that referenced this issue Oct 17, 2017
PR-URL: #15408
Fixes: #14960
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
MylesBorins pushed a commit that referenced this issue Oct 25, 2017
PR-URL: #15408
Fixes: #14960
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants