summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/createdesktopentryoperation.cpp
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@theqtcompany.com>2014-11-28 17:10:13 +0100
committerKai Koehne <kai.koehne@theqtcompany.com>2014-12-01 14:40:24 +0100
commitadae71dcc66a86904da7feb4a166012bfa14f5df (patch)
tree6181e923f8cceb11b18dedf0857046e332bbd87d /src/libs/installer/createdesktopentryoperation.cpp
parent12399b1b97e05626087cd2ebf673725d363a0a54 (diff)
Clean up CreateDesktopEntry operation
We can't delay the deletion of the file if we then try to replace it with the backup file/write to it. In addition, since we're on Unix, the deletion of the file can only fail if we don't have sufficient rights, and delaying the deletion until a 'reboot' doesn't fix this. Also, don't treat any errors in the undo step as errors that should show up in the UI: There are lots of reasons people might clean up their settings. Change-Id: I2e85f94e4fa427e0911ffab3a0111e4fb058ff1a Reviewed-by: Niels Weber <niels.weber@theqtcompany.com>
Diffstat (limited to 'src/libs/installer/createdesktopentryoperation.cpp')
-rw-r--r--src/libs/installer/createdesktopentryoperation.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/libs/installer/createdesktopentryoperation.cpp b/src/libs/installer/createdesktopentryoperation.cpp
index e9d1ebadf..168dcba01 100644
--- a/src/libs/installer/createdesktopentryoperation.cpp
+++ b/src/libs/installer/createdesktopentryoperation.cpp
@@ -109,7 +109,9 @@ CreateDesktopEntryOperation::~CreateDesktopEntryOperation()
void CreateDesktopEntryOperation::backup()
{
const QString filename = absoluteFileName();
- if (!QFile::exists(filename))
+ QFile file(filename);
+
+ if (!file.exists())
return;
try {
@@ -119,8 +121,8 @@ void CreateDesktopEntryOperation::backup()
return;
}
- if (!QFile::copy(filename, value(QLatin1String("backupOfExistingDesktopEntry")).toString()))
- setErrorString(tr("Could not backup file %1").arg(filename));
+ if (!file.copy(value(QLatin1String("backupOfExistingDesktopEntry")).toString()))
+ setErrorString(tr("Could not backup file %1: %2").arg(filename, file.errorString()));
}
bool CreateDesktopEntryOperation::performOperation()
@@ -136,13 +138,13 @@ bool CreateDesktopEntryOperation::performOperation()
const QString filename = absoluteFileName();
const QString &values = args[1];
- if (QFile::exists(filename) && !deleteFileNowOrLater(filename)) {
+ QFile file(filename);
+ if (file.exists() && !file.remove()) {
setError(UserDefinedError);
setErrorString(tr("Failed to overwrite %1").arg(filename));
return false;
}
- QFile file(filename);
if(!file.open(QIODevice::WriteOnly)) {
setError(UserDefinedError);
setErrorString(tr("Could not write Desktop Entry at %1").arg(filename));
@@ -169,20 +171,27 @@ bool CreateDesktopEntryOperation::undoOperation()
const QString filename = absoluteFileName();
// first remove the link
- if (!deleteFileNowOrLater(filename)) {
- setErrorString(tr("Could not delete file %1").arg(filename));
- return false;
+ QFile file(filename);
+ if (file.exists() && !file.remove()) {
+ qWarning() << "Could not delete file" << filename << file.errorString();
+ return true;
}
if (!hasValue(QLatin1String("backupOfExistingDesktopEntry")))
return true;
- const QString backupOfExistingDesktopEntry = value(QLatin1String("backupOfExistingDesktopEntry")).toString();
- const bool success = QFile::copy(backupOfExistingDesktopEntry, filename)
- && deleteFileNowOrLater(backupOfExistingDesktopEntry);
- if (!success)
- setErrorString(tr("Could not restore backup file into %1").arg(filename));
- return success;
+ QFile backupFile(value(QLatin1String("backupOfExistingDesktopEntry")).toString());
+ if (!backupFile.exists()) {
+ // do not treat this as a real error: The backup file might have been just nuked by the user.
+ qWarning() << "Could not restore original desktop entry at" << filename
+ << ": Backup file" << backupFile.fileName() << "does not exist anymore.";
+ return true;
+ }
+
+ if (!backupFile.rename(filename))
+ qWarning() << "Could not restore the file" << filename << ":" << backupFile.errorString();
+
+ return true;
}
bool CreateDesktopEntryOperation::testOperation()