diff options
author | timoreo <contact@timoreo.fr> | 2022-11-01 09:56:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-01 09:56:16 +0100 |
commit | 04b39294ba012721279ca9d009f99f75178fd57a (patch) | |
tree | 1f0868f170d867bc77e1dcdac0168c6cbb794725 | |
parent | 3a446c410cc6200b3ca05a03867daabdb7b32b30 (diff) | |
parent | 81333515e0ecfa0ad0880032808a220a3f463e30 (diff) | |
download | PrismLauncher-04b39294ba012721279ca9d009f99f75178fd57a.tar.gz PrismLauncher-04b39294ba012721279ca9d009f99f75178fd57a.tar.bz2 PrismLauncher-04b39294ba012721279ca9d009f99f75178fd57a.zip |
Merge pull request #333 from flowln/fix_atl_packs_post_modpack_update
-rw-r--r-- | launcher/FileSystem.cpp | 32 | ||||
-rw-r--r-- | tests/FileSystem_test.cpp | 26 |
2 files changed, 46 insertions, 12 deletions
diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index aaa75e6f..4026d6c1 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -183,6 +183,21 @@ bool copy::operator()(const QString& offset) if (!m_followSymlinks) opt |= copy_opts::copy_symlinks; + // 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)) + return; + + auto dst_path = PathCombine(dst, relative_dst_path); + ensureFilePathExists(dst_path); + + fs::copy(toStdString(src_path), toStdString(dst_path), opt, err); + if (err) { + qWarning() << "Failed to copy files:" << QString::fromStdString(err.message()); + qDebug() << "Source file:" << src_path; + qDebug() << "Destination file:" << dst_path; + } + }; // We can't use copy_opts::recursive because we need to take into account the // blacklisted paths, so we iterate over the source directory, and if there's no blacklist @@ -194,20 +209,13 @@ bool copy::operator()(const QString& offset) auto src_path = source_it.next(); auto relative_path = src_dir.relativeFilePath(src_path); - if (m_blacklist && m_blacklist->matches(relative_path)) - continue; - - auto dst_path = PathCombine(dst, relative_path); - ensureFilePathExists(dst_path); - - fs::copy(toStdString(src_path), toStdString(dst_path), opt, err); - if (err) { - qWarning() << "Failed to copy files:" << QString::fromStdString(err.message()); - qDebug() << "Source file:" << src_path; - qDebug() << "Destination file:" << dst_path; - } + copy_file(src_path, relative_path); } + // If the root src is not a directory, the previous iterator won't run. + if (!fs::is_directory(toStdString(src))) + copy_file(src, ""); + return err.value() == 0; } diff --git a/tests/FileSystem_test.cpp b/tests/FileSystem_test.cpp index 47a963b0..21270f6f 100644 --- a/tests/FileSystem_test.cpp +++ b/tests/FileSystem_test.cpp @@ -183,6 +183,32 @@ slots: f(); } + void test_copy_single_file() + { + QTemporaryDir tempDir; + tempDir.setAutoRemove(true); + + { + QString file = QFINDTESTDATA("testdata/FileSystem/test_folder/pack.mcmeta"); + + qDebug() << "From:" << file << "To:" << tempDir.path(); + + QDir target_dir(FS::PathCombine(tempDir.path(), "pack.mcmeta")); + qDebug() << tempDir.path(); + qDebug() << target_dir.path(); + FS::copy c(file, target_dir.filePath("pack.mcmeta")); + c(); + + auto filter = QDir::Filter::Files; + + for (auto entry: target_dir.entryList(filter)) { + qDebug() << entry; + } + + QVERIFY(target_dir.entryList(filter).contains("pack.mcmeta")); + } + } + void test_getDesktop() { QCOMPARE(FS::getDesktopDir(), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); |