Merge remote-tracking branch 'origin/2.3'
authorChristian Kamm <mail@ckamm.de>
Thu, 22 Jun 2017 12:06:31 +0000 (14:06 +0200)
committerChristian Kamm <mail@ckamm.de>
Thu, 22 Jun 2017 12:06:31 +0000 (14:06 +0200)
1  2 
src/cmd/cmd.cpp
src/gui/folder.cpp
src/gui/folderman.cpp
src/gui/folderwatcher_linux.cpp
src/gui/ignorelisteditor.cpp
src/libsync/syncjournaldb.cpp
src/libsync/syncjournaldb.h

diff --cc src/cmd/cmd.cpp
Simple merge
Simple merge
index 6c9fd71cfca8e52b052723f0c8cbc222ee3d9c77,cb0fa90b532c69768408750c839efa7b4611bd63..ce5376b2ba713da945116b8bcb5d8a35ce815263
@@@ -236,14 -232,25 +236,25 @@@ int FolderMan::setupFolders(
  
  void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account, bool backwardsCompatible)
  {
 -    foreach (const autofolderAlias, settings.childGroups()) {
 +    foreach (const auto &folderAlias, settings.childGroups()) {
          FolderDefinition folderDefinition;
          if (FolderDefinition::load(settings, folderAlias, &folderDefinition)) {
+             auto defaultJournalPath = folderDefinition.defaultJournalPath(account->account());
              // Migration: Old settings don't have journalPath
              if (folderDefinition.journalPath.isEmpty()) {
-                 folderDefinition.journalPath = folderDefinition.defaultJournalPath(account->account());
+                 folderDefinition.journalPath = defaultJournalPath;
+             }
+             // Migration: ._ files sometimes don't work
+             // So if the configured journalPath is the default one ("._sync_*.db")
+             // but the current default doesn't have the underscore, switch to the
+             // new default. See SyncJournalDb::makeDbName().
+             if (folderDefinition.journalPath.startsWith("._sync_")
+                 && defaultJournalPath.startsWith(".sync_")) {
+                 folderDefinition.journalPath = defaultJournalPath;
              }
-             folderDefinition.defaultJournalPath(account->account());
              // Migration: If an old db is found, move it to the new name.
              if (backwardsCompatible) {
                  SyncJournalDb::maybeMigrateDb(folderDefinition.localPath, folderDefinition.absoluteJournalPath());
index b505b8dd0b084bafd3edc8a8b1a11c3ff8c586d2,d647f659599fd23f8a9a4ec3a02fbff937ea7e91..5d2d4e7fd451ea049a765683ec6745a3c47df371
@@@ -160,9 -168,15 +160,12 @@@ void FolderWatcherPrivate::slotReceived
          // Fire event for the path that was changed.
          if (event->len > 0 && event->wd > -1) {
              QByteArray fileName(event->name);
-             if (fileName.startsWith("._sync_") || fileName.startsWith(".csync_journal.db") || fileName.startsWith(".owncloudsync.log")) {
 -            // qDebug() << Q_FUNC_INFO << event->name;
 -            if (fileName.startsWith("._sync_") ||
 -                    fileName.startsWith(".csync_journal.db") ||
 -                    fileName.startsWith(".owncloudsync.log") ||
 -                    fileName.startsWith(".sync_")) {
 -                // qDebug() << "ignore journal";
++            if (fileName.startsWith("._sync_")
++                || fileName.startsWith(".csync_journal.db")
++                || fileName.startsWith(".owncloudsync.log")
++                || fileName.startsWith(".sync_")) {
              } else {
                  const QString p = _watches[event->wd] + '/' + fileName;
 -                //qDebug() << "found a change in " << p;
                  _parent->changeDetected(p);
              }
          }
index 83fd39ffd9a7ca2cfcbb7b2a7905c35cc97e07a8,1d124d1d6a5e4937e8da4d9b42004b9bbd2f6176..64c39c48fe38c121987dea03f07792fe9e152d54
@@@ -46,8 -46,11 +46,11 @@@ IgnoreListEditor::IgnoreListEditor(QWid
      ConfigFile cfgFile;
      readOnlyTooltip = tr("This entry is provided by the system at '%1' "
                           "and cannot be modified in this view.")
 -            .arg(QDir::toNativeSeparators(cfgFile.excludeFile(ConfigFile::SystemScope)));
 +                          .arg(QDir::toNativeSeparators(cfgFile.excludeFile(ConfigFile::SystemScope)));
  
+     addPattern(".csync_journal.db*", /*deletable=*/false, /*readonly=*/true);
+     addPattern("._sync_*.db*", /*deletable=*/false, /*readonly=*/true);
+     addPattern(".sync_*.db*", /*deletable=*/false, /*readonly=*/true);
      readIgnoreFile(cfgFile.excludeFile(ConfigFile::SystemScope), true);
      readIgnoreFile(cfgFile.excludeFile(ConfigFile::UserScope), false);
  
index 3406c7e357219e651a26f3e53a7c380f59a70ad1,c6c4a9cd5bb1cdc34c7bd3cb286c1a88317a0af5..b6bcff4d0d48cd81e5efea57a8919788d78fab47
   */
  
  #include <QFile>
 +#include <QLoggingCategory>
  #include <QStringList>
 -#include <QDebug>
  #include <QElapsedTimer>
  #include <QUrl>
+ #include <QDir>
  
  #include "ownsql.h"
  
  
  namespace OCC {
  
 -SyncJournalDb::SyncJournalDb(const QString& dbFilePath, QObject *parent) :
 -    QObject(parent),
 -    _dbFile(dbFilePath),
 -    _transaction(0)
 -{
 +Q_LOGGING_CATEGORY(lcDb, "sync.database", QtInfoMsg)
  
 +SyncJournalDb::SyncJournalDb(const QString &dbFilePath, QObject *parent)
 +    : QObject(parent)
 +    , _dbFile(dbFilePath)
 +    , _transaction(0)
 +{
  }
  
- QString SyncJournalDb::makeDbName(const QUrl &remoteUrl,
 -QString SyncJournalDb::makeDbName(const QString& localPath,
 -                                  const QUrl& remoteUrl,
 -                                  const QString& remotePath,
 -                                  const QString& user)
++QString SyncJournalDb::makeDbName(const QString &localPath,
++    const QUrl &remoteUrl,
 +    const QString &remotePath,
 +    const QString &user)
  {
      QString journalPath = QLatin1String("._sync_");
  
 -    QString key = QString::fromUtf8("%1@%2:%3").arg(
 -            user,
 -            remoteUrl.toString(),
 -            remotePath);
 +    QString key = QString::fromUtf8("%1@%2:%3").arg(user, remoteUrl.toString(), remotePath);
  
      QByteArray ba = QCryptographicHash::hash(key.toUtf8(), QCryptographicHash::Md5);
 -    journalPath.append( ba.left(6).toHex() );
 +    journalPath.append(ba.left(6).toHex());
      journalPath.append(".db");
  
 -        qDebug() << "Using alternate database path" << alternateJournalPath;
+     // If the journal doesn't exist and we can't create a file
+     // at that location, try again with a journal name that doesn't
+     // have the ._ prefix.
+     //
+     // The disadvantage of that filename is that it will only be ignored
+     // by client versions >2.3.2.
+     //
+     // See #5633: "._*" is often forbidden on samba shared folders.
+     // If it exists already, the path is clearly usable
+     QFile file(QDir(localPath).filePath(journalPath));
+     if (file.exists()) {
+         return journalPath;
+     }
+     // Try to create a file there
+     if (file.open(QIODevice::ReadWrite)) {
+         // Ok, all good.
+         file.close();
+         file.remove();
+         return journalPath;
+     }
+     // Can we create it if we drop the underscore?
+     QString alternateJournalPath = journalPath.mid(2).prepend(".");
+     QFile file2(QDir(localPath).filePath(alternateJournalPath));
+     if (file2.open(QIODevice::ReadWrite)) {
+         // The alternative worked, use it
 -    qDebug() << "Could not find a writable database path" << file.fileName();
++        qCInfo(lcDb) << "Using alternate database path" << alternateJournalPath;
+         file2.close();
+         file2.remove();
+         return alternateJournalPath;
+     }
+     // Neither worked, just keep the original and throw errors later
++    qCWarning(lcDb) << "Could not find a writable database path" << file.fileName();
      return journalPath;
  }
  
index f51d5b9c1e11b08fe3b29de6c470af5e07427c6f,37df8c81eae4b976897881714b1eda0769423deb..3f6c89e43553ccc06ac65e58b35ec4e0fd70e3c8
@@@ -41,12 -41,13 +41,13 @@@ public
      virtual ~SyncJournalDb();
  
      /// Create a journal path for a specific configuration
-     static QString makeDbName(const QUrl &remoteUrl,
 -    static QString makeDbName(const QString& localPath,
 -                              const QUrl& remoteUrl,
 -                              const QString& remotePath,
 -                              const QString& user);
++    static QString makeDbName(const QString &localPath,
++        const QUrl &remoteUrl,
 +        const QString &remotePath,
 +        const QString &user);
  
      /// Migrate a csync_journal to the new path, if necessary. Returns false on error
 -    static bool maybeMigrateDb(const QString& localPath, const QString& absoluteJournalPath);
 +    static bool maybeMigrateDb(const QString &localPath, const QString &absoluteJournalPath);
  
      // to verify that the record could be queried successfully check
      // with SyncJournalFileRecord::isValid()