From a2738d390694ae8dc32a8c27e76db08c9963e570 Mon Sep 17 00:00:00 2001 From: Ryan Zimmerman <17342435+RyanZim@users.noreply.github.com> Date: Fri, 24 Apr 2020 07:32:54 -0400 Subject: [PATCH] Don't use deprecated process.umask() (#791) * Don't use deprecated process.umask() Refs https://github.com/sindresorhus/make-dir/issues/27 * Remove unneeded umask tests No need to test Node.js core's behavior (which is all these tests do) --- lib/mkdirs/__tests__/umask.test.js | 80 ------------------------------ lib/mkdirs/make-dir.js | 3 +- 2 files changed, 1 insertion(+), 82 deletions(-) delete mode 100644 lib/mkdirs/__tests__/umask.test.js diff --git a/lib/mkdirs/__tests__/umask.test.js b/lib/mkdirs/__tests__/umask.test.js deleted file mode 100644 index e911dbc5..00000000 --- a/lib/mkdirs/__tests__/umask.test.js +++ /dev/null @@ -1,80 +0,0 @@ -'use strict' - -const assert = require('assert') -const fs = require('fs') -const path = require('path') -const os = require('os') -const fse = require('../../') - -/* global afterEach, beforeEach, describe, it */ - -describe('mkdirp', () => { - let TEST_DIR - let _rndDir - - // should investigate this test and file more - if (os.platform().indexOf('win') === 0) return - - beforeEach(done => { - TEST_DIR = path.join(os.tmpdir(), 'mkdirp') - fse.emptyDir(TEST_DIR, () => { - // for actual tests - const x = Math.floor(Math.random() * Math.pow(16, 6)).toString(16) - const y = Math.floor(Math.random() * Math.pow(16, 6)).toString(16) - const z = Math.floor(Math.random() * Math.pow(16, 6)).toString(16) - - _rndDir = path.join(TEST_DIR, [x, y, z].join(path.sep)) - - // just to be safe, although unnecessary - assert(!fs.existsSync(_rndDir)) - done() - }) - }) - - afterEach(done => fse.remove(TEST_DIR, done)) - - describe('umask', () => { - describe('async', () => { - it('should have proper umask', done => { - process.umask(0) - - fse.mkdirp(_rndDir, err => { - assert.ifError(err) - fse.pathExists(_rndDir, (err, ex) => { - assert.ifError(err) - assert.ok(ex, 'file created') - fs.stat(_rndDir, (err, stat) => { - assert.ifError(err) - assert.strictEqual(stat.mode & 0o777, 0o777 & (~process.umask())) - assert.ok(stat.isDirectory(), 'target not a directory') - done() - }) - }) - }) - }) - }) - - describe('sync', () => { - it('should have proper umask', done => { - process.umask(0) - - try { - fse.mkdirpSync(_rndDir) - } catch (err) { - return done(err) - } - - fse.pathExists(_rndDir, (err, ex) => { - assert.ifError(err) - assert.ok(ex, 'file created') - fs.stat(_rndDir, (err, stat) => { - assert.ifError(err) - assert.strictEqual(stat.mode & 0o777, (0o777 & (~process.umask()))) - assert.ok(stat.isDirectory(), 'target not a directory') - done() - }) - }) - }) - }) - }) -}) diff --git a/lib/mkdirs/make-dir.js b/lib/mkdirs/make-dir.js index f17ecffb..3e7e8360 100644 --- a/lib/mkdirs/make-dir.js +++ b/lib/mkdirs/make-dir.js @@ -25,8 +25,7 @@ const checkPath = pth => { } const processOptions = options => { - // Must be defined here so we get fresh process.umask() - const defaults = { mode: 0o777 & (~process.umask()) } + const defaults = { mode: 0o777 } if (typeof options === 'number') options = { mode: options } return { ...defaults, ...options } }