MCPcopy
hub / github.com/webpack/webpack / copyDiff

Function copyDiff

test/WatchTestCases.template.js:38–66  ·  view source on GitHub ↗

* @param {string} src src * @param {string} dest dest * @param {boolean} initial is initial?

(src, dest, initial)

Source from the content-addressed store, hash-verified

36 * @param {boolean} initial is initial?
37 */
38function copyDiff(src, dest, initial) {
39 if (!fs.existsSync(dest)) fs.mkdirSync(dest);
40 const files = fs.readdirSync(src);
41 for (const filename of files) {
42 const srcFile = path.join(src, filename);
43 const destFile = path.join(dest, filename);
44 const directory = fs.statSync(srcFile).isDirectory();
45 if (directory) {
46 copyDiff(srcFile, destFile, initial);
47 } else {
48 const content = fs.readFileSync(srcFile);
49 if (/^DELETE\s*$/.test(content.toString("utf8"))) {
50 fs.unlinkSync(destFile);
51 } else if (/^DELETE_DIRECTORY\s*$/.test(content.toString("utf8"))) {
52 rimraf.sync(destFile);
53 } else {
54 fs.writeFileSync(destFile, content);
55 if (initial) {
56 const longTimeAgo = Date.now() - 1000 * 60 * 60 * 24;
57 fs.utimesSync(
58 destFile,
59 Date.now() - longTimeAgo,
60 Date.now() - longTimeAgo
61 );
62 }
63 }
64 }
65 }
66}
67
68/**
69 * @param {SuiteConfig} config suite config

Callers 1

describeCasesFunction · 0.85

Calls 2

testMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected