2017-01-03 22:16:48 +01:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2016-06-05 18:44:41 +02:00
|
|
|
// Flags: --expose_internals
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2017-02-12 02:25:33 +01:00
|
|
|
const common = require('../common');
|
2017-12-21 23:46:46 +01:00
|
|
|
|
2017-09-15 23:08:11 +02:00
|
|
|
const fixtures = require('../common/fixtures');
|
2012-01-31 00:54:40 +01:00
|
|
|
|
2017-12-21 23:46:46 +01:00
|
|
|
const assert = require('assert');
|
2016-12-31 00:38:06 +01:00
|
|
|
const fs = require('fs');
|
2017-12-21 23:46:46 +01:00
|
|
|
const path = require('path');
|
2012-01-31 00:54:40 +01:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const O_APPEND = fs.constants.O_APPEND || 0;
|
|
|
|
const O_CREAT = fs.constants.O_CREAT || 0;
|
|
|
|
const O_EXCL = fs.constants.O_EXCL || 0;
|
|
|
|
const O_RDONLY = fs.constants.O_RDONLY || 0;
|
|
|
|
const O_RDWR = fs.constants.O_RDWR || 0;
|
2017-01-13 01:34:24 +01:00
|
|
|
const O_SYNC = fs.constants.O_SYNC || 0;
|
2017-09-15 23:08:11 +02:00
|
|
|
const O_DSYNC = fs.constants.O_DSYNC || 0;
|
2017-01-08 14:19:00 +01:00
|
|
|
const O_TRUNC = fs.constants.O_TRUNC || 0;
|
|
|
|
const O_WRONLY = fs.constants.O_WRONLY || 0;
|
2012-01-31 00:54:40 +01:00
|
|
|
|
2016-06-05 18:44:41 +02:00
|
|
|
const { stringToFlags } = require('internal/fs');
|
|
|
|
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(stringToFlags('r'), O_RDONLY);
|
|
|
|
assert.strictEqual(stringToFlags('r+'), O_RDWR);
|
2017-01-13 01:34:24 +01:00
|
|
|
assert.strictEqual(stringToFlags('rs+'), O_RDWR | O_SYNC);
|
|
|
|
assert.strictEqual(stringToFlags('sr+'), O_RDWR | O_SYNC);
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(stringToFlags('w'), O_TRUNC | O_CREAT | O_WRONLY);
|
|
|
|
assert.strictEqual(stringToFlags('w+'), O_TRUNC | O_CREAT | O_RDWR);
|
|
|
|
assert.strictEqual(stringToFlags('a'), O_APPEND | O_CREAT | O_WRONLY);
|
|
|
|
assert.strictEqual(stringToFlags('a+'), O_APPEND | O_CREAT | O_RDWR);
|
|
|
|
|
|
|
|
assert.strictEqual(stringToFlags('wx'), O_TRUNC | O_CREAT | O_WRONLY | O_EXCL);
|
|
|
|
assert.strictEqual(stringToFlags('xw'), O_TRUNC | O_CREAT | O_WRONLY | O_EXCL);
|
|
|
|
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);
|
2018-02-15 15:13:26 +01:00
|
|
|
assert.strictEqual(stringToFlags('as'), O_APPEND | O_CREAT | O_WRONLY | O_SYNC);
|
|
|
|
assert.strictEqual(stringToFlags('sa'), O_APPEND | O_CREAT | O_WRONLY | O_SYNC);
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(stringToFlags('ax+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL);
|
|
|
|
assert.strictEqual(stringToFlags('xa+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL);
|
2018-02-15 15:13:26 +01:00
|
|
|
assert.strictEqual(stringToFlags('as+'), O_APPEND | O_CREAT | O_RDWR | O_SYNC);
|
|
|
|
assert.strictEqual(stringToFlags('sa+'), O_APPEND | O_CREAT | O_RDWR | O_SYNC);
|
2012-01-31 01:36:57 +01:00
|
|
|
|
2016-01-13 21:42:45 +01:00
|
|
|
('+ +a +r +w rw wa war raw r++ a++ w++ x +x x+ rx rx+ wxx wax xwx xxx')
|
|
|
|
.split(' ')
|
|
|
|
.forEach(function(flags) {
|
2017-06-20 23:20:10 +02:00
|
|
|
common.expectsError(
|
2017-01-20 03:01:01 +01:00
|
|
|
() => stringToFlags(flags),
|
2017-06-20 23:20:10 +02:00
|
|
|
{ code: 'ERR_INVALID_OPT_VALUE', type: TypeError }
|
2017-01-20 03:01:01 +01:00
|
|
|
);
|
2016-01-13 21:42:45 +01:00
|
|
|
});
|
2016-03-07 21:32:54 +01:00
|
|
|
|
2017-06-20 23:20:10 +02:00
|
|
|
common.expectsError(
|
2016-06-05 18:44:41 +02:00
|
|
|
() => stringToFlags({}),
|
2017-06-20 23:20:10 +02:00
|
|
|
{ code: 'ERR_INVALID_OPT_VALUE', type: TypeError }
|
2016-03-07 21:32:54 +01:00
|
|
|
);
|
|
|
|
|
2017-06-20 23:20:10 +02:00
|
|
|
common.expectsError(
|
2016-06-05 18:44:41 +02:00
|
|
|
() => stringToFlags(true),
|
2017-06-20 23:20:10 +02:00
|
|
|
{ code: 'ERR_INVALID_OPT_VALUE', type: TypeError }
|
2016-03-07 21:32:54 +01:00
|
|
|
);
|
|
|
|
|
2017-06-20 23:20:10 +02:00
|
|
|
common.expectsError(
|
2016-06-05 18:44:41 +02:00
|
|
|
() => stringToFlags(null),
|
2017-06-20 23:20:10 +02:00
|
|
|
{ code: 'ERR_INVALID_OPT_VALUE', type: TypeError }
|
2016-03-07 21:32:54 +01:00
|
|
|
);
|
2017-09-15 23:08:11 +02:00
|
|
|
|
2017-12-21 23:46:46 +01:00
|
|
|
if (common.isLinux || common.isOSX) {
|
2017-12-25 07:38:11 +01:00
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
|
|
|
const file = path.join(tmpdir.path, 'a.js');
|
2017-12-21 23:46:46 +01:00
|
|
|
fs.copyFileSync(fixtures.path('a.js'), file);
|
2017-09-22 03:10:04 +02:00
|
|
|
fs.open(file, O_DSYNC, common.mustCall(assert.ifError));
|
2017-09-15 23:08:11 +02:00
|
|
|
}
|