GeezerVison is showing github.com — fs: respect dereference when copy symlink directory · nodejs/node@ee89c31
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/node_file.cc +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -3060,7 +3060,9 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) { |
3060 | 3060 |
|
3061 | 3061 | bool dest_exists = !error_code && dest_status.type() != |
3062 | 3062 | std::filesystem::file_type::not_found; |
3063 | | - bool src_is_dir = src_status.type() == std::filesystem::file_type::directory; |
| 3063 | + bool src_is_dir = |
| 3064 | + (src_status.type() == std::filesystem::file_type::directory) || |
| 3065 | + (dereference && src_status.type() == std::filesystem::file_type::symlink); |
3064 | 3066 |
|
3065 | 3067 | if (!error_code) { |
3066 | 3068 | // Check if src and dest are identical. |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-fs-cp.mjs +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -119,6 +119,23 @@ function nextdir() { |
119 | 119 | } |
120 | 120 |
|
121 | 121 |
|
| 122 | +// It overrides target directory with what symlink points to, when dereference is true. |
| 123 | +{ |
| 124 | + const src = nextdir(); |
| 125 | + const symlink = nextdir(); |
| 126 | + const dest = nextdir(); |
| 127 | + mkdirSync(src, mustNotMutateObjectDeep({ recursive: true })); |
| 128 | + writeFileSync(join(src, 'foo.js'), 'foo', 'utf8'); |
| 129 | + symlinkSync(src, symlink); |
| 130 | + |
| 131 | + mkdirSync(dest, mustNotMutateObjectDeep({ recursive: true })); |
| 132 | + |
| 133 | + cpSync(symlink, dest, mustNotMutateObjectDeep({ dereference: true, recursive: true })); |
| 134 | + const destStat = lstatSync(dest); |
| 135 | + assert(!destStat.isSymbolicLink()); |
| 136 | + assertDirEquivalent(src, dest); |
| 137 | +} |
| 138 | + |
122 | 139 | // It throws error when verbatimSymlinks is not a boolean. |
123 | 140 | { |
124 | 141 | const src = './test/fixtures/copy/kitchen-sink'; |
|