Skip to content

Commit

Permalink
fix(util/fs): use file content instead of mtime to determine equality (
Browse files Browse the repository at this point in the history
…yarnpkg#6010)

npm 6 locks mtime of all files in the published tarball to be October
26th 1985, which means mtime is no longer changed when a package
is published with an npm version above 6.

See: https://npm.community/t/tarball-content-timestamps-locked-to-1985/149

Fixes: yarnpkg#5723
  • Loading branch information
rufman authored and arcanis committed Jun 21, 2018
1 parent 7f1a3f4 commit c53d039
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/reporters/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const messages = {
verboseFileCopy: 'Copying $0 to $1.',
verboseFileLink: 'Creating hardlink at $0 to $1.',
verboseFileSymlink: 'Creating symlink at $0 to $1.',
verboseFileSkip: 'Skipping copying of file $0 as the file at $1 is the same size ($2) and mtime ($3).',
verboseFileSkip: 'Skipping copying of file $0 as the file at $1 is the same size ($2) and has the same content.',
verboseFileSkipSymlink: 'Skipping copying of $0 as the file at $1 is the same symlink ($2).',
verboseFileSkipHardlink: 'Skipping copying of $0 as the file at $1 is the same hardlink ($2).',
verboseFileRemoveExtraneous: 'Removing extraneous file $0.',
Expand Down
6 changes: 3 additions & 3 deletions src/util/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import BlockingQueue from './blocking-queue.js';
import * as promise from './promise.js';
import {promisify} from './promise.js';
import map from './map.js';
import {copyFile, fileDatesEqual, unlink} from './fs-normalized.js';
import {copyFile, unlink} from './fs-normalized.js';

export const constants =
typeof fs.constants !== 'undefined'
Expand Down Expand Up @@ -222,10 +222,10 @@ async function buildActionsForCopy(
return;
}

if (bothFiles && srcStat.size === destStat.size && fileDatesEqual(srcStat.mtime, destStat.mtime)) {
if (bothFiles && srcStat.size === destStat.size && fs.readFileSync(src).equals(fs.readFileSync(dest))) {
// we can safely assume this is the same file
onDone();
reporter.verbose(reporter.lang('verboseFileSkip', src, dest, srcStat.size, +srcStat.mtime));
reporter.verbose(reporter.lang('verboseFileSkip', src, dest, srcStat.size));
return;
}

Expand Down

0 comments on commit c53d039

Please sign in to comment.