[Bug] fs.exists, Deno.readTextFile, Deno.writeTextFile Fail to Work on Memory Disk
Version: Deno 2.0.0 OS: Windows 10 x86_64
deno 2.0.0 (stable, release, x86_64-pc-windows-msvc)
v8 12.9.202.13-rusty
typescript 5.6.2
Intro
I use a memory disk created by ImDisk. Its setup is as follows. However, some Deno file system APIs fail to work on it.
Reproduce the Issue
Here are the steps.
Create a test file
cd /d y:\
echo test > a.txt
Create a test typescript file
import { exists } from "https://deno.land/std/fs/mod.ts";
Deno.readTextFile("y:\\a.txt")
.then((x) => console.log(x))
.catch((e) => console.error(e));
Deno.writeTextFile("y:\\test.txt", "test")
.then((x) => console.log(x))
.catch((e) => console.error(e));
exists("y:\\a.txt")
.then((x) => console.log(x))
.catch((e) => console.error(e));
Execute the typescript file
The error message is as follows.
Error: Incorrect function. (os error 1): readfile 'y:\a.txt'
at Object.readTextFile (ext:deno_fs/30_fs.js:777:24)
at file:///C:/test.ts:3:6 {
code: "EISDIR"
}
Error: Incorrect function. (os error 1): writefile 'y:\test.txt'
at writeFile (ext:deno_fs/30_fs.js:835:13)
at Object.writeTextFile (ext:deno_fs/30_fs.js:877:12)
at file:///C:/test.ts:6:6 {
code: "EISDIR"
}
Error: Incorrect function. (os error 1): stat 'y:\a.txt'
at async Object.stat (ext:deno_fs/30_fs.js:407:15)
at async exists (https://deno.land/[email protected]/fs/exists.ts:112:18) {
code: "EISDIR"
}
Summary
The impacted file system APIs are not restricted to the ones in the test. There might be more of them.
Actually, not all file system APIs fail. E.g. Deno.copyFile, Deno.remove work well. I guess because they leverage OS native API.
Here is the test result in Node.js.
Script
const fs = require("fs");
fs.exists("y:\\a.txt", (err, data) => {
if (err) {
console.error(err);
return;
}
console.log(data);
});
fs.readFile("y:\\a.txt", (err, data) => {
if (err) {
console.error(err);
return;
}
console.log(data);
});
fs.writeFile("y:\\test.txt", "test", (err) => {
if (err) {
console.error(err);
return;
}
console.log("done");
});
Result
true
done
<Buffer 74 65 73 74 0a>
I found that it is also causing deno compile hello.ts errored when the hello.ts is under the imdisk drive,
PS R:\> deno compile R:\Temp\hello.ts
Check file:///R:/Temp/hello.ts
Compile file:///R:/Temp/hello.ts to hello.exe
error: Writing deno compile executable to temporary file 'hello.exe.tmp-53bfb427e4a38f96'
Caused by:
函数不正确。 (os error 1)
However when I put the hello.ts into normal disk drive, and keep the working directory not leaving, deno can succesfully build the binary and write it to the working directory;
Version info
PS R:\> deno --version
deno 2.0.6 (stable, release, x86_64-pc-windows-msvc)
v8 12.9.202.13-rusty
typescript 5.6.2