Skip to content

Commit

Permalink
lib/copy/ncp: preserve mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jprichardson committed Jul 9, 2015
1 parent 330ecb5 commit 082aa7f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.22.0 / 2015-xx-yy
-------------------
- preserve mode in `copy()`

0.21.0 / 2015-07-04
-------------------
- add option to preserve timestamps in `copy()` and `copySync()`. See: https://github.com/jprichardson/node-fs-extra/pull/141
Expand Down
29 changes: 19 additions & 10 deletions lib/copy/ncp.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ function ncp (source, dest, options, callback) {
name: source,
mode: stats.mode,
mtime: stats.mtime, // modified time
atime: stats.atime // access time
atime: stats.atime, // access time
stats: stats // temporary
}

if (stats.isDirectory()) {
Expand Down Expand Up @@ -110,14 +111,17 @@ function ncp (source, dest, options, callback) {
}

writeStream.once('finish', function () {
if (preserveTimestamps) {
utimes.utimesMillis(target, file.atime, file.mtime, function (err) {
if (err) return onError(err)
return doneOne()
})
} else {
doneOne()
}
fs.chmod(target, file.mode, function (err) {
if (err) return onError(err)
if (preserveTimestamps) {
utimes.utimesMillis(target, file.atime, file.mtime, function (err) {
if (err) return onError(err)
return doneOne()
})
} else {
doneOne()
}
})
})
}

Expand All @@ -141,7 +145,12 @@ function ncp (source, dest, options, callback) {
function mkDir (dir, target) {
fs.mkdir(target, dir.mode, function (err) {
if (err) return onError(err)
copyDir(dir.name)
// despite setting mode in fs.mkdir, doesn't seem to work
// so we set it here.
fs.chmod(target, dir.mode, function (err) {
if (err) return onError(err)
copyDir(dir.name)
})
})
}

Expand Down

0 comments on commit 082aa7f

Please sign in to comment.