Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Image customization: search all mountpoints for config.txt
Search all mountpoints associated with the target drive for FAT partition that has config.txt Ref: #171
- Loading branch information
Showing
1 changed file
with
29 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -807,6 +807,7 @@ void DownloadThread::setImageCustomization(const QByteArray &config, const QByte | |
bool DownloadThread::_customizeImage() | ||
{ | ||
QString folder; | ||
std::vector<std::string> mountpoints; | ||
QByteArray devlower = _filename.toLower(); | ||
|
||
emit preparationStatusUpdate(tr("Waiting for FAT partition to be mounted")); | ||
|
@@ -832,14 +833,14 @@ bool DownloadThread::_customizeImage() | |
{ | ||
if (QByteArray::fromStdString(i.device).toLower() == devlower && i.mountpoints.size()) | ||
{ | ||
folder = QByteArray::fromStdString(i.mountpoints.front()); | ||
mountpoints = i.mountpoints; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
#ifdef Q_OS_WIN | ||
if (folder.isEmpty() && !_nr.isEmpty()) { | ||
if (mountpoints.empty() && !_nr.isEmpty()) { | ||
qDebug() << "Windows did not assign drive letter automatically. Ask diskpart to do so manually."; | ||
proc.start("diskpart"); | ||
proc.waitForStarted(); | ||
|
@@ -855,7 +856,7 @@ bool DownloadThread::_customizeImage() | |
{ | ||
if (QByteArray::fromStdString(i.device).toLower() == devlower && i.mountpoints.size()) | ||
{ | ||
folder = QByteArray::fromStdString(i.mountpoints.front()); | ||
mountpoints = i.mountpoints; | ||
break; | ||
} | ||
} | ||
|
@@ -865,7 +866,7 @@ bool DownloadThread::_customizeImage() | |
#ifdef Q_OS_LINUX | ||
bool manualmount = false; | ||
|
||
if (folder.isEmpty()) | ||
if (mountpoints.empty()) | ||
{ | ||
/* Manually mount folder */ | ||
manualmount = true; | ||
|
@@ -880,16 +881,16 @@ bool DownloadThread::_customizeImage() | |
/* Not running as root, try to outsource mounting to udisks2 */ | ||
#ifndef QT_NO_DBUS | ||
UDisks2Api udisks2; | ||
folder = udisks2.mountDevice(fatpartition); | ||
mountpoints.push_back(udisks2.mountDevice(fatpartition).toStdString()); | ||
#endif | ||
} | ||
else | ||
{ | ||
/* Running as root, attempt running mount directly */ | ||
QTemporaryDir td; | ||
QStringList args; | ||
folder = td.path(); | ||
args << "-t" << "vfat" << fatpartition << folder; | ||
mountpoints.push_back(td.path().toStdString()); | ||
args << "-t" << "vfat" << fatpartition << td.path(); | ||
|
||
if (QProcess::execute("mount", args) != 0) | ||
{ | ||
|
@@ -901,7 +902,7 @@ bool DownloadThread::_customizeImage() | |
} | ||
#endif | ||
|
||
if (folder.isEmpty()) | ||
if (mountpoints.empty()) | ||
{ | ||
// | ||
qDebug() << "drive info. searching for:" << devlower; | ||
|
@@ -921,15 +922,32 @@ bool DownloadThread::_customizeImage() | |
|
||
/* Some operating system take longer to complete mounting FAT32 | ||
wait up to 3 seconds for config.txt file to appear */ | ||
QString configFilename = folder+"/config.txt"; | ||
QString configFilename; | ||
bool foundFile = false; | ||
|
||
for (int tries = 0; tries < 3; tries++) | ||
{ | ||
if (QFile::exists(configFilename)) | ||
/* Search all mountpoints, as on some systems FAT partition | ||
may not be first volume */ | ||
for (auto mp : mountpoints) | ||
{ | ||
folder = QString::fromStdString(mp); | ||
if (!folder.isEmpty() && folder.back() == '\\') | ||
folder.chop(1); | ||
configFilename = folder+"/config.txt"; | ||
|
||
if (QFile::exists(configFilename)) | ||
{ | ||
foundFile = true; | ||
break; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
maxnet
Author
Collaborator
|
||
} | ||
} | ||
if (foundFile) | ||
break; | ||
QThread::sleep(1); | ||
} | ||
|
||
if (!QFile::exists(configFilename)) | ||
if (!foundFile) | ||
{ | ||
emit error(tr("Unable to customize. File '%1' does not exist.").arg(configFilename)); | ||
return false; | ||
|
It may be too much of a rare edge-case to worry about, but what if the user has two drives plugged in that both contain a
config.txt
file?