Skip to content

Commit

Permalink
exclusionWildcards to also work for directories
Browse files Browse the repository at this point in the history
  • Loading branch information
mplpl committed Jan 24, 2022
1 parent 68c8f2f commit 229be77
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib7z/lib7z.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,27 @@ LIB7ZRC MLListArchive(std::wstring archiveNameW, std::vector<DirectoryItem> &ret
return 0;
}

bool DoesNameMatchWildcards(UString name, std::vector<std::wstring> exclusionWildcards) {
bool DoesNameMatchWildcards(UString name,
std::vector<std::wstring> &exclusionWildcards,
std::vector<UString> &removedPathes) {

for (std::vector<std::wstring>::iterator it = exclusionWildcards.begin();
it < exclusionWildcards.end(); it++)
{
UString nameOnly = ExtractFileNameFromPath(name);
bool match = DoesWildcardMatchName(it->c_str(), nameOnly);
if (match) return true;
if (match) {
removedPathes.push_back(name);
return true;
}
}

// now check if the item is not inside of already removed folder
for (std::vector<UString>::iterator it = removedPathes.begin();
it < removedPathes.end(); it++)
{
bool found = name.IsPrefixedBy((*it + L"/"));
if (found) return true;
}
return false;
}
Expand Down Expand Up @@ -242,12 +255,13 @@ LIB7ZRC MLExtractFromArchive(std::wstring archiveNameW, std::wstring outDirW,
files2.push_back(*it + L"/");
}

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

if (DoesNameMatchWildcards(filePath, exclusionWildcards)) continue;
if (DoesNameMatchWildcards(filePath, exclusionWildcards, removedPathes)) continue;

if (files.size())
{
Expand Down
12 changes: 12 additions & 0 deletions m7z/unittest/m7zTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,16 @@ -(void)testExtractWithExclusionsWildcard {
XCTAssert(ret.count == 2);
}

-(void)testExtractWithExclusionsWildcardDir {
M7ZArchive *archive = [[M7ZArchive alloc] initWithName:self.archName];
archive.delegate = self.delegate;
XCTAssert([archive addItems:@[self.subDir]] == 0);
XCTAssert([archive extractAllToDir:self.unpackDir
excluding:@[@"a"]] == 0);

NSFileManager *fm = [NSFileManager defaultManager];
NSError *err;
NSArray *ret = [fm contentsOfDirectoryAtPath:self.unpackDir error:&err];
XCTAssert(ret.count == 0);
}
@end

0 comments on commit 229be77

Please sign in to comment.