Skip to content

Instantly share code, notes, and snippets.

@stefanpenner
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanpenner/2cc619b8740fe2463c2a to your computer and use it in GitHub Desktop.
Save stefanpenner/2cc619b8740fe2463c2a to your computer and use it in GitHub Desktop.
// 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
@stefanpenner
Copy link
Author

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