Ignore Hidden Files
authorOlivier Goffart <ogoffart@woboq.com>
Tue, 10 Jul 2018 14:37:59 +0000 (16:37 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:57:57 +0000 (10:57 +0100)
src/csync/csync_update.cpp
src/libsync/discovery.cpp
src/libsync/discovery.h
src/libsync/discoveryphase.h
src/libsync/syncengine.cpp

index 6edfa0b46d3f4431c7fbb6e5eb584295f0868dec..4c121503b78adb64bce0665de0a2508ef7bb3bb4 100644 (file)
@@ -784,15 +784,6 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
         continue;
     }
 
-    /* if the filename starts with a . we consider it a hidden file
-     * For windows, the hidden state is also discovered within the vio
-     * local stat function.
-     */
-    if( filename[0] == '.' ) {
-        if (filename != ".sys.admin#recall#") { /* recall file shall not be ignored (#4420) */
-            dirent->is_hidden = true;
-        }
-    }
 
 #if 0
     // Now process to have a relative path to the sync root for the local replica, or to the data root on the remote.
index 03d97dbb5449399a11cb849c7da729349d8a7332..2dec6fdac1cb52e608c898a5ac779d9e557b0e9b 100644 (file)
@@ -102,6 +102,7 @@ void ProcessDirectoryJob::start()
             i.size = dirent->size;
             i.inode = dirent->inode;
             i.isDirectory = dirent->type == ItemTypeDirectory;
+            i.isHidden = dirent->is_hidden;
             if (dirent->type != ItemTypeDirectory && dirent->type != ItemTypeFile)
                 qFatal("FIXME:  NEED TO CARE ABOUT THE OTHER STUFF ");
             _localEntries.push_back(i);
@@ -150,7 +151,15 @@ void ProcessDirectoryJob::process()
 
     for (const auto &f : entriesNames) {
         QString path = _currentFolder + f;
-        if (handleExcluded(path, (localEntriesHash.value(f).isDirectory || serverEntriesHash.value(f).isDirectory)))
+        auto localEntry = localEntriesHash.value(f);
+        auto serverEntry = serverEntriesHash.value(f);
+
+        // If the filename starts with a . we consider it a hidden file
+        // For windows, the hidden state is also discovered within the vio
+        // local stat function.
+        // Recall file shall not be ignored (#4420)
+        bool isHidden = localEntry.isHidden || (f[0] == '.' && f != QLatin1String(".sys.admin#recall#"));
+        if (handleExcluded(path, localEntry.isDirectory || serverEntry.isDirectory, isHidden))
             continue;
 
         SyncJournalFileRecord record;
@@ -158,16 +167,16 @@ void ProcessDirectoryJob::process()
             qFatal("TODO: DB ERROR HANDLING");
         }
         if (_queryServer == InBlackList || _discoveryData->isInSelectiveSyncBlackList(path)) {
-            processBlacklisted(path, localEntriesHash.value(f), record);
+            processBlacklisted(path, localEntry, record);
             continue;
         }
-        processFile(path, localEntriesHash.value(f), serverEntriesHash.value(f), record);
+        processFile(path, localEntry, serverEntry, record);
     }
 
     progress();
 }
 
-bool ProcessDirectoryJob::handleExcluded(const QString &path, bool isDirectory)
+bool ProcessDirectoryJob::handleExcluded(const QString &path, bool isDirectory, bool isHidden)
 {
     // FIXME! call directly, without char* conversion
     auto excluded = _discoveryData->_excludes->csyncTraversalMatchFun()(path.toUtf8(), isDirectory ? ItemTypeDirectory : ItemTypeFile);
@@ -181,6 +190,9 @@ bool ProcessDirectoryJob::handleExcluded(const QString &path, bool isDirectory)
             isInvalidPattern = true;
         }
     }
+    if (excluded == CSYNC_NOT_EXCLUDED && _discoveryData->_ignoreHiddenFiles && isHidden) {
+        excluded = CSYNC_FILE_EXCLUDE_HIDDEN;
+    }
 
     if (excluded == CSYNC_NOT_EXCLUDED /* FIXME && item->_type != ItemTypeSoftLink */) {
         return false;
index 3ba55155f5c617094103a3ccc7003073d71c8144..8c7b729ebd586ac4195378ae1740c895666c807a 100644 (file)
@@ -89,6 +89,7 @@ struct LocalInfo
     int64_t size = 0;
     uint64_t inode = 0;
     bool isDirectory = false;
+    bool isHidden = false;
     bool isValid() const { return !name.isNull(); }
 };
 
@@ -129,7 +130,7 @@ public:
 private:
     void process();
     // return true if the file is excluded
-    bool handleExcluded(const QString &path, bool isDirectory);
+    bool handleExcluded(const QString &path, bool isDirectory, bool isHidden);
     void processFile(const QString &, const LocalInfo &, const RemoteInfo &, const SyncJournalFileRecord &);
     void processBlacklisted(const QString &path, const LocalInfo &, const SyncJournalFileRecord &);
     void subJobFinished();
index 35973378f02b8885ca433b8a6d4fe9b178ed537c..0058e846e6cee7ad235d576404fa12db15dc5df4 100644 (file)
@@ -110,6 +110,7 @@ public:
     QStringList _selectiveSyncWhiteList;
     ExcludedFiles *_excludes;
     QString _invalidFilenamePattern; // FIXME: maybe move in ExcludedFiles
+    bool _ignoreHiddenFiles = false;
 
     bool isInSelectiveSyncBlackList(const QString &path) const;
     bool checkSelectiveSyncNewFolder(const QString &path, RemotePermissions rp);
index e564f769ea63ffe5af893727e38c472e2b20f340..31a12dac62b0928082d0e89b15fb44c482f23882 100644 (file)
@@ -882,6 +882,7 @@ void SyncEngine::slotStartDiscovery()
         invalidFilenamePattern = "[\\\\:?*\"<>|]";
     }
     ddata->_invalidFilenamePattern = invalidFilenamePattern;
+    ddata->_ignoreHiddenFiles = ignoreHiddenFiles();
 
     connect(ddata.data(), &DiscoveryPhase::folderDiscovered, this, &SyncEngine::slotFolderDiscovered);
     connect(ddata.data(), &DiscoveryPhase::newBigFolder, this, &SyncEngine::newBigFolder);