From c40496aaa1abbac526886695da3198e3e6f52f2c Mon Sep 17 00:00:00 2001 From: Shubham Joshi Date: Mon, 17 Sep 2018 22:15:31 -0700 Subject: [PATCH 01/10] Propogate the -u option when copying recursively --- src/cp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cp.js b/src/cp.js index 6218f670..aa3c80ef 100644 --- a/src/cp.js +++ b/src/cp.js @@ -260,7 +260,7 @@ function _cp(options, sources, dest) { try { common.statFollowLinks(path.dirname(dest)); - cpdirSyncRecursive(src, newDest, 0, { no_force: options.no_force, followsymlink: options.followsymlink }); + cpdirSyncRecursive(src, newDest, 0, { no_force: options.no_force, followsymlink: options.followsymlink, update: options.update }); } catch (e) { /* istanbul ignore next */ common.error("cannot create directory '" + dest + "': No such file or directory"); From 4ca5694d64452faec3ce88418dee419e879a7c52 Mon Sep 17 00:00:00 2001 From: Shubham Joshi Date: Mon, 17 Sep 2018 22:57:32 -0700 Subject: [PATCH 02/10] Added test for cp -Ru --- test/cp.js | 13 +++++++++++++ test/resources/cp/cp-Ru/bar/file | 0 test/resources/cp/cp-Ru/bar/foo/file | 0 test/resources/cp/cp-Ru/foo/file | 0 4 files changed, 13 insertions(+) create mode 100644 test/resources/cp/cp-Ru/bar/file create mode 100644 test/resources/cp/cp-Ru/bar/foo/file create mode 100644 test/resources/cp/cp-Ru/foo/file diff --git a/test/cp.js b/test/cp.js index 660dcb88..441cffe7 100644 --- a/test/cp.js +++ b/test/cp.js @@ -451,6 +451,19 @@ test('-R implies -P', t => { }); }); +test('-Ru no longer ignores -u', t => { + const [source, dest] = ['foo', 'bar'].map(s => `test/resources/cp/cp-Ru/${s}/file`); + // First, update the dest file + shell.touch(dest); + // Get the old mtime for dest + const oldTime = fs.statSync(dest).mtimeMs; + // Now, copy the old dir to the new one + shell.cp('-Ru', source, dest); + // Get the new mtime for dest + const newTime = fs.statSync(dest).mtimeMs; + t.is(oldTime, newTime); +}); + test('using -P explicitly works', t => { utils.skipOnWin(t, () => { shell.cp('-P', 'test/resources/cp/links/sym.lnk', t.context.tmp); diff --git a/test/resources/cp/cp-Ru/bar/file b/test/resources/cp/cp-Ru/bar/file new file mode 100644 index 00000000..e69de29b diff --git a/test/resources/cp/cp-Ru/bar/foo/file b/test/resources/cp/cp-Ru/bar/foo/file new file mode 100644 index 00000000..e69de29b diff --git a/test/resources/cp/cp-Ru/foo/file b/test/resources/cp/cp-Ru/foo/file new file mode 100644 index 00000000..e69de29b From dface6c7bcae4589d238f94895c45c9153baf299 Mon Sep 17 00:00:00 2001 From: Shubham Joshi Date: Mon, 17 Sep 2018 22:59:49 -0700 Subject: [PATCH 03/10] Fixed lint errors --- test/cp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cp.js b/test/cp.js index 441cffe7..08436f08 100644 --- a/test/cp.js +++ b/test/cp.js @@ -457,7 +457,7 @@ test('-Ru no longer ignores -u', t => { shell.touch(dest); // Get the old mtime for dest const oldTime = fs.statSync(dest).mtimeMs; - // Now, copy the old dir to the new one + // Now, copy the old dir to the new one shell.cp('-Ru', source, dest); // Get the new mtime for dest const newTime = fs.statSync(dest).mtimeMs; From 8d5811d7f229153c590adac8fc1bb642778cdbe0 Mon Sep 17 00:00:00 2001 From: Shubham Joshi Date: Tue, 18 Sep 2018 22:18:10 -0700 Subject: [PATCH 04/10] Better description of test case --- test/cp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cp.js b/test/cp.js index 08436f08..580fef45 100644 --- a/test/cp.js +++ b/test/cp.js @@ -451,7 +451,7 @@ test('-R implies -P', t => { }); }); -test('-Ru no longer ignores -u', t => { +test('-Ru respects the -u flag recursively', t => { const [source, dest] = ['foo', 'bar'].map(s => `test/resources/cp/cp-Ru/${s}/file`); // First, update the dest file shell.touch(dest); From 3f2d0fd413dd26a0489ed11a2f9bf1edc40a304e Mon Sep 17 00:00:00 2001 From: Shubham Joshi Date: Thu, 20 Sep 2018 00:14:56 -0700 Subject: [PATCH 05/10] Fixed test to check contents. Added test for succesful updates --- test/cp.js | 42 ++++++++++++++++++++++------ test/resources/cp/cp-Ru/bar/file | 0 test/resources/cp/cp-Ru/bar/foo/file | 0 test/resources/cp/cp-Ru/foo/file | 0 4 files changed, 34 insertions(+), 8 deletions(-) delete mode 100644 test/resources/cp/cp-Ru/bar/file delete mode 100644 test/resources/cp/cp-Ru/bar/foo/file delete mode 100644 test/resources/cp/cp-Ru/foo/file diff --git a/test/cp.js b/test/cp.js index 580fef45..f22df6f4 100644 --- a/test/cp.js +++ b/test/cp.js @@ -451,17 +451,43 @@ test('-R implies -P', t => { }); }); -test('-Ru respects the -u flag recursively', t => { - const [source, dest] = ['foo', 'bar'].map(s => `test/resources/cp/cp-Ru/${s}/file`); - // First, update the dest file - shell.touch(dest); +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)); + ShellString('foo\n').to(sourceFile); + ShellString('bar\n').to(destFile); // Get the old mtime for dest - const oldTime = fs.statSync(dest).mtimeMs; + const oldTime = fs.statSync(destFile).mtimeMs; + // Send the old file to two days ago + shell.touch('-m', oldTime - (2 * 24 * 60 * 60 * 1000), sourceFile); // Now, copy the old dir to the new one - shell.cp('-Ru', source, dest); + 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)); + ShellString('foo\n').to(sourceFile); + 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 - const newTime = fs.statSync(dest).mtimeMs; - t.is(oldTime, newTime); + // Check that dest has been updated + t.is(shell.cat(sourceFile).stdout, 'foo\n'); }); test('using -P explicitly works', t => { diff --git a/test/resources/cp/cp-Ru/bar/file b/test/resources/cp/cp-Ru/bar/file deleted file mode 100644 index e69de29b..00000000 diff --git a/test/resources/cp/cp-Ru/bar/foo/file b/test/resources/cp/cp-Ru/bar/foo/file deleted file mode 100644 index e69de29b..00000000 diff --git a/test/resources/cp/cp-Ru/foo/file b/test/resources/cp/cp-Ru/foo/file deleted file mode 100644 index e69de29b..00000000 From 3283d5e57df3253740ba6369f6a5587b98bc8dbc Mon Sep 17 00:00:00 2001 From: Shubham Joshi Date: Thu, 20 Sep 2018 00:26:39 -0700 Subject: [PATCH 06/10] Fixed undefined reference error --- test/cp.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/cp.js b/test/cp.js index f22df6f4..d38770b7 100644 --- a/test/cp.js +++ b/test/cp.js @@ -458,8 +458,8 @@ test('-Ru respects the -u flag recursively (don\'t update newer file)', t => { const destDir = `${dir}/new`; const destFile = `${destDir}/file`; [sourceDir, destDir].forEach(d => shell.mkdir('-p', d)); - ShellString('foo\n').to(sourceFile); - ShellString('bar\n').to(destFile); + 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 old file to two days ago @@ -477,8 +477,8 @@ test('-Ru respects the -u flag recursively (update older file)', t => { const destDir = `${dir}/new`; const destFile = `${destDir}/file`; [sourceDir, destDir].forEach(d => shell.mkdir('-p', d)); - ShellString('foo\n').to(sourceFile); - ShellString('bar\n').to(destFile); + 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 From ee59552460b3f588016d6ab01c80e78c3c269cf4 Mon Sep 17 00:00:00 2001 From: Shubham Joshi Date: Thu, 20 Sep 2018 00:38:13 -0700 Subject: [PATCH 07/10] Fixed lint errors --- test/cp.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/cp.js b/test/cp.js index d38770b7..54135792 100644 --- a/test/cp.js +++ b/test/cp.js @@ -453,10 +453,10 @@ 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 sourceDir = `${dir}/old`; const sourceFile = `${sourceDir}/file`; - const destDir = `${dir}/new`; - const destFile = `${destDir}/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); @@ -472,10 +472,10 @@ test('-Ru respects the -u flag recursively (don\'t update newer file)', t => { test('-Ru respects the -u flag recursively (update older file)', t => { const dir = `${t.context.tmp}/cp-Ru`; - const sourceDir = `${dir}/old`; + const sourceDir = `${dir}/old`; const sourceFile = `${sourceDir}/file`; - const destDir = `${dir}/new`; - const destFile = `${destDir}/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); From cdb269f8c4111ca603152a752d75e99ce58d9c7c Mon Sep 17 00:00:00 2001 From: Shubham Joshi Date: Sun, 28 Oct 2018 04:43:28 -0700 Subject: [PATCH 08/10] Cleaned up comments and strings to make them more descriptive --- test/cp.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/cp.js b/test/cp.js index 54135792..12cbf2f2 100644 --- a/test/cp.js +++ b/test/cp.js @@ -458,16 +458,16 @@ test('-Ru respects the -u flag recursively (don\'t update newer file)', t => { 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); + shell.ShellString('Source File Contents\n').to(sourceFile); + shell.ShellString('Destination File Contents\n').to(destFile); // Get the old mtime for dest const oldTime = fs.statSync(destFile).mtimeMs; - // Send the old file to two days ago + // Send the source file to be older than the destination file 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'); + t.is(shell.cat(destFile).stdout, 'Destination File Contents\n'); }); test('-Ru respects the -u flag recursively (update older file)', t => { @@ -477,17 +477,16 @@ test('-Ru respects the -u flag recursively (update older file)', t => { 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); + shell.ShellString('Source File Contents\n').to(sourceFile); + shell.ShellString('Destination File Contents\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 // Check that dest has been updated - t.is(shell.cat(sourceFile).stdout, 'foo\n'); + t.is(shell.cat(sourceFile).stdout, 'Source File Contents\n'); }); test('using -P explicitly works', t => { From d4c27fc534211bc8251a5b4ad4e33ad0c493ccf3 Mon Sep 17 00:00:00 2001 From: Shubham Joshi Date: Sun, 28 Oct 2018 04:54:05 -0700 Subject: [PATCH 09/10] Created constant for magic number (two days in ms) --- test/cp.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/test/cp.js b/test/cp.js index 12cbf2f2..503e2c37 100644 --- a/test/cp.js +++ b/test/cp.js @@ -452,6 +452,8 @@ test('-R implies -P', t => { }); test('-Ru respects the -u flag recursively (don\'t update newer file)', t => { + // Setup code + const TWO_DAYS_IN_MS = 2 * 24 * 60 * 60 * 1000; const dir = `${t.context.tmp}/cp-Ru`; const sourceDir = `${dir}/old`; const sourceFile = `${sourceDir}/file`; @@ -460,10 +462,12 @@ test('-Ru respects the -u flag recursively (don\'t update newer file)', t => { [sourceDir, destDir].forEach(d => shell.mkdir('-p', d)); shell.ShellString('Source File Contents\n').to(sourceFile); shell.ShellString('Destination File Contents\n').to(destFile); + // End setup + // Get the old mtime for dest const oldTime = fs.statSync(destFile).mtimeMs; - // Send the source file to be older than the destination file - shell.touch('-m', oldTime - (2 * 24 * 60 * 60 * 1000), sourceFile); + // Set the source file to be older than the destination file + shell.touch('-m', oldTime - TWO_DAYS_IN_MS, sourceFile); // Now, copy the old dir to the new one shell.cp('-Ru', sourceDir, destDir); // Check that dest has not been updated @@ -471,6 +475,8 @@ test('-Ru respects the -u flag recursively (don\'t update newer file)', t => { }); test('-Ru respects the -u flag recursively (update older file)', t => { + // Setup code + const TWO_DAYS_IN_MS = 2 * 24 * 60 * 60 * 1000; const dir = `${t.context.tmp}/cp-Ru`; const sourceDir = `${dir}/old`; const sourceFile = `${sourceDir}/file`; @@ -479,10 +485,12 @@ test('-Ru respects the -u flag recursively (update older file)', t => { [sourceDir, destDir].forEach(d => shell.mkdir('-p', d)); shell.ShellString('Source File Contents\n').to(sourceFile); shell.ShellString('Destination File Contents\n').to(destFile); + // End setup + // 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); + // Set the destination file to be older than the source file + shell.touch('-m', oldTime + TWO_DAYS_IN_MS, sourceFile); // Now, copy the old dir to the new one shell.cp('-Ru', sourceDir, destDir); // Check that dest has been updated From f5907472bdb9e07058777634f13170f70f31e56b Mon Sep 17 00:00:00 2001 From: Shubham Joshi Date: Sun, 28 Oct 2018 05:04:01 -0700 Subject: [PATCH 10/10] Removed trailing spaces --- test/cp.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/cp.js b/test/cp.js index 503e2c37..f3606a27 100644 --- a/test/cp.js +++ b/test/cp.js @@ -463,7 +463,6 @@ test('-Ru respects the -u flag recursively (don\'t update newer file)', t => { shell.ShellString('Source File Contents\n').to(sourceFile); shell.ShellString('Destination File Contents\n').to(destFile); // End setup - // Get the old mtime for dest const oldTime = fs.statSync(destFile).mtimeMs; // Set the source file to be older than the destination file @@ -486,7 +485,6 @@ test('-Ru respects the -u flag recursively (update older file)', t => { shell.ShellString('Source File Contents\n').to(sourceFile); shell.ShellString('Destination File Contents\n').to(destFile); // End setup - // Get the old mtime for dest const oldTime = fs.statSync(destFile).mtimeMs; // Set the destination file to be older than the source file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy