PropagateDirectory: Set initial dir mtime to server mtime #7119
authorChristian Kamm <mail@ckamm.de>
Fri, 29 Mar 2019 09:16:09 +0000 (10:16 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:46 +0000 (10:58 +0100)
It's still not synced in any way later.

src/libsync/owncloudpropagator.cpp
test/testsyncengine.cpp

index 781ee30b7fb677c4bf6ccdb4d38b1c3e2ad3d7e1..83b067270685f2443befdd200aa680db9307005e 100644 (file)
@@ -965,6 +965,12 @@ void PropagateDirectory::slotSubJobsFinished(SyncFileItem::Status status)
             propagator()->_journal->deleteFileRecord(_item->_originalFile, true);
         }
 
+        if (_item->_instruction == CSYNC_INSTRUCTION_NEW && _item->_direction == SyncFileItem::Down) {
+            // special case for local MKDIR, set local directory mtime
+            // (it's not synced later at all, but can be nice to have it set initially)
+            FileSystem::setModTime(propagator()->getFilePath(_item->destination()), _item->_modtime);
+        }
+
         // For new directories we always want to update the etag once
         // the directory has been propagated. Otherwise the directory
         // could appear locally without being added to the database.
index f4e0ad1623b8c2158ddc005e764a7e48a679a5aa..ae1e16efc6e88b5badc9dd55264985580046ad56 100644 (file)
@@ -698,6 +698,22 @@ private slots:
         QCOMPARE(QFileInfo(fakeFolder.localPath() + conflictName).permissions(), perm);
     }
 #endif
+
+    // Check that server mtime is set on directories on initial propagation
+    void testDirectoryInitialMtime()
+    {
+        FakeFolder fakeFolder{ FileInfo{} };
+        fakeFolder.remoteModifier().mkdir("foo");
+        fakeFolder.remoteModifier().insert("foo/bar");
+        auto datetime = QDateTime::currentDateTime();
+        datetime.setSecsSinceEpoch(datetime.toSecsSinceEpoch()); // wipe ms
+        fakeFolder.remoteModifier().find("foo")->lastModified = datetime;
+
+        QVERIFY(fakeFolder.syncOnce());
+        QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
+
+        QCOMPARE(QFileInfo(fakeFolder.localPath() + "foo").lastModified(), datetime);
+    }
 };
 
 QTEST_GUILESS_MAIN(TestSyncEngine)