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.promises.realpath errors with long paths (fs.realpath.native does not error) #51031

Closed
sapphi-red opened this issue Dec 3, 2023 · 1 comment · Fixed by #51032
Closed

Comments

@sapphi-red
Copy link
Contributor

sapphi-red commented Dec 3, 2023

Version

v20.9.0, v20.10.0

Platform

Microsoft Windows NT 10.0.22621.0 x64

Subsystem

fs

What steps will reproduce the bug?

Save the following script in a path that has more than 10 characters (e.g. C:\\abcdefghi).
Then, run it.

import { resolve } from 'node:path'
import { realpath, writeFile } from 'node:fs/promises'
import { realpath as realpathCallback, realpathSync } from 'node:fs'

const p = `./test_${'a'.repeat(240)}.txt`

await writeFile(p, '')

console.log('length: ', resolve(p).length)

try {
  await realpath(p)
} catch (e) {
  console.log('error with fs.promises.realpath', e)
}

try {
  await new Promise((res, rej) => {
    realpathCallback(p, (err, resolved) => {
      if (err) {
        rej(err)
        return
      }
      res(resolved)
    })
  })
} catch (e) {
  console.log('error with fs.realpath', e)
}

try {
  await new Promise((res, rej) => {
    realpathCallback.native(p, (err, resolved) => {
      if (err) {
        rej(err)
        return
      }
      res(resolved)
    })
  })
} catch (e) {
  console.log('error with fs.realpath.native', e)
}

try {
  realpathSync(p)
} catch (e) {
  console.log('error with fs.realpathSync', e)
}

try {
  realpathSync.native(p)
} catch (e) {
  console.log('error with fs.realpathSync.native', e)
}

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

No error happens.

What do you see instead?

The following error happens:

error with fs.promises.realpath [Error: ENOENT: no such file or directory, realpath './test_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt']

Additional information

Maybe related to #50753, but running (Get-Item -Path "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem").GetValue("LongPathsEnabled") (in both normal mode and admin mode) returns 0 on my machine.

Also #39721 might be related.

@sapphi-red
Copy link
Contributor Author

node/lib/fs.js

Lines 2931 to 2938 in 23031d9

realpath.native = (path, options, callback) => {
callback = makeCallback(callback || options);
options = getOptions(options);
path = getValidatedPath(path);
const req = new FSReqCallback();
req.oncomplete = callback;
binding.realpath(pathModule.toNamespacedPath(path), options.encoding, req);
};

async function realpath(path, options) {
options = getOptions(options);
path = getValidatedPath(path);
return await PromisePrototypeThen(
binding.realpath(path, options.encoding, kUsePromises),
undefined,
handleErrorFromBinding,
);
}

It seems pathModule.toNamespacedPath is missing for fs.promises, will make a PR.

sapphi-red added a commit to sapphi-red/node that referenced this issue Dec 3, 2023
Unlike other fs functions that work with paths, realpath isn't
using pathModule.toNamespacedPath prior to calling libuv function. This
is causing issues on windows.

Windows long path test is also improved to cover the mentioned issue.

Fixes: nodejs#51031
sapphi-red added a commit to sapphi-red/node that referenced this issue Dec 3, 2023
Unlike other fs functions that work with paths, realpath isn't
using pathModule.toNamespacedPath prior to calling libuv function. This
is causing issues on windows.

Windows long path test is also improved to cover the mentioned issue.

Fixes: nodejs#51031
sapphi-red added a commit to sapphi-red/node that referenced this issue Dec 5, 2023
Unlike other fs functions that work with paths, realpath isn't
using pathModule.toNamespacedPath prior to calling libuv function. This
is causing issues on windows.

Windows long path test is also improved to cover the mentioned issue.

Fixes: nodejs#51031
nodejs-github-bot pushed a commit that referenced this issue Dec 28, 2023
Unlike other fs functions that work with paths, realpath isn't
using pathModule.toNamespacedPath prior to calling libuv function. This
is causing issues on windows.

Windows long path test is also improved to cover the mentioned issue.

Fixes: #51031
PR-URL: #51032
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
RafaelGSS pushed a commit that referenced this issue Jan 2, 2024
Unlike other fs functions that work with paths, realpath isn't
using pathModule.toNamespacedPath prior to calling libuv function. This
is causing issues on windows.

Windows long path test is also improved to cover the mentioned issue.

Fixes: #51031
PR-URL: #51032
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
richardlau pushed a commit that referenced this issue Mar 25, 2024
Unlike other fs functions that work with paths, realpath isn't
using pathModule.toNamespacedPath prior to calling libuv function. This
is causing issues on windows.

Windows long path test is also improved to cover the mentioned issue.

Fixes: #51031
PR-URL: #51032
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
richardlau pushed a commit that referenced this issue Mar 25, 2024
Unlike other fs functions that work with paths, realpath isn't
using pathModule.toNamespacedPath prior to calling libuv function. This
is causing issues on windows.

Windows long path test is also improved to cover the mentioned issue.

Fixes: #51031
PR-URL: #51032
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant