Linux: delay extracting .zip after mount on sandboxed systems

This commit is contained in:
Floris Bos 2021-03-26 15:54:52 +01:00
parent f682c3a7dd
commit c8409d7419

View file

@ -193,6 +193,25 @@ void DownloadExtractThread::extractImageRun()
archive_read_free(a); archive_read_free(a);
} }
#ifdef Q_OS_LINUX
/* Returns true if folder lives on a different device than parent directory */
inline bool isMountPoint(const QString &folder)
{
struct stat statFolder, statParent;
QFileInfo fi(folder);
QByteArray folderAscii = folder.toLatin1();
QByteArray parentDir = fi.dir().path().toLatin1();
if ( ::stat(folderAscii.constData(), &statFolder) == -1
|| ::stat(parentDir.constData(), &statParent) == -1)
{
return false;
}
return (statFolder.st_dev != statParent.st_dev);
}
#endif
void DownloadExtractThread::extractMultiFileRun() void DownloadExtractThread::extractMultiFileRun()
{ {
QString folder; QString folder;
@ -228,7 +247,7 @@ void DownloadExtractThread::extractMultiFileRun()
fatpartition += "p1"; fatpartition += "p1";
else else
fatpartition += "1"; fatpartition += "1";
args << fatpartition << folder; args << "-t" << "vfat" << fatpartition << folder;
if (QProcess::execute("mount", args) != 0) if (QProcess::execute("mount", args) != 0)
{ {
@ -238,6 +257,16 @@ void DownloadExtractThread::extractMultiFileRun()
td.setAutoRemove(false); td.setAutoRemove(false);
manualmount = true; manualmount = true;
} }
/* When run under some container environments -even when udisks2 said
it completed mounting the fs- we may have to wait a bit more
until mountpoint is available in sandbox which lags behind */
for (int tries=0; tries<3; tries++)
{
if (isMountPoint(folder))
break;
QThread::sleep(1);
}
#endif #endif
if (folder.isEmpty()) if (folder.isEmpty())