From 906a89c16d565df3614f3da5ead2a1091a005076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Fri, 8 Dec 2017 23:55:59 +0000 Subject: [PATCH] Use ExternalCommand to copy fstab file to its final location. --- src/core/fstab.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/core/fstab.cpp b/src/core/fstab.cpp index 756a147..2a5fb69 100644 --- a/src/core/fstab.cpp +++ b/src/core/fstab.cpp @@ -18,6 +18,7 @@ *************************************************************************/ #include "core/fstab.h" +#include "util/externalcommand.h" #include @@ -179,32 +180,32 @@ static void writeEntry(QFile& output, const FstabEntry& entry) bool writeMountpoints(const FstabEntryList fstabEntries, const QString& filename) { - bool rval = true; QTemporaryFile out; out.setAutoRemove(false); if (!out.open()) { qWarning() << "could not open output file " << out.fileName(); - rval = false; + return false; } else { for (const auto &e : fstabEntries) writeEntry(out, e); out.close(); - const QString bakFilename = QStringLiteral("%1.bak").arg(filename); - QFile::remove(bakFilename); + ExternalCommand mvCmd(QStringLiteral("mv"), { filename, bakFilename } ); - if (QFile::exists(filename) && !QFile::rename(filename, bakFilename)) { - qWarning() << "could not rename " << filename << " to " << bakFilename; - rval = false; + if ( !(mvCmd.run(-1) && mvCmd.exitCode() == 0) ) { + qWarning() << "could not backup " << filename << " to " << bakFilename; + return false; } - if (rval && !QFile::rename(out.fileName(), filename)) { - qWarning() << "could not rename " << out.fileName() << " to " << filename; - rval = false; + ExternalCommand mvCmd2(QStringLiteral("mv"), { out.fileName(), filename } ); + + if ( !(mvCmd2.run(-1) && mvCmd2.exitCode() == 0) ) { + qWarning() << "could not move " << out.fileName() << " to " << filename; + return false; } } - return rval; + return true; }