• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// This tests that the lower bits of mode > 0o777 still works in fs.open().
4
5const common = require('../common');
6const assert = require('assert');
7const path = require('path');
8const fs = require('fs');
9
10const mode = common.isWindows ? 0o444 : 0o644;
11
12const maskToIgnore = 0o10000;
13
14const tmpdir = require('../common/tmpdir');
15tmpdir.refresh();
16
17function test(mode, asString) {
18  const suffix = asString ? 'str' : 'num';
19  const input = asString ?
20    (mode | maskToIgnore).toString(8) : (mode | maskToIgnore);
21
22  {
23    const file = path.join(tmpdir.path, `openSync-${suffix}.txt`);
24    const fd = fs.openSync(file, 'w+', input);
25    assert.strictEqual(fs.fstatSync(fd).mode & 0o777, mode);
26    fs.closeSync(fd);
27    assert.strictEqual(fs.statSync(file).mode & 0o777, mode);
28  }
29
30  {
31    const file = path.join(tmpdir.path, `open-${suffix}.txt`);
32    fs.open(file, 'w+', input, common.mustSucceed((fd) => {
33      assert.strictEqual(fs.fstatSync(fd).mode & 0o777, mode);
34      fs.closeSync(fd);
35      assert.strictEqual(fs.statSync(file).mode & 0o777, mode);
36    }));
37  }
38}
39
40test(mode, true);
41test(mode, false);
42