Discovery: Fix detection of hidden files.
authorKlaas Freitag <freitag@owncloud.com>
Mon, 26 Oct 2015 13:24:05 +0000 (14:24 +0100)
committerKlaas Freitag <freitag@owncloud.com>
Mon, 26 Oct 2015 13:24:05 +0000 (14:24 +0100)
In the discovery phase we want to detect that dot-files are hidden
on Linux and Mac.

This fixes strange behaviour seen in issue #3980

csync/src/csync_update.c
src/libsync/discoveryphase.cpp

index 99570c2320bb8b5bc738dc43f4aa72e9dc17c86a..49546d52b1076194d18e7eb909e5d7ca2e181df3 100644 (file)
@@ -688,8 +688,8 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
     }
 
     /* skip "." and ".." */
-    if (d_name[0] == '.' && (d_name[1] == '\0'
-          || (d_name[1] == '.' && d_name[2] == '\0'))) {
+    if ( (d_name[0] == '.' && d_name[1] == '\0')
+          || (d_name[0] == '.' && d_name[1] == '.' && d_name[2] == '\0')) {
       csync_vio_file_stat_destroy(dirent);
       dirent = NULL;
       continue;
@@ -748,6 +748,16 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
         res = 0;
     }
 
+    /* for non windows platforms, detect if the filename starts with a .
+     * and if so, it's a hidden file. For windows, the hidden state is
+     * discovered within the vio local stat function.
+     */
+#ifndef _WIN32
+    if( d_name[0] == '.' ) {
+        fs->flags |= CSYNC_VIO_FILE_FLAGS_HIDDEN;
+    }
+#endif
+
     if( res == 0) {
       switch (fs->type) {
         case CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK:
index dcf2500ae1a7c4dcaffe6dd3559dd28efd855a3d..36be74d39970d125033aba70e7af87a54e7e40cc 100644 (file)
@@ -317,7 +317,13 @@ void DiscoverySingleDirectoryJob::directoryListingIteratedSlot(QString file,QMap
         if (!file_stat->etag || strlen(file_stat->etag) == 0) {
             qDebug() << "WARNING: etag of" << file_stat->name << "is" << file_stat->etag << " This must not happen.";
         }
-        if( file.startsWith(QChar('.')) ) {
+
+        QStringRef fileRef(&file);
+        int slashPos = file.lastIndexOf(QLatin1Char('/'));
+        if( slashPos > -1 ) {
+            fileRef = fileRef.mid(slashPos+1);
+        }
+        if( fileRef.startsWith(QChar('.')) ) {
             file_stat->flags = CSYNC_VIO_FILE_FLAGS_HIDDEN;
         }
         //qDebug() << "!!!!" << file_stat << file_stat->name << file_stat->file_id << map.count();