Skip to content

Commit

Permalink
Update time before fd close
Browse files Browse the repository at this point in the history
  • Loading branch information
dwi2 committed May 10, 2018
1 parent d84236d commit 3ede418
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/cp.js
Expand Up @@ -74,13 +74,13 @@ function copyFileSync(srcFile, destFile, options) {
pos += bytesRead;
}

fs.closeSync(fdr);
fs.closeSync(fdw);

if (options.preserve) {
fs.chownSync(destFile, srcStat.uid, srcStat.gid);
fs.utimesSync(destFile, srcStat.atime, srcStat.mtime);
fs.fchownSync(fdw, srcStat.uid, srcStat.gid);
fs.futimesSync(fdw, srcStat.atime, srcStat.mtime);
}

fs.closeSync(fdr);
fs.closeSync(fdw);
}
}

Expand Down
6 changes: 0 additions & 6 deletions test/cp.js
Expand Up @@ -760,9 +760,6 @@ test('should not overwrite recently created files (not give error no-force mode)
test('cp -p should preserve mode, ownership, and timestamp', t => {
const result = shell.cp('-p', 'test/resources/file1', `${t.context.tmp}/preservedFile1`);
const stat = common.statFollowLinks('test/resources/file1');
if (process.platform === 'linux') {
utils.sleep(1000);
}
const statOfResult = common.statFollowLinks(`${t.context.tmp}/preservedFile1`);

t.is(result.code, 0);
Expand All @@ -776,9 +773,6 @@ test('cp -p should preserve mode, ownership, and timestamp', t => {
test('cp -p should preserve mode, ownership, and timestamp of symlink', t => {
const result = shell.cp('-p', 'test/resources/link', `${t.context.tmp}/copiedLink`);
const stat = common.statFollowLinks('test/resources/link');
if (process.platform === 'linux') {
utils.sleep(1000);
}
const statOfResult = common.statFollowLinks(`${t.context.tmp}/copiedLink`);

t.is(result.code, 0);
Expand Down

0 comments on commit 3ede418

Please sign in to comment.