added a test: open a new file for writing, and set a mode for that file

This commit is contained in:
Stephen Ward 2018-09-24 23:28:56 -04:00
parent f3a7170133
commit 30752c9109
2 changed files with 20 additions and 2 deletions

View File

@ -1629,7 +1629,7 @@ function open(fs, context, path, flags, mode, callback) {
*/ */
if (arguments.length == 5){ if (arguments.length == 5){
callback = arguments[arguments.length - 1]; callback = arguments[arguments.length - 1];
mode = 0o666; mode = 0o644;
} }
else { else {
//need to test this validateAndMakeMode //need to test this validateAndMakeMode
@ -1928,8 +1928,8 @@ function validateAndMaskMode(value, def, callback) {
callback = def; callback = def;
def = undefined; def = undefined;
} }
if (isUint32(value)) { if (isUint32(value)) {
let newMode = value & FULL_READ_WRITE_EXEC_PERMISSIONS;
return value & FULL_READ_WRITE_EXEC_PERMISSIONS; return value & FULL_READ_WRITE_EXEC_PERMISSIONS;
} }

View File

@ -106,6 +106,24 @@ describe('fs.open', function() {
}); });
}); });
it('should create a new file, when flagged for write, and set the mode to the passed value', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w', 0o777, function(error) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result.mode).to.exist;
expect(result.mode & 0o777).to.equal(0o777);
done();
});
});
});
/** /**
* This test is currently correct per our code, but incorrect according to the spec. * This test is currently correct per our code, but incorrect according to the spec.
* When we fix https://github.com/filerjs/filer/issues/314 we'll have to update this. * When we fix https://github.com/filerjs/filer/issues/314 we'll have to update this.