11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// This tests that the lower bits of mode > 0o777 still works in fs.open(). 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst common = require('../common'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst path = require('path'); 81cb0ef41Sopenharmony_ciconst fs = require('fs'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst mode = common.isWindows ? 0o444 : 0o644; 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst maskToIgnore = 0o10000; 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 151cb0ef41Sopenharmony_citmpdir.refresh(); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_cifunction test(mode, asString) { 181cb0ef41Sopenharmony_ci const suffix = asString ? 'str' : 'num'; 191cb0ef41Sopenharmony_ci const input = asString ? 201cb0ef41Sopenharmony_ci (mode | maskToIgnore).toString(8) : (mode | maskToIgnore); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci { 231cb0ef41Sopenharmony_ci const file = path.join(tmpdir.path, `openSync-${suffix}.txt`); 241cb0ef41Sopenharmony_ci const fd = fs.openSync(file, 'w+', input); 251cb0ef41Sopenharmony_ci assert.strictEqual(fs.fstatSync(fd).mode & 0o777, mode); 261cb0ef41Sopenharmony_ci fs.closeSync(fd); 271cb0ef41Sopenharmony_ci assert.strictEqual(fs.statSync(file).mode & 0o777, mode); 281cb0ef41Sopenharmony_ci } 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci { 311cb0ef41Sopenharmony_ci const file = path.join(tmpdir.path, `open-${suffix}.txt`); 321cb0ef41Sopenharmony_ci fs.open(file, 'w+', input, common.mustSucceed((fd) => { 331cb0ef41Sopenharmony_ci assert.strictEqual(fs.fstatSync(fd).mode & 0o777, mode); 341cb0ef41Sopenharmony_ci fs.closeSync(fd); 351cb0ef41Sopenharmony_ci assert.strictEqual(fs.statSync(file).mode & 0o777, mode); 361cb0ef41Sopenharmony_ci })); 371cb0ef41Sopenharmony_ci } 381cb0ef41Sopenharmony_ci} 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_citest(mode, true); 411cb0ef41Sopenharmony_citest(mode, false); 42