Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on creating debug archive in read-only location #6598

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions src/gui/generalsettings.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/generalsettings.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/generalsettings.cpp

File src/gui/generalsettings.cpp does not conform to Custom style guidelines. (lines 115, 116, 117, 118, 514, 515, 516, 517, 518, 526, 527, 528, 529)
* Copyright (C) by Daniel Molkentin <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -107,8 +107,19 @@
return list;
}

void createDebugArchive(const QString &filename)
bool createDebugArchive(const QString &filename)

Check warning on line 110 in src/gui/generalsettings.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/generalsettings.cpp:110:6 [modernize-use-trailing-return-type]

use a trailing return type for this function
{
const auto fileInfo = QFileInfo(filename);
const auto dirInfo = QFileInfo(fileInfo.dir().absolutePath());
if (!dirInfo.isWritable()) {
QMessageBox::critical(
nullptr,
QObject::tr("Failed to create debug archive"),
QObject::tr("Could not create debug archive in selected location!")
);
return false;
}

const auto entries = createDebugArchiveFileList();

KZip zip(filename);
Expand All @@ -127,7 +138,9 @@
zip.prepareWriting("__nextcloud_client_buildinfo.txt", {}, {}, buildInfo.size());
zip.writeData(buildInfo, buildInfo.size());
zip.finishWriting(buildInfo.size());
return true;
}

}

namespace OCC {
Expand Down Expand Up @@ -498,13 +511,24 @@

void GeneralSettings::slotCreateDebugArchive()
{
const auto filename = QFileDialog::getSaveFileName(this, tr("Create Debug Archive"), QString(), tr("Zip Archives") + " (*.zip)");
const auto filename = QFileDialog::getSaveFileName(
this,
tr("Create Debug Archive"),
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),
tr("Zip Archives") + " (*.zip)"
);

if (filename.isEmpty()) {
return;
}

createDebugArchive(filename);
QMessageBox::information(this, tr("Debug Archive Created"), tr("Debug archive is created at %1").arg(filename));
if (createDebugArchive(filename)) {
QMessageBox::information(
this,
tr("Debug Archive Created"),
tr("Debug archive is created at %1").arg(filename)
);
}
}

void GeneralSettings::slotShowLegalNotice()
Expand Down
Loading