diff --git a/src/filesystem/implementation.js b/src/filesystem/implementation.js index 09fe361..2c6cc69 100644 --- a/src/filesystem/implementation.js +++ b/src/filesystem/implementation.js @@ -1629,7 +1629,7 @@ function open(fs, context, path, flags, mode, callback) { */ if (arguments.length == 5){ callback = arguments[arguments.length - 1]; - mode = 0o666; + mode = 0o644; } else { //need to test this validateAndMakeMode @@ -1928,8 +1928,8 @@ function validateAndMaskMode(value, def, callback) { callback = def; def = undefined; } - if (isUint32(value)) { + let newMode = value & FULL_READ_WRITE_EXEC_PERMISSIONS; return value & FULL_READ_WRITE_EXEC_PERMISSIONS; } diff --git a/tests/spec/fs.open.spec.js b/tests/spec/fs.open.spec.js index b995755..474fd23 100644 --- a/tests/spec/fs.open.spec.js +++ b/tests/spec/fs.open.spec.js @@ -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. * When we fix https://github.com/filerjs/filer/issues/314 we'll have to update this.