-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[win][fs] Some functions do not support tailing dot "."
and space " "
in a filename
#8836
Comments
By the way, I expected that it will not support ADS (Alternate Data Streams) too, but it works fine. import fs from "node:fs/promises";
await fs.writeFile("ads.txt", `data:ads.txt`);
await fs.writeFile("ads.txt:metadata", `metadata:ads.txt`); // Alternate Data Stream
console.log((await fs.readFile("ads.txt")).toString());
console.log((await fs.readFile("ads.txt:metadata")).toString());
console.log((await fs.stat("ads.txt:metadata")).size);
await fs.unlink("ads.txt");
Anyway, it makes sense to add a test for it too in |
It's strange, but adding https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#skip-normalization
import fs from "node:fs/promises";
import path from "node:path";
for (const filename of [" spaces.txt ", ".dots.txt."]) {
// const prefixed_filename = path.toNamespacedPath(path.resolve(filename)); // still does not work #8247
const prefixed_filename = "\\\\?\\" + path.resolve(filename);
console.log(prefixed_filename);
try {
await fs.writeFile(prefixed_filename, `data:"${filename}"`);
} catch (e) { console.error(e); }
try {
console.log((await fs.readFile(prefixed_filename)).toString());
} catch (e) { console.error(e); }
try {
console.log((await fs.stat(prefixed_filename)).size);
} catch (e) { console.error(e); }
try {
await fs.unlink(filename);
continue;
} catch (e) { console.error(e); }
try {
const newName = filename.replaceAll(/^[ .]+|[ .]+$/g, "");
await fs.rename(prefixed_filename, newName);
} catch (e) { console.error(e); }
} More over, in this case In this case the prefix works: |
Well, this works in Bun: import fs from "node:fs/promises";
import path from "node:path";
for (const filename of [" spaces.txt ", ".dots.txt."]) {
try {
await fs.writeFile(filename, `data:"${filename}"`);
} catch (e) { console.error(e); }
const prefixed_filename = "\\\\?\\" + path.resolve(filename);
console.log(prefixed_filename);
try {
console.log((await fs.readFile(prefixed_filename)).toString());
} catch (e) { console.error(e); }
try {
console.log((await fs.stat(prefixed_filename)).size);
} catch (e) { console.error(e); }
try {
await fs.unlink(filename);
continue;
} catch (e) { console.error(e); }
try {
const newName = filename.replaceAll(/^[ .]+|[ .]+$/g, "");
await fs.rename(prefixed_filename, newName);
} catch (e) { console.error(e); }
} |
|
i think once the path pr merges it might be worthwhile to use that api internally for all the fs stuff on windows. it probably should replace |
What version of Bun is running?
1.0.26
What platform is your computer?
Window 10
What steps can reproduce the bug?
What is the expected behavior?
The
" spaces.txt "
,".dots.txt."
files have been created, read, then deleted.What do you see instead?
The
" spaces.txt "
,".dots.txt."
files have been created, but not read, or deleted.Additional information
Tailing / heading dots
"."
and spaces" "
are allowed by NTFS, while Windows Explorer does not like them (it works buggy with them).https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
Bun can create (
writeFile
) them, but not read (readFile
,stat
) or delete (unlink
,rename
) them.Rel:
The text was updated successfully, but these errors were encountered: