From 098fdee5061d9c3bb0214250fba2d00bffb0fcd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Wed, 20 Sep 2017 21:22:53 +0100 Subject: [PATCH] fstab fixes: * Do not output # for empty inline comments. * More checks to validate fstab entry. --- src/core/fstab.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/core/fstab.cpp b/src/core/fstab.cpp index 8508576..6b88562 100644 --- a/src/core/fstab.cpp +++ b/src/core/fstab.cpp @@ -86,7 +86,7 @@ FstabEntryList readFstabEntries( const QString& fstabPath ) fstabEntries.append( {splitLine.at(0), splitLine.at(1), splitLine.at(2), splitLine.at(3), splitLine.at(4).toInt() } ); break; case 6: - fstabEntries.append( {splitLine.at(0), splitLine.at(1), splitLine.at(2), splitLine.at(3), splitLine.at(4).toInt(), splitLine.at(5).toInt(), QLatin1Char('#') + comment } ); + fstabEntries.append( {splitLine.at(0), splitLine.at(1), splitLine.at(2), splitLine.at(3), splitLine.at(4).toInt(), splitLine.at(5).toInt(), comment.isEmpty() ? QString() : QLatin1Char('#') + comment } ); break; default: fstabEntries.append( { {}, {}, {}, {}, {}, {}, QLatin1Char('#') + line } ); @@ -159,10 +159,19 @@ static void writeEntry(QFile& output, const FstabEntry& entry) return; } + QString options; + if (entry.options().size() > 0) { + options = entry.options().join(QLatin1Char(',')); + if (options.isEmpty()) + options = QStringLiteral("defaults"); + } + else + options = QStringLiteral("defaults"); + s << entry.fsSpec() << "\t" - << entry.mountPoint() << "\t" + << (entry.mountPoint().isEmpty() ? QStringLiteral("none") : entry.mountPoint()) << "\t" << entry.type() << "\t" - << (entry.options().size() > 0 ? entry.options().join(QLatin1Char(',')) : QStringLiteral("defaults")) << "\t" + << options << "\t" << entry.dumpFreq() << "\t" << entry.passNumber() << "\t" << entry.comment() << "\n";