New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cp): support update flag when recursing #889
Changes from 7 commits
c40496a
4ca5694
dface6c
8d5811d
3f2d0fd
3283d5e
ee59552
cdb269f
d4c27fc
0b1579b
f590747
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -451,6 +451,45 @@ test('-R implies -P', t => { | |
}); | ||
}); | ||
|
||
test('-Ru respects the -u flag recursively (don\'t update newer file)', t => { | ||
const dir = `${t.context.tmp}/cp-Ru`; | ||
const sourceDir = `${dir}/old`; | ||
const sourceFile = `${sourceDir}/file`; | ||
const destDir = `${dir}/new`; | ||
const destFile = `${destDir}/file`; | ||
[sourceDir, destDir].forEach(d => shell.mkdir('-p', d)); | ||
shell.ShellString('foo\n').to(sourceFile); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: file contents could be more descriptive. How about |
||
shell.ShellString('bar\n').to(destFile); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to separate setup from test logic. Two (alternative) suggestions:
You'll need to continue modifying the time stamps at runtime, as you have here. |
||
// Get the old mtime for dest | ||
const oldTime = fs.statSync(destFile).mtimeMs; | ||
// Send the old file to two days ago | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: you can better document this by creating a constant You could then make this comment more descriptive: |
||
shell.touch('-m', oldTime - (2 * 24 * 60 * 60 * 1000), sourceFile); | ||
// Now, copy the old dir to the new one | ||
shell.cp('-Ru', sourceDir, destDir); | ||
// Check that dest has not been updated | ||
t.is(shell.cat(destFile).stdout, 'bar\n'); | ||
}); | ||
|
||
test('-Ru respects the -u flag recursively (update older file)', t => { | ||
const dir = `${t.context.tmp}/cp-Ru`; | ||
const sourceDir = `${dir}/old`; | ||
const sourceFile = `${sourceDir}/file`; | ||
const destDir = `${dir}/new`; | ||
const destFile = `${destDir}/file`; | ||
[sourceDir, destDir].forEach(d => shell.mkdir('-p', d)); | ||
shell.ShellString('foo\n').to(sourceFile); | ||
shell.ShellString('bar\n').to(destFile); | ||
// Get the old mtime for dest | ||
const oldTime = fs.statSync(destFile).mtimeMs; | ||
// Send the source file to two days ahead | ||
shell.touch('-m', oldTime + (2 * 24 * 60 * 60 * 1000), sourceFile); | ||
// Now, copy the old dir to the new one | ||
shell.cp('-Ru', sourceDir, destDir); | ||
// Get the new mtime for dest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I think this comment is leftover from a previous commit (you're not checking mtimes anymore) |
||
// Check that dest has been updated | ||
t.is(shell.cat(sourceFile).stdout, 'foo\n'); | ||
}); | ||
|
||
joshi-sh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
test('using -P explicitly works', t => { | ||
utils.skipOnWin(t, () => { | ||
shell.cp('-P', 'test/resources/cp/links/sym.lnk', t.context.tmp); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be able to replace this with a template literal to avoid escaping the apostrophe. I can't remember if our lint currently forbids this (see #788). If lint complains, just leave as-is.