Skip to content

Commit 229be77

Browse files
committed
exclusionWildcards to also work for directories
1 parent 68c8f2f commit 229be77

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

lib7z/lib7z.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,27 @@ LIB7ZRC MLListArchive(std::wstring archiveNameW, std::vector<DirectoryItem> &ret
176176
return 0;
177177
}
178178

179-
bool DoesNameMatchWildcards(UString name, std::vector<std::wstring> exclusionWildcards) {
179+
bool DoesNameMatchWildcards(UString name,
180+
std::vector<std::wstring> &exclusionWildcards,
181+
std::vector<UString> &removedPathes) {
180182

181183
for (std::vector<std::wstring>::iterator it = exclusionWildcards.begin();
182184
it < exclusionWildcards.end(); it++)
183185
{
184186
UString nameOnly = ExtractFileNameFromPath(name);
185187
bool match = DoesWildcardMatchName(it->c_str(), nameOnly);
186-
if (match) return true;
188+
if (match) {
189+
removedPathes.push_back(name);
190+
return true;
191+
}
192+
}
193+
194+
// now check if the item is not inside of already removed folder
195+
for (std::vector<UString>::iterator it = removedPathes.begin();
196+
it < removedPathes.end(); it++)
197+
{
198+
bool found = name.IsPrefixedBy((*it + L"/"));
199+
if (found) return true;
187200
}
188201
return false;
189202
}
@@ -242,12 +255,13 @@ LIB7ZRC MLExtractFromArchive(std::wstring archiveNameW, std::wstring outDirW,
242255
files2.push_back(*it + L"/");
243256
}
244257

258+
std::vector<UString> removedPathes;
245259
for (UInt32 i = 0; i < numItems; i++)
246260
{
247261
UString filePath;
248262
RINOK(arc.GetItemPath(i, filePath));
249263

250-
if (DoesNameMatchWildcards(filePath, exclusionWildcards)) continue;
264+
if (DoesNameMatchWildcards(filePath, exclusionWildcards, removedPathes)) continue;
251265

252266
if (files.size())
253267
{

m7z/unittest/m7zTests.m

+12
Original file line numberDiff line numberDiff line change
@@ -333,4 +333,16 @@ -(void)testExtractWithExclusionsWildcard {
333333
XCTAssert(ret.count == 2);
334334
}
335335

336+
-(void)testExtractWithExclusionsWildcardDir {
337+
M7ZArchive *archive = [[M7ZArchive alloc] initWithName:self.archName];
338+
archive.delegate = self.delegate;
339+
XCTAssert([archive addItems:@[self.subDir]] == 0);
340+
XCTAssert([archive extractAllToDir:self.unpackDir
341+
excluding:@[@"a"]] == 0);
342+
343+
NSFileManager *fm = [NSFileManager defaultManager];
344+
NSError *err;
345+
NSArray *ret = [fm contentsOfDirectoryAtPath:self.unpackDir error:&err];
346+
XCTAssert(ret.count == 0);
347+
}
336348
@end

0 commit comments

Comments
 (0)