Skip to content

Commit

Permalink
[build/fs] Fix copyAll default atime and mtime (#88921)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbudz committed Jan 21, 2021
1 parent 5ec099a commit 2d86004
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/dev/build/lib/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ export async function copy(source: string, destination: string, options: CopyOpt
interface CopyAllOptions {
select?: string[];
dot?: boolean;
time?: string | number | Date;
time?: Date;
}

export async function copyAll(
sourceDir: string,
destination: string,
options: CopyAllOptions = {}
) {
const { select = ['**/*'], dot = false, time = Date.now() } = options;
const { select = ['**/*'], dot = false, time = new Date() } = options;

assertAbsolute(sourceDir);
assertAbsolute(destination);
Expand Down
14 changes: 14 additions & 0 deletions src/dev/build/lib/integration_tests/fs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,20 @@ describe('copyAll()', () => {
expect(Math.abs(fooDir.atimeMs - time.getTime())).toBeLessThan(oneDay);
expect(Math.abs(barTxt.mtimeMs - time.getTime())).toBeLessThan(oneDay);
});

it('defaults atime and mtime to now', async () => {
const destination = resolve(TMP, 'a/b/c/d/e/f');
await copyAll(FIXTURES, destination);
const barTxt = statSync(resolve(destination, 'foo_dir/bar.txt'));
const fooDir = statSync(resolve(destination, 'foo_dir'));

// precision is platform specific
const now = new Date();
const oneDay = 86400000;
expect(Math.abs(barTxt.atimeMs - now.getTime())).toBeLessThan(oneDay);
expect(Math.abs(fooDir.atimeMs - now.getTime())).toBeLessThan(oneDay);
expect(Math.abs(barTxt.mtimeMs - now.getTime())).toBeLessThan(oneDay);
});
});

describe('getFileHash()', () => {
Expand Down

0 comments on commit 2d86004

Please sign in to comment.