refactor: allow copy operation with whitelist
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
parent
ddfb449b28
commit
e048bce13e
@ -174,7 +174,7 @@ bool copy::operator()(const QString& offset)
|
||||
|
||||
// Function that'll do the actual copying
|
||||
auto copy_file = [&](QString src_path, QString relative_dst_path) {
|
||||
if (m_blacklist && m_blacklist->matches(relative_dst_path))
|
||||
if (m_matcher && (m_matcher->matches(relative_dst_path) == !m_whitelist))
|
||||
return;
|
||||
|
||||
auto dst_path = PathCombine(dst, relative_dst_path);
|
||||
|
@ -88,9 +88,14 @@ class copy {
|
||||
m_followSymlinks = follow;
|
||||
return *this;
|
||||
}
|
||||
copy& blacklist(const IPathMatcher* filter)
|
||||
copy& matcher(const IPathMatcher* filter)
|
||||
{
|
||||
m_blacklist = filter;
|
||||
m_matcher = filter;
|
||||
return *this;
|
||||
}
|
||||
copy& whitelist(bool whitelist)
|
||||
{
|
||||
m_whitelist = whitelist;
|
||||
return *this;
|
||||
}
|
||||
bool operator()() { return operator()(QString()); }
|
||||
@ -100,7 +105,8 @@ class copy {
|
||||
|
||||
private:
|
||||
bool m_followSymlinks = true;
|
||||
const IPathMatcher* m_blacklist = nullptr;
|
||||
const IPathMatcher* m_matcher = nullptr;
|
||||
bool m_whitelist = false;
|
||||
QDir m_src;
|
||||
QDir m_dst;
|
||||
};
|
||||
|
@ -26,7 +26,7 @@ void InstanceCopyTask::executeTask()
|
||||
setStatus(tr("Copying instance %1").arg(m_origInstance->name()));
|
||||
|
||||
FS::copy folderCopy(m_origInstance->instanceRoot(), m_stagingPath);
|
||||
folderCopy.followSymlinks(false).blacklist(m_matcher.get());
|
||||
folderCopy.followSymlinks(false).matcher(m_matcher.get());
|
||||
|
||||
m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), folderCopy);
|
||||
connect(&m_copyFutureWatcher, &QFutureWatcher<bool>::finished, this, &InstanceCopyTask::copyFinished);
|
||||
|
@ -126,7 +126,7 @@ slots:
|
||||
qDebug() << tempDir.path();
|
||||
qDebug() << target_dir.path();
|
||||
FS::copy c(folder, target_dir.path());
|
||||
c.blacklist(new RegexpMatcher("[.]?mcmeta"));
|
||||
c.matcher(new RegexpMatcher("[.]?mcmeta"));
|
||||
c();
|
||||
|
||||
for(auto entry: target_dir.entryList())
|
||||
@ -147,6 +147,41 @@ slots:
|
||||
f();
|
||||
}
|
||||
|
||||
void test_copy_with_whitelist()
|
||||
{
|
||||
QString folder = QFINDTESTDATA("testdata/FileSystem/test_folder");
|
||||
auto f = [&folder]()
|
||||
{
|
||||
QTemporaryDir tempDir;
|
||||
tempDir.setAutoRemove(true);
|
||||
qDebug() << "From:" << folder << "To:" << tempDir.path();
|
||||
|
||||
QDir target_dir(FS::PathCombine(tempDir.path(), "test_folder"));
|
||||
qDebug() << tempDir.path();
|
||||
qDebug() << target_dir.path();
|
||||
FS::copy c(folder, target_dir.path());
|
||||
c.matcher(new RegexpMatcher("[.]?mcmeta"));
|
||||
c.whitelist(true);
|
||||
c();
|
||||
|
||||
for(auto entry: target_dir.entryList())
|
||||
{
|
||||
qDebug() << entry;
|
||||
}
|
||||
QVERIFY(target_dir.entryList().contains("pack.mcmeta"));
|
||||
QVERIFY(!target_dir.entryList().contains("assets"));
|
||||
};
|
||||
|
||||
// first try variant without trailing /
|
||||
QVERIFY(!folder.endsWith('/'));
|
||||
f();
|
||||
|
||||
// then variant with trailing /
|
||||
folder.append('/');
|
||||
QVERIFY(folder.endsWith('/'));
|
||||
f();
|
||||
}
|
||||
|
||||
void test_copy_with_dot_hidden()
|
||||
{
|
||||
QString folder = QFINDTESTDATA("testdata/FileSystem/test_folder");
|
||||
|
Loading…
Reference in New Issue
Block a user