-
Notifications
You must be signed in to change notification settings - Fork 98
No auto delete when fd is closed on Windows #115
Copy link
Copy link
Closed
Urigo/tortilla
#58Labels
Description
On Windows (10), the auto-deletion of temporary files doesn't work if the file descriptor is closed manually.
The reason for this is that the "calculation" of EBADF doesn't produce the correct result on Windows. It's set to -40839 while it should be 94083. The property os.constants.errno.EBADF contains the correct value.
I'm fairly new to NodeJS so I don't feel like I could provide a proper fix (pull request) - especially considering backward compatibility with older node versions. and don't know how this should/could be solved properly.
Here's some code to reproduce the problem:
const fs = require('fs');
const os = require('os');
const _c = process.binding('constants');
const EBADF = _c.EBADF || _c.os.errno.EBADF; // Like the tmp module does it.
const CREATE_FLAGS = (_c.O_CREAT || _c.fs.O_CREAT) | (_c.O_EXCL || _c.fs.O_EXCL) | (_c.O_RDWR || _c.fs.O_RDWR);
const FILE_MODE = 384;
fs.unlinkSync('test.txt');
var fd = fs.openSync('test.txt', CREATE_FLAGS, FILE_MODE);
fs.writeSync(fd, 'test');
fs.closeSync(fd);
try {
fs.closeSync(fd);
}
catch (e) {
console.log('Exception: ' + e);
console.log('ErrNo: ' + e.errno);
console.log('Expected: ' + EBADF);
console.log('From Constants: ' + os.constants.errno.EBADF);
}This produces the following output:
Exception: Error: EBADF: bad file descriptor, close
ErrNo: -4083
Expected: 9
From Constants: 9
Reactions are currently unavailable