Skip to content

Commit

Permalink
Use octal literal notation
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanZim committed Feb 1, 2020
1 parent f1c3151 commit c39d505
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 86 deletions.
4 changes: 2 additions & 2 deletions lib/copy-sync/__tests__/copy-sync-file.test.js
Expand Up @@ -57,7 +57,7 @@ describe('+ copySync() / file', () => {
const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy')
fs.writeFileSync(fileSrc, crypto.randomBytes(SIZE))

fs.chmodSync(fileSrc, parseInt('750', 8))
fs.chmodSync(fileSrc, 0o750)
fs.copySync(fileSrc, fileDest)

const statSrc = fs.statSync(fileSrc)
Expand Down Expand Up @@ -187,7 +187,7 @@ describe('+ copySync() / file', () => {
describe('> when overwrite is true and dest is readonly', () => {
it('should copy the file and not throw an error', () => {
try {
fs.chmodSync(dest, parseInt('444', 8))
fs.chmodSync(dest, 0o444)
fs.copySync(src, dest, { overwrite: true })
destData = fs.readFileSync(dest, 'utf8')
assert.strictEqual(srcData, destData)
Expand Down
24 changes: 10 additions & 14 deletions lib/copy/__tests__/copy-permissions.test.js
Expand Up @@ -8,10 +8,6 @@ const assert = require('assert')

/* global beforeEach, describe, it */

const o777 = parseInt('777', 8)
const o666 = parseInt('666', 8)
const o444 = parseInt('444', 8)

describe('copy', () => {
let TEST_DIR

Expand All @@ -27,8 +23,8 @@ describe('copy', () => {
// var userid = require('userid')

// http://man7.org/linux/man-pages/man2/stat.2.html
const S_IFREG = parseInt('0100000', 8) // regular file
const S_IFDIR = parseInt('0040000', 8) // directory
const S_IFREG = 0o100000 // regular file
const S_IFDIR = 0o40000 // directory

// these are Mac specific I think (at least staff), should find Linux equivalent
let gidWheel
Expand All @@ -54,31 +50,31 @@ describe('copy', () => {

const f1 = path.join(srcDir, 'f1.txt')
fs.writeFileSync(f1, '')
fs.chmodSync(f1, o666)
fs.chmodSync(f1, 0o666)
fs.chownSync(f1, process.getuid(), gidWheel)
const f1stats = fs.lstatSync(f1)
assert.strictEqual(f1stats.mode - S_IFREG, o666)
assert.strictEqual(f1stats.mode - S_IFREG, 0o666)

const d1 = path.join(srcDir, 'somedir')
fs.mkdirSync(d1)
fs.chmodSync(d1, o777)
fs.chmodSync(d1, 0o777)
fs.chownSync(d1, process.getuid(), gidStaff)
const d1stats = fs.lstatSync(d1)
assert.strictEqual(d1stats.mode - S_IFDIR, o777)
assert.strictEqual(d1stats.mode - S_IFDIR, 0o777)

const f2 = path.join(d1, 'f2.bin')
fs.writeFileSync(f2, '')
fs.chmodSync(f2, o777)
fs.chmodSync(f2, 0o777)
fs.chownSync(f2, process.getuid(), gidStaff)
const f2stats = fs.lstatSync(f2)
assert.strictEqual(f2stats.mode - S_IFREG, o777)
assert.strictEqual(f2stats.mode - S_IFREG, 0o777)

const d2 = path.join(srcDir, 'crazydir')
fs.mkdirSync(d2)
fs.chmodSync(d2, o444)
fs.chmodSync(d2, 0o444)
fs.chownSync(d2, process.getuid(), gidWheel)
const d2stats = fs.lstatSync(d2)
assert.strictEqual(d2stats.mode - S_IFDIR, o444)
assert.strictEqual(d2stats.mode - S_IFDIR, 0o444)

const destDir = path.join(permDir, 'dest')
fse.copy(srcDir, destDir, err => {
Expand Down
2 changes: 1 addition & 1 deletion lib/copy/__tests__/ncp/ncp-error-perm.test.js
Expand Up @@ -37,7 +37,7 @@ describe('ncp / error / dest-permission', () => {
fse.outputFileSync(someFile, 'hello')

fse.mkdirsSync(dest)
fs.chmodSync(dest, parseInt('444', 8))
fs.chmodSync(dest, 0o444)

const subdest = path.join(dest, 'another-dir')

Expand Down
13 changes: 4 additions & 9 deletions lib/mkdirs/__tests__/chmod.test.js
Expand Up @@ -8,11 +8,6 @@ const assert = require('assert')

/* global afterEach, beforeEach, describe, it */

const o755 = parseInt('755', 8)
const o744 = parseInt('744', 8)
const o777 = parseInt('777', 8)
const o666 = parseInt('666', 8)

describe('mkdirp / chmod', () => {
let TEST_DIR
let TEST_SUBDIR
Expand All @@ -35,17 +30,17 @@ describe('mkdirp / chmod', () => {
afterEach(done => fse.remove(TEST_DIR, done))

it('chmod-pre', done => {
const mode = o744
const mode = 0o744
fse.mkdirp(TEST_SUBDIR, mode, err => {
assert.ifError(err, 'should not error')
fs.stat(TEST_SUBDIR, (err, stat) => {
assert.ifError(err, 'should exist')
assert.ok(stat && stat.isDirectory(), 'should be directory')

if (os.platform().indexOf('win') === 0) {
assert.strictEqual(stat && stat.mode & o777, o666, 'windows shit')
assert.strictEqual(stat && stat.mode & 0o777, 0o666, 'windows shit')
} else {
assert.strictEqual(stat && stat.mode & o777, mode, 'should be 0744')
assert.strictEqual(stat && stat.mode & 0o777, mode, 'should be 0744')
}

done()
Expand All @@ -54,7 +49,7 @@ describe('mkdirp / chmod', () => {
})

it('chmod', done => {
const mode = o755
const mode = 0o755
fse.mkdirp(TEST_SUBDIR, mode, err => {
assert.ifError(err, 'should not error')
fs.stat(TEST_SUBDIR, (err, stat) => {
Expand Down
4 changes: 1 addition & 3 deletions lib/mkdirs/__tests__/clobber.test.js
Expand Up @@ -8,8 +8,6 @@ const assert = require('assert')

/* global before, describe, it */

const o755 = parseInt('755', 8)

describe('mkdirp / clobber', () => {
let TEST_DIR
let file
Expand Down Expand Up @@ -42,7 +40,7 @@ describe('mkdirp / clobber', () => {
})

it('should clobber', done => {
fse.mkdirp(file, o755, err => {
fse.mkdirp(file, 0o755, err => {
assert.ok(err)
if (os.platform().indexOf('win') === 0) {
assert.strictEqual(err.code, 'EEXIST')
Expand Down
10 changes: 3 additions & 7 deletions lib/mkdirs/__tests__/mkdirp.test.js
Expand Up @@ -8,10 +8,6 @@ const assert = require('assert')

/* global afterEach, beforeEach, describe, it */

const o755 = parseInt('755', 8)
const o777 = parseInt('777', 8)
const o666 = parseInt('666', 8)

describe('mkdirp / mkdirp', () => {
let TEST_DIR

Expand All @@ -29,7 +25,7 @@ describe('mkdirp / mkdirp', () => {

const file = path.join(TEST_DIR, x, y, z)

fse.mkdirp(file, o755, err => {
fse.mkdirp(file, 0o755, err => {
assert.ifError(err)
fse.pathExists(file, (err, ex) => {
assert.ifError(err)
Expand All @@ -38,9 +34,9 @@ describe('mkdirp / mkdirp', () => {
assert.ifError(err)

if (os.platform().indexOf('win') === 0) {
assert.strictEqual(stat.mode & o777, o666)
assert.strictEqual(stat.mode & 0o777, 0o666)
} else {
assert.strictEqual(stat.mode & o777, o755)
assert.strictEqual(stat.mode & 0o777, 0o755)
}

assert.ok(stat.isDirectory(), 'target not a directory')
Expand Down
12 changes: 4 additions & 8 deletions lib/mkdirs/__tests__/perm.test.js
Expand Up @@ -8,10 +8,6 @@ const assert = require('assert')

/* global afterEach, beforeEach, describe, it */

const o755 = parseInt('755', 8)
const o777 = parseInt('777', 8)
const o666 = parseInt('666', 8)

describe('mkdirp / perm', () => {
let TEST_DIR

Expand All @@ -25,7 +21,7 @@ describe('mkdirp / perm', () => {
it('async perm', done => {
const file = path.join(TEST_DIR, (Math.random() * (1 << 30)).toString(16))

fse.mkdirp(file, o755, err => {
fse.mkdirp(file, 0o755, err => {
assert.ifError(err)
fse.pathExists(file, (err, ex) => {
assert.ifError(err)
Expand All @@ -34,9 +30,9 @@ describe('mkdirp / perm', () => {
assert.ifError(err)

if (os.platform().indexOf('win') === 0) {
assert.strictEqual(stat.mode & o777, o666)
assert.strictEqual(stat.mode & 0o777, 0o666)
} else {
assert.strictEqual(stat.mode & o777, o755)
assert.strictEqual(stat.mode & 0o777, 0o755)
}

assert.ok(stat.isDirectory(), 'target not a directory')
Expand All @@ -47,7 +43,7 @@ describe('mkdirp / perm', () => {
})

it('async root perm', done => {
fse.mkdirp(path.join(os.tmpdir(), 'tmp'), o755, err => {
fse.mkdirp(path.join(os.tmpdir(), 'tmp'), 0o755, err => {
assert.ifError(err)
done()
})
Expand Down
12 changes: 4 additions & 8 deletions lib/mkdirs/__tests__/perm_sync.test.js
Expand Up @@ -8,10 +8,6 @@ const assert = require('assert')

/* global afterEach, beforeEach, describe, it */

const o755 = parseInt('755', 8)
const o777 = parseInt('777', 8)
const o666 = parseInt('666', 8)

describe('mkdirp / perm_sync', () => {
let TEST_DIR

Expand All @@ -25,17 +21,17 @@ describe('mkdirp / perm_sync', () => {
it('sync perm', done => {
const file = path.join(TEST_DIR, (Math.random() * (1 << 30)).toString(16) + '.json')

fse.mkdirpSync(file, o755)
fse.mkdirpSync(file, 0o755)
fse.pathExists(file, (err, ex) => {
assert.ifError(err)
assert.ok(ex, 'file created')
fs.stat(file, (err, stat) => {
assert.ifError(err)

if (os.platform().indexOf('win') === 0) {
assert.strictEqual(stat.mode & o777, o666)
assert.strictEqual(stat.mode & 0o777, 0o666)
} else {
assert.strictEqual(stat.mode & o777, o755)
assert.strictEqual(stat.mode & 0o777, 0o755)
}

assert.ok(stat.isDirectory(), 'target not a directory')
Expand All @@ -46,7 +42,7 @@ describe('mkdirp / perm_sync', () => {

it('sync root perm', done => {
const file = TEST_DIR
fse.mkdirpSync(file, o755)
fse.mkdirpSync(file, 0o755)
fse.pathExists(file, (err, ex) => {
assert.ifError(err)
assert.ok(ex, 'file created')
Expand Down
10 changes: 3 additions & 7 deletions lib/mkdirs/__tests__/race.test.js
Expand Up @@ -8,10 +8,6 @@ const assert = require('assert')

/* global afterEach, beforeEach, describe, it */

const o755 = parseInt('755', 8)
const o777 = parseInt('777', 8)
const o666 = parseInt('666', 8)

describe('mkdirp / race', () => {
let TEST_DIR
let file
Expand Down Expand Up @@ -42,7 +38,7 @@ describe('mkdirp / race', () => {
mk(file, () => --res === 0 ? done() : undefined)

function mk (file, callback) {
fse.mkdirp(file, o755, err => {
fse.mkdirp(file, 0o755, err => {
assert.ifError(err)
fse.pathExists(file, (err, ex) => {
assert.ifError(err)
Expand All @@ -51,9 +47,9 @@ describe('mkdirp / race', () => {
assert.ifError(err)

if (os.platform().indexOf('win') === 0) {
assert.strictEqual(stat.mode & o777, o666)
assert.strictEqual(stat.mode & 0o777, 0o666)
} else {
assert.strictEqual(stat.mode & o777, o755)
assert.strictEqual(stat.mode & 0o777, 0o755)
}

assert.ok(stat.isDirectory(), 'target not a directory')
Expand Down
10 changes: 3 additions & 7 deletions lib/mkdirs/__tests__/rel.test.js
Expand Up @@ -10,10 +10,6 @@ const assert = require('assert')

/* global afterEach, beforeEach, describe, it */

const o755 = parseInt('755', 8)
const o777 = parseInt('777', 8)
const o666 = parseInt('666', 8)

describe('mkdirp / relative', () => {
let TEST_DIR
let file
Expand All @@ -39,7 +35,7 @@ describe('mkdirp / relative', () => {
it('should make the directory with relative path', done => {
process.chdir(TEST_DIR)

fse.mkdirp(file, o755, err => {
fse.mkdirp(file, 0o755, err => {
assert.ifError(err)
fse.pathExists(file, (err, ex) => {
assert.ifError(err)
Expand All @@ -50,9 +46,9 @@ describe('mkdirp / relative', () => {
process.chdir(CWD)

if (os.platform().indexOf('win') === 0) {
assert.strictEqual(stat.mode & o777, o666)
assert.strictEqual(stat.mode & 0o777, 0o666)
} else {
assert.strictEqual(stat.mode & o777, o755)
assert.strictEqual(stat.mode & 0o777, 0o755)
}

assert.ok(stat.isDirectory(), 'target not a directory')
Expand Down
4 changes: 1 addition & 3 deletions lib/mkdirs/__tests__/root.test.js
Expand Up @@ -7,8 +7,6 @@ const assert = require('assert')

/* global describe, it */

const o755 = parseInt('755', 8)

describe('mkdirp / root', () => {
// '/' on unix, 'c:/' on windows.
const dir = path.normalize(path.resolve(path.sep)).toLowerCase()
Expand All @@ -17,7 +15,7 @@ describe('mkdirp / root', () => {
if (process.platform === 'win32' && (dir.indexOf('c:\\') === -1) && (dir.indexOf('d:\\') === -1)) return

it('should', done => {
fse.mkdirp(dir, o755, err => {
fse.mkdirp(dir, 0o755, err => {
if (err) throw err
fs.stat(dir, (er, stat) => {
if (er) throw er
Expand Down
10 changes: 3 additions & 7 deletions lib/mkdirs/__tests__/sync.test.js
Expand Up @@ -8,10 +8,6 @@ const assert = require('assert')

/* global afterEach, beforeEach, describe, it */

const o755 = parseInt('755', 8)
const o777 = parseInt('777', 8)
const o666 = parseInt('666', 8)

describe('mkdirp / sync', () => {
let TEST_DIR
let file
Expand All @@ -35,7 +31,7 @@ describe('mkdirp / sync', () => {

it('should', done => {
try {
fse.mkdirpSync(file, o755)
fse.mkdirpSync(file, 0o755)
} catch (err) {
assert.fail(err)
}
Expand All @@ -47,9 +43,9 @@ describe('mkdirp / sync', () => {
assert.ifError(err)
// http://stackoverflow.com/questions/592448/c-how-to-set-file-permissions-cross-platform
if (os.platform().indexOf('win') === 0) {
assert.strictEqual(stat.mode & o777, o666)
assert.strictEqual(stat.mode & 0o777, 0o666)
} else {
assert.strictEqual(stat.mode & o777, o755)
assert.strictEqual(stat.mode & 0o777, 0o755)
}

assert.ok(stat.isDirectory(), 'target not a directory')
Expand Down

0 comments on commit c39d505

Please sign in to comment.