-
-
Save stefanpenner/2cc619b8740fe2463c2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// thanks @krisselden for explaining the difference between win32 & unix FS's | |
// that manifest in this scenario | |
var fs = require('fs'); | |
var file = 'output.txt'; | |
fs.writeFileSync(file, 'first file'); | |
var bufferA = new Buffer(256); | |
var bufferB = new Buffer(256); | |
var a = fs.openSync(file, 'r'); | |
fs.unlinkSync(file); | |
fs.writeFileSync(file, 'second file'); | |
var b = fs.openSync(file, 'r'); | |
// thanks @krisselden for fixing my output | |
aBytesRead = fs.readSync(a, bufferA, 0, 20, 'utf-8'); | |
bBytesRead = fs.readSync(b, bufferB, 0, 20, 'utf-8'); | |
console.log('a', bufferA.toString('utf-8', 0, aBytesRead)); | |
console.log('b', bufferB.toString('utf-8', 0, bBytesRead)); | |
// On posix we will get: | |
// first file | |
// second file | |
// On win32 we should explode while doing the second writeFileSync loc:15 | |
// as unlinking allows shared delete (via libuv) but not writing to a file | |
// named the same as one that is unlinked, if the unlinked file still has open | |
// file descriptors |
although https://github.com/joyent/libuv/blob/master/src/win/fs.c#L426-L432 claims to match unix semantics, it does so in many scenarios, but not the one demonstrated above.
I do not believe it to be possible to match this scenario, but maybe someone with more win32 chops can correct me.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/joyent/libuv/blob/master/src/win/fs.c#L426-L432