ncp
ncp copied to clipboard
File permissions on destination not matching source?
trafficstars
I poked around the code and noticed that it doesn't indeed attempt to preserve file permissions, but I feel that I must be doing something wrong if that's case.
Here's my test program with ncp 0.5.0 and v0.10.25:
var fs = require('fs');
var path = require('path');
var ncp = require('ncp');
var assert = require('assert');
var userid = require('userid'); //npm install --save userid
var rimraf = require('rimraf'); //npm install --save rimraf
var DIR = '/tmp/ncptest';
if (fs.existsSync(DIR))
rimraf.sync(DIR);
fs.mkdirSync(DIR);
//http://man7.org/linux/man-pages/man2/stat.2.html
var S_IFREG = 0100000 //regular file
var S_IFDIR = 0040000 //directory
var permDir = path.join(DIR, 'perms');
fs.mkdirSync(permDir);
var srcDir = path.join(permDir, 'src');
fs.mkdirSync(srcDir);
var f1 = path.join(srcDir, 'f1.txt');
fs.writeFileSync(f1, '');
fs.chmodSync(f1, 0666);
fs.chownSync(f1, process.getuid(), userid.gid('wheel'));
var f1stats = fs.lstatSync(f1);
assert.equal (f1stats.mode - S_IFREG, 0666);
var d1 = path.join(srcDir, 'somedir');
fs.mkdirSync(d1);
fs.chmodSync(d1, 0777);
fs.chownSync(d1, process.getuid(), userid.gid('staff'));
var d1stats = fs.lstatSync(d1);
assert.equal (d1stats.mode - S_IFDIR, 0777);
var f2 = path.join(d1, 'f2.bin');
fs.writeFileSync(f2, '');
fs.chmodSync(f2, 0777);
fs.chownSync(f2, process.getuid(), userid.gid('staff'));
var f2stats = fs.lstatSync(f2);
assert.equal (f2stats.mode - S_IFREG, 0777);
var d2 = path.join(srcDir, 'crazydir');
fs.mkdirSync(d2);
fs.chmodSync(d2, 0444);
fs.chownSync(d2, process.getuid(), userid.gid('wheel'));
var d2stats = fs.lstatSync(d2);
assert.equal (d2stats.mode - S_IFDIR, 0444);
var destDir = path.join(permDir, 'dest');
ncp(srcDir, destDir, function(err) {
assert (!err)
var newf1stats = fs.lstatSync(path.join(permDir, 'dest/f1.txt'));
var newd1stats = fs.lstatSync(path.join(permDir, 'dest/somedir'));
var newf2stats = fs.lstatSync(path.join(permDir, 'dest/somedir/f2.bin'));
var newd2stats = fs.lstatSync(path.join(permDir, 'dest/crazydir'));
assert.equal (newf1stats.mode, f1stats.mode);
assert.equal (newd1stats.mode, d1stats.mode);
assert.equal (newf2stats.mode, f2stats.mode);
assert.equal (newd2stats.mode, d2stats.mode);
})
Any ideas?
Have you verified that this is a bug?
I believe this bug is preventing my tests from running under Windows. I see many EPERM errors.
I can confirm that the test fails. Haven't figured out why yet. I'll investigate some more, but I'd also definitely take a patch if anybody else figures it out first.