From c8409d741939c0af32180c731a86adcdeaba802d Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Fri, 26 Mar 2021 15:54:52 +0100 Subject: [PATCH] Linux: delay extracting .zip after mount on sandboxed systems --- downloadextractthread.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/downloadextractthread.cpp b/downloadextractthread.cpp index 399dacc..4104f5e 100644 --- a/downloadextractthread.cpp +++ b/downloadextractthread.cpp @@ -193,6 +193,25 @@ void DownloadExtractThread::extractImageRun() 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() { QString folder; @@ -228,7 +247,7 @@ void DownloadExtractThread::extractMultiFileRun() fatpartition += "p1"; else fatpartition += "1"; - args << fatpartition << folder; + args << "-t" << "vfat" << fatpartition << folder; if (QProcess::execute("mount", args) != 0) { @@ -238,6 +257,16 @@ void DownloadExtractThread::extractMultiFileRun() td.setAutoRemove(false); 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 if (folder.isEmpty())