fix: copy needs to overwrite

Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
Rachel Powers 2023-06-28 13:51:58 -07:00
parent 400a2f7201
commit cb7ff81ade
No known key found for this signature in database
GPG Key ID: E10E321EB160949B
3 changed files with 13 additions and 4 deletions

View File

@ -297,6 +297,9 @@ bool copy::operator()(const QString& offset, bool dryRun)
if (!m_followSymlinks)
opt |= copy_opts::copy_symlinks;
if (m_overwrite)
opt |= copy_opts::overwrite_existing;
// Function that'll do the actual copying
auto copy_file = [&](QString src_path, QString relative_dst_path) {
if (m_matcher && (m_matcher->matches(relative_dst_path) != m_whitelist))

View File

@ -120,6 +120,11 @@ class copy : public QObject {
m_whitelist = whitelist;
return *this;
}
copy& overwrite(const bool overwrite)
{
m_overwrite = overwrite;
return *this;
}
bool operator()(bool dryRun = false) { return operator()(QString(), dryRun); }
@ -136,6 +141,7 @@ class copy : public QObject {
bool m_followSymlinks = true;
const IPathMatcher* m_matcher = nullptr;
bool m_whitelist = false;
bool m_overwrite = false;
QDir m_src;
QDir m_dst;
int m_copied;

View File

@ -672,7 +672,7 @@ void PrismUpdaterApp::moveAndFinishUpdate(QDir target)
auto install_path = FS::PathCombine(target.absolutePath(), rel_path);
logUpdate(tr("Installing %1 from %2").arg(install_path).arg(to_install_file));
FS::ensureFilePathExists(install_path);
auto result = FS::copy(to_install_file, install_path)();
auto result = FS::copy(to_install_file, install_path).overwrite(true)();
if (!result) {
error = true;
logUpdate(tr("Failed copy %1 to %2").arg(to_install_file).arg(install_path));
@ -686,11 +686,11 @@ void PrismUpdaterApp::moveAndFinishUpdate(QDir target)
if (error) {
logUpdate(tr("There were errors installing the update."));
auto fail_marker = FS::PathCombine(m_dataPath, ".prism_launcher_update.fail");
FS::copy(m_updateLogPath, fail_marker)();
FS::copy(m_updateLogPath, fail_marker).overwrite(true)();
} else {
logUpdate(tr("Update succeed."));
auto success_marker = FS::PathCombine(m_dataPath, ".prism_launcher_update.success");
FS::copy(m_updateLogPath, success_marker)();
FS::copy(m_updateLogPath, success_marker).overwrite(true)();
}
auto update_lock_path = FS::PathCombine(m_dataPath, ".prism_launcher_update.lock");
FS::deletePath(update_lock_path);
@ -1078,7 +1078,7 @@ void PrismUpdaterApp::backupAppDir()
auto bak_path = FS::PathCombine(backup_dir, rel_path);
logUpdate(tr("Backing up and then removing %1").arg(to_bak_file));
FS::ensureFilePathExists(bak_path);
auto result = FS::copy(to_bak_file, bak_path)();
auto result = FS::copy(to_bak_file, bak_path).overwrite(true)();
if (!result) {
logUpdate(tr("Failed to backup %1 to %2").arg(to_bak_file).arg(bak_path));
} else {