public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Jan Grulich <jgrulich@redhat.com>
To: git-commits@fedoraproject.org
Subject: [rpms/mediawriter] f45: Fix download completion race in write helpers
Date: Mon, 12 Oct 2026 08:36:37 GMT	[thread overview]
Message-ID: <179179419789.1.10466266448209221002.rpms-mediawriter-f69403200354@fedoraproject.org> (raw)

            A new commit has been pushed.

            Repo   : rpms/mediawriter
            Branch : f45
            Commit : f69403200354616ebff8d1019aa188316fd8da80
            Author : Jan Grulich <jgrulich@redhat.com>
            Date   : 2026-10-12T10:35:37+02:00
            Stats  : +187/-1 in 2 file(s)
            URL    : https://src.fedoraproject.org/rpms/mediawriter/c/f69403200354616ebff8d1019aa188316fd8da80?branch=f45

            Log:
            Fix download completion race in write helpers

Resolves: rhbz#2547739

---
diff --git a/mediawriter-fix-download-completion-race-in-write-helpers.patch b/mediawriter-fix-download-completion-race-in-write-helpers.patch
new file mode 100644
index 0000000..b791a36
--- /dev/null
+++ b/mediawriter-fix-download-completion-race-in-write-helpers.patch
@@ -0,0 +1,180 @@
+From 122f491387dfa88d1095bc64c40e17f10bf551b5 Mon Sep 17 00:00:00 2001
+From: Jan Grulich <jgrulich@redhat.com>
+Date: Mon, 12 Oct 2026 09:18:01 +0200
+Subject: [PATCH] Fix download completion race in write helpers - #1005
+
+Fix stalled writes after delayed authorization and prevent crashes when
+write is clicked again.
+---
+ src/app/drivemanager.cpp       | 12 ++++++++++++
+ src/helper/linux/writejob.cpp  | 12 ++++++++++--
+ src/helper/mac/writejob.cpp    | 19 +++++++++++++++++--
+ src/helper/win/writejob.cpp    | 20 ++++++++++++++++++--
+ src/lib/libwindisk/windisk.cpp |  1 +
+ 6 files changed, 58 insertions(+), 37 deletions(-)
+ delete mode 100644 src/helper/win/win.pro
+
+diff --git a/src/app/drivemanager.cpp b/src/app/drivemanager.cpp
+index 7ff95cd5..4d27fcf9 100644
+--- a/src/app/drivemanager.cpp
++++ b/src/app/drivemanager.cpp
+@@ -43,6 +43,8 @@ DriveManager *DriveManager::_self = nullptr;
+ 
+ void DriveOperationDeleter::operator()(QProcess *process)
+ {
++    process->disconnect();
++
+     if (process->state() != QProcess::NotRunning) {
+ #ifdef Q_OS_WIN
+         process->kill();
+@@ -389,6 +391,11 @@ static QString helperPath()
+ 
+ bool Drive::write(ReleaseVariant *data)
+ {
++    if (m_process) {
++        mWarning() << "Cannot start writing while a helper process still exists" << m_process.get();
++        return false;
++    }
++
+     m_image = data;
+     m_image->setErrorString(QString());
+     if (data && data->size() > 0 && size() > 0 && data->realSize() > size()) {
+@@ -449,6 +456,11 @@ void Drive::cancel()
+ 
+ void Drive::restore()
+ {
++    if (m_process) {
++        mWarning() << "Cannot start restoring while a helper process still exists" << m_process.get();
++        return;
++    }
++
+     const QString path = helperPath();
+     if (path.isEmpty()) {
+         setRestoreStatus(RESTORE_ERROR);
+diff --git a/src/helper/linux/writejob.cpp b/src/helper/linux/writejob.cpp
+index 6f1bf8e5..5fceebab 100644
+--- a/src/helper/linux/writejob.cpp
++++ b/src/helper/linux/writejob.cpp
+@@ -224,7 +224,14 @@ void WriteJob::work()
+         return;
+ 
+     if (what.endsWith(".part")) {
+-        watcher.addPath(what);
++        const bool watching = watcher.addPath(what);
++        if (!QFile::exists(what)) {
++            onFileChanged(what);
++        } else if (!watching) {
++            err << tr("Unable to watch the downloaded image.") << "\n";
++            err.flush();
++            qApp->exit(4);
++        }
+     } else {
+         if (!write(fd.fileDescriptor()))
+             return;
+@@ -235,9 +242,10 @@ void WriteJob::work()
+ 
+ void WriteJob::onFileChanged(const QString &path)
+ {
+-    if (QFile::exists(path))
++    if (!what.endsWith(".part") || QFile::exists(path))
+         return;
+ 
++    watcher.removePath(path);
+     what.replace(QRegularExpression(".part$"), "");
+ 
+     if (!QFile::exists(what)) {
+diff --git a/src/helper/mac/writejob.cpp b/src/helper/mac/writejob.cpp
+index 67653110..dbd21e22 100644
+--- a/src/helper/mac/writejob.cpp
++++ b/src/helper/mac/writejob.cpp
+@@ -59,7 +59,16 @@ WriteJob::WriteJob(const QString &what, const QString &where)
+ {
+     connect(&watcher, &QFileSystemWatcher::fileChanged, this, &WriteJob::onFileChanged);
+     if (what.endsWith(".part")) {
+-        watcher.addPath(what);
++        QTimer::singleShot(0, this, [this]() {
++            const bool watching = watcher.addPath(this->what);
++            if (!QFile::exists(this->what)) {
++                onFileChanged(this->what);
++            } else if (!watching) {
++                err << tr("Unable to watch the downloaded image.") << "\n";
++                err.flush();
++                qApp->exit(4);
++            }
++        });
+     } else {
+         QTimer::singleShot(0, this, &WriteJob::work);
+     }
+@@ -154,11 +163,17 @@ void WriteJob::work()
+ 
+ void WriteJob::onFileChanged(const QString &path)
+ {
+-    if (QFile::exists(path))
++    if (!what.endsWith(".part") || QFile::exists(path))
+         return;
+ 
++    watcher.removePath(path);
+     what.replace(QRegularExpression("[.]part$"), "");
+ 
++    if (!QFile::exists(what)) {
++        qApp->exit(4);
++        return;
++    }
++
+     work();
+ }
+ 
+diff --git a/src/helper/win/writejob.cpp b/src/helper/win/writejob.cpp
+index 3739bf9d..e5f84281 100644
+--- a/src/helper/win/writejob.cpp
++++ b/src/helper/win/writejob.cpp
+@@ -53,7 +53,16 @@ WriteJob::WriteJob(const QString &image, const QString &driveNumber, QObject *pa
+ 
+     if (m_image.endsWith(".part")) {
+         connect(&m_watcher, &QFileSystemWatcher::fileChanged, this, &WriteJob::onFileChanged);
+-        m_watcher.addPath(m_image);
++        QTimer::singleShot(0, this, [this]() {
++            const bool watching = m_watcher.addPath(m_image);
++            if (!QFile::exists(m_image)) {
++                onFileChanged(m_image);
++            } else if (!watching) {
++                m_err << tr("Unable to watch the downloaded image.") << "\n";
++                m_err.flush();
++                qApp->exit(4);
++            }
++        });
+     } else {
+         QTimer::singleShot(0, this, &WriteJob::work);
+     }
+@@ -129,11 +138,18 @@ void WriteJob::work()
+ 
+ void WriteJob::onFileChanged(const QString &path)
+ {
+-    if (QFile::exists(path))
++    if (!m_image.endsWith(".part") || QFile::exists(path))
+         return;
++
++    m_watcher.removePath(path);
+     QRegularExpression reg("[.]part$");
+     m_image = m_image.replace(reg, "");
+ 
++    if (!QFile::exists(m_image)) {
++        qApp->exit(4);
++        return;
++    }
++
+     work();
+ }
+ 
+diff --git a/src/lib/libwindisk/windisk.cpp b/src/lib/libwindisk/windisk.cpp
+index f2ecb8c8..a4c76551 100644
+--- a/src/lib/libwindisk/windisk.cpp
++++ b/src/lib/libwindisk/windisk.cpp
+@@ -23,6 +23,7 @@
+ 
+ #include <comdef.h>
+ #include <dbt.h>
++#include <share.h>
+ 
+ #include <QStandardPaths>
+ #include <QThread>

diff --git a/mediawriter.spec b/mediawriter.spec
index d453105..8cd4391 100644
--- a/mediawriter.spec
+++ b/mediawriter.spec
@@ -1,12 +1,14 @@
 Name:           mediawriter
 Version:        5.3.2
-Release:        2%{?dist}
+Release:        3%{?dist}
 Summary:        Fedora Media Writer
 
 License:        LGPL-2.0-or-later AND GPL-2.0-or-later
 URL:            https://github.com/FedoraQt/MediaWriter
 Source0:        https://github.com/FedoraQt/MediaWriter/archive/%{version}.tar.gz#/MediaWriter-%{version}.tar.gz
 
+Patch0:         mediawriter-fix-download-completion-race-in-write-helpers.patch
+
 Provides:       liveusb-creator = %{version}-%{release}
 Obsoletes:      liveusb-creator <= 3.95.4-2
 
@@ -68,6 +70,10 @@ appstream-util validate-relax --nonet %{buildroot}/%{_datadir}/metainfo/org.fedo
 %{_datadir}/icons/hicolor/512x512/apps/org.fedoraproject.MediaWriter.png
 
 %changelog
+* Mon Oct 12 2026 Jan Grulich <jgrulich@redhat.com> - 5.3.2-3
+- Fix download completion race in write helpers
+  Resolves: rhbz#2547739
+
 * Thu Jul 16 2026 Fedora Release Engineering <releng@fedoraproject.org> - 5.3.2-2
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_45_Mass_Rebuild
 

                 reply	other threads:[~2026-10-12  8:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179179419789.1.10466266448209221002.rpms-mediawriter-f69403200354@fedoraproject.org \
    --to=jgrulich@redhat.com \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox