bun icon indicating copy to clipboard operation
bun copied to clipboard

[win][fs] There is no support of long paths

Open AlttiRi opened this issue 1 year ago • 4 comments

What version of Bun is running?

1.0.23

What platform is your computer?

Window 10

What steps can reproduce the bug?

import fs from "node:fs/promises";


const filePathAbs = "C:\\VeryLongName00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\\Again00000000000000000000000000000000\\[twitter] SpaceX—2024.01.17—1747633689276608977—GEDXkT3WUAAWxF3.jpg";
console.log(filePathAbs.length);
console.log(await fs.stat(filePathAbs));

What is the expected behavior?

315
Stats {
  ...
  size: 1182629,
  ...
}

What do you see instead?

315
ENOENT: No such file or directory
   errno: -4058
 syscall: "stat"

Additional information

BTW, 8.3 file path is supported:

const filePath83 = "C:\\VERYLO~1\\AGAIN0~1\\[twitter] SpaceX—2024.01.17—1747633689276608977—GEDXkT3WUAAWxF3.jpg";
console.log(filePath83.length); // 88
console.log(await fs.stat(filePath83)); // Stats { ... }

Rel:

  • https://github.com/oven-sh/bun/issues/8836

https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#skip-normalization

Unless the path starts exactly with \\?\ (note the use of the canonical backslash), it is normalized.

Why would you want to skip normalization? There are three major reasons:

  1. To get access to paths that are normally unavailable but are legal. A file or directory called hidden., for example, is impossible to access in any other way.
  2. To improve performance by skipping normalization if you've already normalized.
  3. To skip the MAX_PATH check for path length to allow for paths that are greater than 259 characters.

AlttiRi avatar Jan 18 '24 04:01 AlttiRi

Interesting, that adding "\\?\" helps.

While path.toNamespacedPath method is not implemented.

  • https://github.com/oven-sh/bun/issues/8247

https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#win32-file-namespaces https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#dos-device-paths https://doc.rust-lang.org/std/path/enum.Prefix.html#variants

AlttiRi avatar Jan 18 '24 04:01 AlttiRi

bun internally should be adding the \?\ prefix.

paperclover avatar Jan 18 '24 08:01 paperclover

Bump.

The released version is without it. I get the errors while file walking through files with long names.


BTW, also file scanning is slower than with Node.js. (I used it https://github.com/AlttiRi/keep-lister/releases) 44 seconds vs 34 ones.

AlttiRi avatar Apr 01 '24 17:04 AlttiRi

(Bun Version 1.1.38, Windows 11 Version 10.0.22631 Build 22631)

In my package.json I have:

  "scripts": {
    ...,
    "pretty": "bunx prettier ./**/*.{js,jsx,ts,tsx,json,css,scss,md,html} --write",
    ...
  },

When I do bun run pretty or bun pretty (with or without bunx in front of the "scripts" section in "package.json"), I get this:

λ bun run pretty
$ bunx prettier ./**/*.{js,jsx,ts,tsx,json,css,scss,md,html} --write
bun: File name too long:
error: script "pretty" exited with code 1

But when I run bunx prettier ./**/*.{js,jsx,ts,tsx,json,css,scss,md,html} --write directly, it works fine.

MicahLyle avatar Dec 09 '24 00:12 MicahLyle