Use ExternalCommand to copy fstab file to its final location.
This commit is contained in:
parent
d2f13ff4cc
commit
906a89c16d
|
@ -18,6 +18,7 @@
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
#include "core/fstab.h"
|
#include "core/fstab.h"
|
||||||
|
#include "util/externalcommand.h"
|
||||||
|
|
||||||
#include <blkid/blkid.h>
|
#include <blkid/blkid.h>
|
||||||
|
|
||||||
|
@ -179,32 +180,32 @@ static void writeEntry(QFile& output, const FstabEntry& entry)
|
||||||
|
|
||||||
bool writeMountpoints(const FstabEntryList fstabEntries, const QString& filename)
|
bool writeMountpoints(const FstabEntryList fstabEntries, const QString& filename)
|
||||||
{
|
{
|
||||||
bool rval = true;
|
|
||||||
QTemporaryFile out;
|
QTemporaryFile out;
|
||||||
out.setAutoRemove(false);
|
out.setAutoRemove(false);
|
||||||
|
|
||||||
if (!out.open()) {
|
if (!out.open()) {
|
||||||
qWarning() << "could not open output file " << out.fileName();
|
qWarning() << "could not open output file " << out.fileName();
|
||||||
rval = false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
for (const auto &e : fstabEntries)
|
for (const auto &e : fstabEntries)
|
||||||
writeEntry(out, e);
|
writeEntry(out, e);
|
||||||
|
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
const QString bakFilename = QStringLiteral("%1.bak").arg(filename);
|
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)) {
|
if ( !(mvCmd.run(-1) && mvCmd.exitCode() == 0) ) {
|
||||||
qWarning() << "could not rename " << filename << " to " << bakFilename;
|
qWarning() << "could not backup " << filename << " to " << bakFilename;
|
||||||
rval = false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rval && !QFile::rename(out.fileName(), filename)) {
|
ExternalCommand mvCmd2(QStringLiteral("mv"), { out.fileName(), filename } );
|
||||||
qWarning() << "could not rename " << out.fileName() << " to " << filename;
|
|
||||||
rval = false;
|
if ( !(mvCmd2.run(-1) && mvCmd2.exitCode() == 0) ) {
|
||||||
|
qWarning() << "could not move " << out.fileName() << " to " << filename;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rval;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue