fs: support as and as+ flags in stringToFlags()

PR-URL: https://github.com/nodejs/node/pull/18801
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Matheus Marchini <matheus@sthima.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Sarat Addepalli 2018-02-15 19:43:26 +05:30 committed by Ruben Bridgewater
parent 7107c9201d
commit b1e52fe2ea
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
3 changed files with 20 additions and 0 deletions

View File

@ -2019,11 +2019,17 @@ The file is created if it does not exist.
* `'ax'` - Like `'a'` but fails if `path` exists.
* `'as'` - Open file for appending in synchronous mode.
The file is created if it does not exist.
* `'a+'` - Open file for reading and appending.
The file is created if it does not exist.
* `'ax+'` - Like `'a+'` but fails if `path` exists.
* `'as+'` - Open file for reading and appending in synchronous mode.
The file is created if it does not exist.
`mode` sets the file mode (permission and sticky bits), but only if the file was
created. It defaults to `0o666` (readable and writable).
@ -3920,11 +3926,17 @@ The file is created if it does not exist.
* `'ax'` - Like `'a'` but fails if `path` exists.
* `'as'` - Open file for appending in synchronous mode.
The file is created if it does not exist.
* `'a+'` - Open file for reading and appending.
The file is created if it does not exist.
* `'ax+'` - Like `'a+'` but fails if `path` exists.
* `'as+'` - Open file for reading and appending in synchronous mode.
The file is created if it does not exist.
`mode` sets the file mode (permission and sticky bits), but only if the file was
created. It defaults to `0o666` (readable and writable).

View File

@ -223,10 +223,14 @@ function stringToFlags(flags) {
case 'a' : return O_APPEND | O_CREAT | O_WRONLY;
case 'ax' : // Fall through.
case 'xa' : return O_APPEND | O_CREAT | O_WRONLY | O_EXCL;
case 'as' : // Fall through.
case 'sa' : return O_APPEND | O_CREAT | O_WRONLY | O_SYNC;
case 'a+' : return O_APPEND | O_CREAT | O_RDWR;
case 'ax+': // Fall through.
case 'xa+': return O_APPEND | O_CREAT | O_RDWR | O_EXCL;
case 'as+': // Fall through.
case 'sa+': return O_APPEND | O_CREAT | O_RDWR | O_SYNC;
}
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'flags', flags);

View File

@ -56,8 +56,12 @@ assert.strictEqual(stringToFlags('wx+'), O_TRUNC | O_CREAT | O_RDWR | O_EXCL);
assert.strictEqual(stringToFlags('xw+'), O_TRUNC | O_CREAT | O_RDWR | O_EXCL);
assert.strictEqual(stringToFlags('ax'), O_APPEND | O_CREAT | O_WRONLY | O_EXCL);
assert.strictEqual(stringToFlags('xa'), O_APPEND | O_CREAT | O_WRONLY | O_EXCL);
assert.strictEqual(stringToFlags('as'), O_APPEND | O_CREAT | O_WRONLY | O_SYNC);
assert.strictEqual(stringToFlags('sa'), O_APPEND | O_CREAT | O_WRONLY | O_SYNC);
assert.strictEqual(stringToFlags('ax+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL);
assert.strictEqual(stringToFlags('xa+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL);
assert.strictEqual(stringToFlags('as+'), O_APPEND | O_CREAT | O_RDWR | O_SYNC);
assert.strictEqual(stringToFlags('sa+'), O_APPEND | O_CREAT | O_RDWR | O_SYNC);
('+ +a +r +w rw wa war raw r++ a++ w++ x +x x+ rx rx+ wxx wax xwx xxx')
.split(' ')