[network/kdeconnect-kde/release/26.08] plugins/share: Fix: Received files with size 0 also get their timestamps set

Albert Vaca Cintora <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 4d3791b8954160c291c02e64969da87235e54199 by Albert Vaca Cintora.
Committed on 02/08/2026 at 22:22.
Pushed by albertvaka into branch 'release/26.08'.

Fix: Received files with size 0 also get their timestamps set

(cherry picked from commit e8a2b954d4a0863a1fcba145c729987b7522ed6d)

M  +13   -7    plugins/share/shareplugin.cpp

https://invent.kde.org/network/kdeconnect-kde/-/commit/4d3791b8954160c291c02e64969da87235e54199

diff --git a/plugins/share/shareplugin.cpp b/plugins/share/shareplugin.cpp
index 8ce9af22a..f6773d4db 100644
--- a/plugins/share/shareplugin.cpp
+++ b/plugins/share/shareplugin.cpp
@@ -119,12 +119,11 @@ void SharePlugin::receivePacket(const NetworkPacket &np)
         //         qCDebug(KDECONNECT_PLUGIN_SHARE) << "receiving file" << filename << "in" << dir << "into" << destination;
         const QString filename = cleanFilename(np.get<QString>(QStringLiteral("filename"), QString::number(QDateTime::currentMSecsSinceEpoch())));
         QUrl destination = getFileDestination(filename);
+        const qint64 dateCreated = np.get<qint64>(QStringLiteral("creationTime"), QDateTime::currentMSecsSinceEpoch());
+        const qint64 dateModified = np.get<qint64>(QStringLiteral("lastModified"), QDateTime::currentMSecsSinceEpoch());
+        const bool open = np.get<bool>(QStringLiteral("open"), false);
 
         if (np.hasPayload()) {
-            qint64 dateCreated = np.get<qint64>(QStringLiteral("creationTime"), QDateTime::currentMSecsSinceEpoch());
-            qint64 dateModified = np.get<qint64>(QStringLiteral("lastModified"), QDateTime::currentMSecsSinceEpoch());
-            const bool open = np.get<bool>(QStringLiteral("open"), false);
-
             if (!m_compositeJob) {
                 m_compositeJob = new CompositeFileTransferJob(device(), this);
                 m_compositeJob->setProperty("destUrl", destinationDir().toString());
@@ -145,8 +144,15 @@ void SharePlugin::receivePacket(const NetworkPacket &np)
             }
         } else {
             QFile file(destination.toLocalFile());
-            file.open(QIODevice::WriteOnly);
-            file.close();
+            if (file.open(QIODevice::WriteOnly)) {
+                file.close();
+                setDateCreated(destination, dateCreated);
+                setDateModified(destination, dateModified);
+                Q_EMIT shareReceived(destination.toString());
+                if (open) {
+                    QDesktopServices::openUrl(destination);
+                }
+            }
         }
     } else if (np.has(QStringLiteral("text"))) {
         QString text = np.get<QString>(QStringLiteral("text"));
@@ -226,9 +232,9 @@ void SharePlugin::finished(KJob *job, const qint64 dateCreated, const qint64 dat
 {
     FileTransferJob *ftjob = qobject_cast<FileTransferJob *>(job);
     if (ftjob && !job->error()) {
-        Q_EMIT shareReceived(ftjob->destination().toString());
         setDateCreated(ftjob->destination(), dateCreated);
         setDateModified(ftjob->destination(), dateModified);
+        Q_EMIT shareReceived(ftjob->destination().toString());
         qCDebug(KDECONNECT_PLUGIN_SHARE) << "File transfer finished." << ftjob->destination();
         if (open) {
             QDesktopServices::openUrl(ftjob->destination());
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.