From add00ce563c572d2f855659f6327ee02372f7ec5 Mon Sep 17 00:00:00 2001 From: Stephen Ward Date: Sun, 23 Sep 2018 13:49:00 -0400 Subject: [PATCH] testing out the validateAndMask() function, with console.log's... --- package-lock.json | 28 +++++++++++++++++++++------- src/filesystem/implementation.js | 16 ++++++++++++++-- tests/spec/fs.open.spec.js | 16 ++++++++++++++++ 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7524475..d76a628 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3278,12 +3278,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3298,17 +3300,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -3425,7 +3430,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -3437,6 +3443,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3451,6 +3458,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -3458,12 +3466,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -3482,6 +3492,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -3562,7 +3573,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -3574,6 +3586,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -3695,6 +3708,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", diff --git a/src/filesystem/implementation.js b/src/filesystem/implementation.js index 6f15e2c..35e4abe 100644 --- a/src/filesystem/implementation.js +++ b/src/filesystem/implementation.js @@ -1623,8 +1623,16 @@ function open(fs, context, path, flags, mode, callback) { * callback = makeCallback(callback); * } */ - - callback = arguments[arguments.length - 1]; + if (arguments.length == 5){ + callback = arguments[arguments.length - 1]; + } + else { + //need to test this validateAndMakeMode + console.log("open'd mode: " + mode) + mode = validateAndMaskMode(mode, FULL_READ_WRITE_EXEC_PERMISSIONS, callback); + console.log("mask'd mode: " + mode) + } + if(!pathCheck(path, callback)) return; function check_result(error, fileNode) { @@ -1913,12 +1921,15 @@ function isUint32(value) { // Validator for mode_t (the S_* constants). Valid numbers or octal strings // will be masked with 0o777 to be consistent with the behavior in POSIX APIs. function validateAndMaskMode(value, def, callback) { + console.log("Passed in mode: " + value) if(typeof def === 'function') { callback = def; def = undefined; } if (isUint32(value)) { + let newMode = value & FULL_READ_WRITE_EXEC_PERMISSIONS; + console.log("Masked mode: " + newMode) return value & FULL_READ_WRITE_EXEC_PERMISSIONS; } @@ -1939,6 +1950,7 @@ function validateAndMaskMode(value, def, callback) { return false; } var parsed = parseInt(value, 8); + console.log("Parsed + Masekd mode: " + parsed & FULL_READ_WRITE_EXEC_PERMISSIONS) return parsed & FULL_READ_WRITE_EXEC_PERMISSIONS; } diff --git a/tests/spec/fs.open.spec.js b/tests/spec/fs.open.spec.js index b995755..ce7435d 100644 --- a/tests/spec/fs.open.spec.js +++ b/tests/spec/fs.open.spec.js @@ -106,6 +106,22 @@ describe('fs.open', function() { }); }); + it('should create a new file when flagged for write, and set the mode', function(done) { + var fs = util.fs(); + + fs.open('/myfile', 'w', 644, function(error) { + if(error) throw error; + + fs.stat('/myfile', function(error, result) { + expect(error).not.to.exist; + expect(result).to.exist; + expect(result.type).to.equal('FILE'); + expect(result.mode).to.exist; + expect(result.mode).to.equal(33188) + 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.