Skip to content

Commit

Permalink
Set new directory mode after copying files (MacOS fix)
Browse files Browse the repository at this point in the history
See issue 599
  • Loading branch information
mbargiel committed Jul 6, 2018
1 parent a5b5159 commit b56d580
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
46 changes: 46 additions & 0 deletions lib/copy/__tests__/copy-readonly-dir.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict'

// relevant: https://github.com/jprichardson/node-fs-extra/issues/599

const fs = require(process.cwd())
const os = require('os')
const fse = require('../../')
const path = require('path')
const assert = require('assert')
const klawSync = require('klaw-sync')

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

let TEST_DIR = ''

const FILES = [
path.join('dir1', 'file1.txt'),
path.join('dir1', 'dir2', 'file2.txt'),
path.join('dir1', 'dir2', 'dir3', 'file3.txt')
]

describe('+ copy() - copy a readonly directory with content', () => {
beforeEach(done => {
TEST_DIR = path.join(os.tmpdir(), 'test', 'fs-extra', 'copy-readonly-dir')
fse.emptyDir(TEST_DIR, done)
})

afterEach(done => {
klawSync(TEST_DIR).forEach(data => fs.chmodSync(data.path, 0o777))
fse.remove(TEST_DIR, done)
})

describe('> when src is readonly directory with content', () => {
it('should copy successfully', done => {
FILES.forEach(file => {
fs.outputFileSync(path.join(TEST_DIR, file), file)
})
klawSync(TEST_DIR).forEach(data => fs.chmodSync(data.path, data.stats.isDirectory() ? 0o555 : 0o444))

fse.copy(path.join(TEST_DIR, 'dir1'), path.join(TEST_DIR, 'target'), err => {
assert.ifError(err)
done()
})
})
})
})
6 changes: 3 additions & 3 deletions lib/copy/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ function mayCopyDir (src, dest, opts, cb) {
}

function mkDirAndCopy (srcStat, src, dest, opts, cb) {
fs.mkdir(dest, srcStat.mode, err => {
fs.mkdir(dest, err => {
if (err) return cb(err)
fs.chmod(dest, srcStat.mode, err => {
copyDir(src, dest, opts, err => {
if (err) return cb(err)
return copyDir(src, dest, opts, cb)
return fs.chmod(dest, srcStat.mode, cb)
})
})
}
Expand Down

0 comments on commit b56d580

Please sign in to comment.