[Pkg-javascript-commits] [node-ncp] 02/05: Imported Upstream version 2.0.0
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sat May 16 23:08:08 UTC 2015
This is an automated email from the git hooks/post-receive script.
andrewrk-guest pushed a commit to branch master
in repository node-ncp.
commit 0fa00fb13773c656bd3c3b9ae53ee118706399b6
Author: Andrew Kelley <superjoe30 at gmail.com>
Date: Sat May 16 23:03:45 2015 +0000
Imported Upstream version 2.0.0
---
lib/ncp.js | 38 +++++++++++++++++++++++++-------
package.json | 56 +++++++++++++++++++++++------------------------
test/modified-files/out/a | 1 +
test/modified-files/src/a | 1 +
test/ncp.js | 30 ++++++++++++++++++++++++-
5 files changed, 89 insertions(+), 37 deletions(-)
diff --git a/lib/ncp.js b/lib/ncp.js
index fb7930c..96eed47 100644
--- a/lib/ncp.js
+++ b/lib/ncp.js
@@ -1,8 +1,6 @@
var fs = require('fs'),
path = require('path');
-const modern = /^v0\.1\d\.\d+$/.test(process.version);
-
module.exports = ncp;
ncp.ncp = ncp;
@@ -21,10 +19,9 @@ function ncp (source, dest, options, callback) {
rename = options.rename,
transform = options.transform,
clobber = options.clobber !== false,
+ modified = options.modified,
dereference = options.dereference,
errs = null,
- eventName = modern ? 'finish' : 'close',
- defer = modern ? setImmediate : process.nextTick,
started = 0,
finished = 0,
running = 0,
@@ -54,7 +51,7 @@ function ncp (source, dest, options, callback) {
function getStats(source) {
var stat = dereference ? fs.stat : fs.lstat;
if (running >= limit) {
- return defer(function () {
+ return setImmediate(function () {
getStats(source);
});
}
@@ -68,6 +65,8 @@ function ncp (source, dest, options, callback) {
// We need to get the mode from the stats object and preserve it.
item.name = source;
item.mode = stats.mode;
+ item.mtime = stats.mtime; //modified time
+ item.atime = stats.atime; //access time
if (stats.isDirectory()) {
return onDir(item);
@@ -95,7 +94,17 @@ function ncp (source, dest, options, callback) {
rmFile(target, function () {
copyFile(file, target);
});
- } else {
+ }
+ if (modified) {
+ var stat = dereference ? fs.stat : fs.lstat;
+ stat(target, function(err, stats) {
+ //if souce modified time greater to target modified time copy file
+ if (file.mtime.getTime()>stats.mtime.getTime())
+ copyFile(file, target);
+ else return cb();
+ });
+ }
+ else {
return cb();
}
});
@@ -115,7 +124,14 @@ function ncp (source, dest, options, callback) {
readStream.pipe(writeStream);
});
}
- writeStream.once(eventName, cb);
+ writeStream.once('finish', function() {
+ if (modified) {
+ //target file modified date sync.
+ fs.utimesSync(target, file.atime, file.mtime);
+ cb();
+ }
+ else cb();
+ });
}
function rmFile(file, done) {
@@ -152,7 +168,7 @@ function ncp (source, dest, options, callback) {
return onError(err);
}
items.forEach(function (item) {
- startCopy(dir + '/' + item);
+ startCopy(path.join(dir, item));
});
return cb();
});
@@ -169,6 +185,9 @@ function ncp (source, dest, options, callback) {
}
function checkLink(resolvedPath, target) {
+ if (dereference) {
+ resolvedPath = path.resolve(basePath, resolvedPath);
+ }
isWritable(target, function (writable) {
if (writable) {
return makeLink(resolvedPath, target);
@@ -177,6 +196,9 @@ function ncp (source, dest, options, callback) {
if (err) {
return onError(err);
}
+ if (dereference) {
+ targetDest = path.resolve(basePath, targetDest);
+ }
if (targetDest === resolvedPath) {
return cb();
}
diff --git a/package.json b/package.json
index 67364d6..211f239 100644
--- a/package.json
+++ b/package.json
@@ -1,30 +1,30 @@
{
- "name" : "ncp",
- "version" : "0.6.0",
- "author": "AvianFlu <charlie at charlieistheman.com>",
- "description" : "Asynchronous recursive file copy utility.",
- "bin": {
- "ncp": "./bin/ncp"
- },
- "devDependencies" : {
- "mocha": "1.15.x",
- "rimraf" : "1.0.x",
- "read-dir-files" : "0.0.x"
- },
- "main": "./lib/ncp.js",
- "repository" : {
- "type" : "git",
- "url" : "https://github.com/AvianFlu/ncp.git"
- },
- "keywords" : [
- "cli",
- "copy"
- ],
- "license" : "MIT",
- "engine" : {
- "node" : ">=0.6"
- },
- "scripts" : {
- "test": "mocha -R spec"
- }
+ "name": "ncp",
+ "version": "2.0.0",
+ "author": "AvianFlu <charlie at charlieistheman.com>",
+ "description": "Asynchronous recursive file copy utility.",
+ "bin": {
+ "ncp": "./bin/ncp"
+ },
+ "devDependencies": {
+ "mocha": "1.15.x",
+ "rimraf": "1.0.x",
+ "read-dir-files": "0.0.x"
+ },
+ "main": "./lib/ncp.js",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/AvianFlu/ncp.git"
+ },
+ "keywords": [
+ "cli",
+ "copy"
+ ],
+ "license": "MIT",
+ "engine": {
+ "node": ">=0.10"
+ },
+ "scripts": {
+ "test": "mocha -R spec"
+ }
}
diff --git a/test/modified-files/out/a b/test/modified-files/out/a
new file mode 100644
index 0000000..d606037
--- /dev/null
+++ b/test/modified-files/out/a
@@ -0,0 +1 @@
+test2
\ No newline at end of file
diff --git a/test/modified-files/src/a b/test/modified-files/src/a
new file mode 100644
index 0000000..29f446a
--- /dev/null
+++ b/test/modified-files/src/a
@@ -0,0 +1 @@
+test3
\ No newline at end of file
diff --git a/test/ncp.js b/test/ncp.js
index 3ddc310..bc6df22 100644
--- a/test/ncp.js
+++ b/test/ncp.js
@@ -5,9 +5,11 @@ var assert = require('assert'),
path = require('path'),
rimraf = require('rimraf'),
readDirFiles = require('read-dir-files'),
+ util = require('util'),
ncp = require('../').ncp;
+
describe('ncp', function () {
describe('regular files and directories', function () {
var fixtures = path.join(__dirname, 'regular-fixtures'),
@@ -166,4 +168,30 @@ describe('ncp', function () {
});
});
});
-});
+
+ describe('modified files copies', function () {
+ var fixtures = path.join(__dirname, 'modified-files'),
+ src = path.join(fixtures, 'src'),
+ out = path.join(fixtures, 'out');
+
+ it('if file not exists copy file to target', function(cb) {
+ rimraf(out, function() {
+ ncp(src, out, {modified: true, clobber: false}, function (err) {
+ assert.equal(fs.existsSync(out), true);
+ cb();
+ });
+ });
+ });
+
+ it('change source file mtime and copy', function(cb) {
+ fs.utimesSync(src+"/a", new Date().getTime()/1000, new Date('2015-01-01 00:00:00').getTime()/1000);
+ ncp(src, out, {modified: true, clobber: false}, function (err) {
+ fs.stat(out+"/a", function(err, stats) {
+ assert.equal(stats.mtime.getTime(), new Date('2015-01-01 00:00:00').getTime());
+ cb();
+ });
+ });
+ });
+
+ });
+});
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-ncp.git
More information about the Pkg-javascript-commits
mailing list