-
Notifications
You must be signed in to change notification settings - Fork 774
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set new directory mode after copying files in copy-sync (MacOS fix)
See issue 599
- Loading branch information
Maxime Bargiel
committed
Jul 9, 2018
1 parent
b56d580
commit 648ac52
Showing
2 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'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('+ copySync() - 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', () => { | ||
FILES.forEach(file => { | ||
fs.outputFileSync(path.join(TEST_DIR, file), file) | ||
}) | ||
const sourceDir = path.join(TEST_DIR, 'dir1') | ||
const sourceHierarchy = klawSync(sourceDir) | ||
sourceHierarchy.forEach(source => fs.chmodSync(source.path, source.stats.isDirectory() ? 0o555 : 0o444)) | ||
|
||
const targetDir = path.join(TEST_DIR, 'target') | ||
fse.copySync(sourceDir, targetDir) | ||
|
||
// Make sure copy was made and mode was preserved | ||
assert(fs.existsSync(targetDir)) | ||
const targetHierarchy = klawSync(targetDir) | ||
assert(targetHierarchy.length === sourceHierarchy.length) | ||
targetHierarchy.forEach(target => assert(target.stats.mode === target.stats.isDirectory() ? 0o555 : 0o444)) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters