Skip to content

Commit 2ea5167

Browse files
fixup! src: move cpSync dir copy logic completely to C++
use std::optional
1 parent 055b84b commit 2ea5167

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/node_file.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3432,7 +3432,7 @@ static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) {
34323432
bool verbatim_symlinks = args[5]->IsTrue();
34333433
bool preserve_timestamps = args[6]->IsTrue();
34343434

3435-
std::function<bool(std::string, std::string)> filter_fn = nullptr;
3435+
std::optional<std::function<bool(std::string, std::string)>> filter_fn;
34363436

34373437
if (args[7]->IsFunction()) {
34383438
Local<v8::Function> args_filter_fn = args[7].As<v8::Function>();
@@ -3485,12 +3485,9 @@ static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) {
34853485
for (auto dir_entry : std::filesystem::directory_iterator(src)) {
34863486
auto dest_file_path = dest / dir_entry.path().filename();
34873487

3488-
if (filter_fn) {
3489-
auto shouldSkip =
3490-
!filter_fn(dir_entry.path().c_str(), dest_file_path.c_str());
3491-
if (shouldSkip) {
3492-
continue;
3493-
}
3488+
if (filter_fn.has_value() && !filter_fn.value()(dir_entry.path().c_str(),
3489+
dest_file_path.c_str())) {
3490+
continue;
34943491
}
34953492

34963493
auto dest_str = PathToString(dest);

0 commit comments

Comments
 (0)