Skip to content

Commit e59acd9

Browse files
Fix the Dir::Size API for Windows (#1379)
Filtering should be applied for files only. Relates-To: OLPEDGE-2733 Signed-off-by: Mykhailo Kuchma <[email protected]>
1 parent 6438ec8 commit e59acd9

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

olp-cpp-sdk-core/src/utils/Dir.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,14 @@ uint64_t Dir::Size(const std::string& path, FilterFunction filter_fn) {
418418
continue;
419419
}
420420

421-
if (filter_fn && !filter_fn(find_data.cFileName)) {
422-
continue;
423-
}
424-
425421
if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
426422
current_path = path + "\\" + find_data.cFileName;
427423
result += Size(current_path, filter_fn);
428424
} else {
425+
if (filter_fn && !filter_fn(find_data.cFileName)) {
426+
continue;
427+
}
428+
429429
LARGE_INTEGER size;
430430
size.LowPart = find_data.nFileSizeLow;
431431
size.HighPart = find_data.nFileSizeHigh;

tests/functional/olp-cpp-sdk-core/DirTest.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ TEST(DirTest, CheckDirSize) {
116116
CreateFile(PathBuild(path, "sub", "subsub", "subsub_file2"), 10);
117117
EXPECT_EQ(Dir::Size(path), 60u);
118118
}
119+
{
120+
SCOPED_TRACE("Filtering");
121+
CreateFile(PathBuild(path, "file3.hpp"), 10);
122+
CreateFile(PathBuild(path, "sub", "sub_file2"), 10);
123+
CreateFile(PathBuild(path, "sub", "subsub", "subsub_file2"), 10);
124+
EXPECT_EQ(Dir::Size(path,
125+
[](const std::string& filename) {
126+
return filename.find(".hpp") != std::string::npos;
127+
}),
128+
10u);
129+
}
119130
Dir::Remove(path);
120131
}
121132

0 commit comments

Comments
 (0)