[Pkg-owncloud-commits] [owncloud-client] 60/171: Propagator: Deal with files becoming directories #4302

Sandro Knauß hefee-guest at moszumanska.debian.org
Wed Feb 17 09:36:48 UTC 2016


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to annotated tag upstream/2.1.1+dfsg
in repository owncloud-client.

commit 5cc4c03b6a505c3b777af088f472b34158126a1d
Author: Christian Kamm <mail at ckamm.de>
Date:   Tue Dec 22 11:26:07 2015 +0100

    Propagator: Deal with files becoming directories #4302
    
    This needed adjustments in reconcile, to mark the item as SYNC
    as well as additions to the LocalMkdir job.
---
 csync/src/csync_update.c           |  5 +++++
 src/libsync/owncloudpropagator.cpp |  6 ++++++
 src/libsync/propagatorjobs.cpp     | 28 +++++++++++++++++++++++++++-
 src/libsync/propagatorjobs.h       | 13 ++++++++++++-
 4 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/csync/src/csync_update.c b/csync/src/csync_update.c
index 44c9703..d166714 100644
--- a/csync/src/csync_update.c
+++ b/csync/src/csync_update.c
@@ -272,6 +272,11 @@ static int _csync_detect_update(CSYNC *ctx, const char *file,
                   (uint64_t) fs->size, (uint64_t) tmp->size, fs->remotePerm, tmp->remotePerm, tmp->has_ignored_files );
         if (ctx->current == REMOTE_REPLICA && !c_streq(fs->etag, tmp->etag)) {
             st->instruction = CSYNC_INSTRUCTION_EVAL;
+
+            // Preserve the EVAL flag later on if the type has changed.
+            if (tmp->type != fs->type)
+                st->child_modified = 1;
+
             goto out;
         }
         if (ctx->current == LOCAL_REPLICA &&
diff --git a/src/libsync/owncloudpropagator.cpp b/src/libsync/owncloudpropagator.cpp
index 478f5fa..9f86f86 100644
--- a/src/libsync/owncloudpropagator.cpp
+++ b/src/libsync/owncloudpropagator.cpp
@@ -246,6 +246,12 @@ PropagateItemJob* OwncloudPropagator::createJob(const SyncFileItemPtr &item) {
         case CSYNC_INSTRUCTION_SYNC:
         case CSYNC_INSTRUCTION_CONFLICT:
             if (item->_isDirectory) {
+                // Did a file turn into a directory?
+                if (QFileInfo(getFilePath(item->_file)).isFile()) {
+                    auto job = new PropagateLocalMkdir(this, item);
+                    job->setDeleteExistingFile(true);
+                    return job;
+                }
                 // Should we set the mtime?
                 return 0;
             }
diff --git a/src/libsync/propagatorjobs.cpp b/src/libsync/propagatorjobs.cpp
index e17ab60..30914ed 100644
--- a/src/libsync/propagatorjobs.cpp
+++ b/src/libsync/propagatorjobs.cpp
@@ -147,8 +147,29 @@ void PropagateLocalMkdir::start()
     if (_propagator->_abortRequested.fetchAndAddRelaxed(0))
         return;
 
-    QDir newDir(_propagator->_localDir + _item->_file);
+    QDir newDir(_propagator->getFilePath(_item->_file));
     QString newDirStr = QDir::toNativeSeparators(newDir.path());
+
+    // When turning something that used to be a file into a directory
+    // we need to delete the file first.
+    QFileInfo fi(newDirStr);
+    if (_deleteExistingFile && fi.exists() && fi.isFile()) {
+#ifdef Q_OS_WIN
+        // On Windows, write only files cannot be deleted.
+        if (!fi.isWritable()) {
+            FileSystem::setFileReadOnlyWeak(newDirStr, false);
+        }
+#endif
+
+        QFile f(newDirStr);
+        if (!f.remove()) {
+            done( SyncFileItem::NormalError,
+                  tr("could not delete file %1, error: %2")
+                  .arg(newDirStr, f.errorString()));
+            return;
+        }
+    }
+
     if( Utility::fsCasePreserving() && _propagator->localFileNameClash(_item->_file ) ) {
         qDebug() << "WARN: new folder to create locally already exists!";
         done( SyncFileItem::NormalError, tr("Attention, possible case sensitivity clash with %1").arg(newDirStr) );
@@ -174,6 +195,11 @@ void PropagateLocalMkdir::start()
     done(SyncFileItem::Success);
 }
 
+void PropagateLocalMkdir::setDeleteExistingFile(bool enabled)
+{
+    _deleteExistingFile = enabled;
+}
+
 void PropagateLocalRename::start()
 {
     if (_propagator->_abortRequested.fetchAndAddRelaxed(0))
diff --git a/src/libsync/propagatorjobs.h b/src/libsync/propagatorjobs.h
index 5ad01c7..2b3b9a4 100644
--- a/src/libsync/propagatorjobs.h
+++ b/src/libsync/propagatorjobs.h
@@ -54,9 +54,20 @@ private:
 class PropagateLocalMkdir : public PropagateItemJob {
     Q_OBJECT
 public:
-    PropagateLocalMkdir (OwncloudPropagator* propagator,const SyncFileItemPtr& item)  : PropagateItemJob(propagator, item) {}
+    PropagateLocalMkdir (OwncloudPropagator* propagator,const SyncFileItemPtr& item)
+        : PropagateItemJob(propagator, item), _deleteExistingFile(false) {}
     void start() Q_DECL_OVERRIDE;
 
+    /**
+     * Whether an existing file with the same name may be deleted before
+     * creating the directory.
+     *
+     * Default: false.
+     */
+    void setDeleteExistingFile(bool enabled);
+
+private:
+    bool _deleteExistingFile;
 };
 
 /**

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list