Refactor duplicate flag checks
This commit is contained in:
parent
034dc8c166
commit
cf7d12a6b3
|
@ -8951,6 +8951,14 @@ define('src/fs',['require','lodash','when','encoding-indexes','encoding','src/pa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function validate_flags(flags) {
|
||||||
|
if(!_(O_FLAGS).has(flags)) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return O_FLAGS[flags];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FileSystem
|
* FileSystem
|
||||||
*/
|
*/
|
||||||
|
@ -9053,10 +9061,9 @@ define('src/fs',['require','lodash','when','encoding-indexes','encoding','src/pa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!_(O_FLAGS).has(flags)) {
|
flags = validate_flags(flags);
|
||||||
|
if(!flags) {
|
||||||
deferred.reject(new EInvalid('flags is not valid'));
|
deferred.reject(new EInvalid('flags is not valid'));
|
||||||
} else {
|
|
||||||
flags = O_FLAGS[flags];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open_file(this, files, path, flags, check_result);
|
open_file(this, files, path, flags, check_result);
|
||||||
|
@ -9357,11 +9364,9 @@ define('src/fs',['require','lodash','when','encoding-indexes','encoding','src/pa
|
||||||
options = { encoding: options, flag: 'r' };
|
options = { encoding: options, flag: 'r' };
|
||||||
}
|
}
|
||||||
|
|
||||||
var flags = options.flag || 'r';
|
var flags = validate_flags(options.flag || 'r');
|
||||||
if(!_(O_FLAGS).has(flags)) {
|
if(!flags) {
|
||||||
deferred.reject(new EInvalid('flags is not valid'));
|
deferred.reject(new EInvalid('flags is not valid'));
|
||||||
} else {
|
|
||||||
flags = O_FLAGS[flags];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open_file(this, files, path, flags, function(err, fileNode) {
|
open_file(this, files, path, flags, function(err, fileNode) {
|
||||||
|
@ -9477,11 +9482,9 @@ define('src/fs',['require','lodash','when','encoding-indexes','encoding','src/pa
|
||||||
options = { encoding: options, flag: 'w' };
|
options = { encoding: options, flag: 'w' };
|
||||||
}
|
}
|
||||||
|
|
||||||
var flags = options.flag || 'w';
|
var flags = validate_flags(options.flag || 'w');
|
||||||
if(!_(O_FLAGS).has(flags)) {
|
if(!flags) {
|
||||||
deferred.reject(new EInvalid('flags is not valid'));
|
deferred.reject(new EInvalid('flags is not valid'));
|
||||||
} else {
|
|
||||||
flags = O_FLAGS[flags];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeof data === "string" && options.encoding === 'utf8') {
|
if(typeof data === "string" && options.encoding === 'utf8') {
|
||||||
|
|
File diff suppressed because one or more lines are too long
25
src/fs.js
25
src/fs.js
|
@ -782,6 +782,14 @@ define(function(require) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function validate_flags(flags) {
|
||||||
|
if(!_(O_FLAGS).has(flags)) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return O_FLAGS[flags];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FileSystem
|
* FileSystem
|
||||||
*/
|
*/
|
||||||
|
@ -884,10 +892,9 @@ define(function(require) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!_(O_FLAGS).has(flags)) {
|
flags = validate_flags(flags);
|
||||||
|
if(!flags) {
|
||||||
deferred.reject(new EInvalid('flags is not valid'));
|
deferred.reject(new EInvalid('flags is not valid'));
|
||||||
} else {
|
|
||||||
flags = O_FLAGS[flags];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open_file(this, files, path, flags, check_result);
|
open_file(this, files, path, flags, check_result);
|
||||||
|
@ -1188,11 +1195,9 @@ define(function(require) {
|
||||||
options = { encoding: options, flag: 'r' };
|
options = { encoding: options, flag: 'r' };
|
||||||
}
|
}
|
||||||
|
|
||||||
var flags = options.flag || 'r';
|
var flags = validate_flags(options.flag || 'r');
|
||||||
if(!_(O_FLAGS).has(flags)) {
|
if(!flags) {
|
||||||
deferred.reject(new EInvalid('flags is not valid'));
|
deferred.reject(new EInvalid('flags is not valid'));
|
||||||
} else {
|
|
||||||
flags = O_FLAGS[flags];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open_file(this, files, path, flags, function(err, fileNode) {
|
open_file(this, files, path, flags, function(err, fileNode) {
|
||||||
|
@ -1308,11 +1313,9 @@ define(function(require) {
|
||||||
options = { encoding: options, flag: 'w' };
|
options = { encoding: options, flag: 'w' };
|
||||||
}
|
}
|
||||||
|
|
||||||
var flags = options.flag || 'w';
|
var flags = validate_flags(options.flag || 'w');
|
||||||
if(!_(O_FLAGS).has(flags)) {
|
if(!flags) {
|
||||||
deferred.reject(new EInvalid('flags is not valid'));
|
deferred.reject(new EInvalid('flags is not valid'));
|
||||||
} else {
|
|
||||||
flags = O_FLAGS[flags];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeof data === "string" && options.encoding === 'utf8') {
|
if(typeof data === "string" && options.encoding === 'utf8') {
|
||||||
|
|
Loading…
Reference in New Issue