[network/kdeconnect-kde] 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 e8a2b954d4a0863a1fcba145c729987b7522ed6d by Albert Vaca Cintora.
Committed on 02/08/2026 at 22:21.
Pushed by albertvaka into branch 'master'.

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

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

https://invent.kde.org/network/kdeconnect-kde/-/commit/e8a2b954d4a0863a1fcba145c729987b7522ed6d

diff --git a/plugins/share/shareplugin.cpp b/plugins/share/shareplugin.cpp
index b7416dfbb..6534e3523 100644
--- a/plugins/share/shareplugin.cpp
+++ b/plugins/share/shareplugin.cpp
@@ -120,12 +120,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());
@@ -146,8 +145,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"));
@@ -236,9 +242,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.