Browse Source

g
Basic implementation of a CSyncFolder

Still waiting for Jann's patches for conflictcopy to hit a stable
release to make it the default.

Duncan Mac-Vicar P 15 years ago
parent
commit
3ce5932bbd

+ 6 - 0
CMakeLists.txt

@@ -1,9 +1,15 @@
 cmake_minimum_required(VERSION 2.8)
 cmake_minimum_required(VERSION 2.8)
 project(mirall)
 project(mirall)
 set(PACKAGE "mirall")
 set(PACKAGE "mirall")
+set( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules )
 include(${CMAKE_SOURCE_DIR}/VERSION.cmake)
 include(${CMAKE_SOURCE_DIR}/VERSION.cmake)
 
 
 find_package(Qt4 4.4.3 COMPONENTS QtCore QtGui QtXml QtNetwork QtTest REQUIRED )
 find_package(Qt4 4.4.3 COMPONENTS QtCore QtGui QtXml QtNetwork QtTest REQUIRED )
+find_package(Csync)
+
+if(CSYNC_FOUND)
+  add_definitions(-DWITH_CSYNC)
+endif(CSYNC_FOUND)
 
 
 macro(add_tests)
 macro(add_tests)
 foreach( loop_var ${ARGV} )
 foreach( loop_var ${ARGV} )

+ 16 - 0
cmake/modules/FindCsync.cmake

@@ -0,0 +1,16 @@
+
+FIND_LIBRARY(CSYNC_LIBRARY NAMES csync)
+FIND_PATH(CSYNC_INCLUDE_PATH csync.h
+    HINTS "/usr/include/csync")
+
+SET(CSYNC_INCLUDE_DIR ${CSYNC_INCLUDE_PATH})
+
+# handle the QUIETLY and REQUIRED arguments and set CSYNC_FOUND to TRUE if
+# all listed variables are TRUE
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Csync DEFAULT_MSG
+  CSYNC_LIBRARY CSYNC_INCLUDE_PATH)
+
+MARK_AS_ADVANCED(
+  CSYNC_INCLUDE_PATH
+  CSYNC_LIBRARY)

+ 10 - 0
src/CMakeLists.txt

@@ -21,6 +21,13 @@ mirall/networklocation.cpp
 mirall/temporarydir.cpp
 mirall/temporarydir.cpp
 mirall/unisonfolder.cpp
 mirall/unisonfolder.cpp
 )
 )
+if(CSYNC_FOUND)
+  set(mirall_SRCS
+    ${mirall_SRCS}
+    mirall/csyncfolder.cpp
+  )
+  include_directories(${CSYNC_INCLUDE_DIR})
+endif(CSYNC_FOUND)
 qt4_automoc(${mirall_SRCS})
 qt4_automoc(${mirall_SRCS})
 
 
 
 
@@ -29,4 +36,7 @@ add_library(mirall_static STATIC ${mirall_SRCS} ${mirall_UI_SRCS})
 add_executable(mirall main.cpp)
 add_executable(mirall main.cpp)
 target_link_libraries(mirall mirall_static)
 target_link_libraries(mirall mirall_static)
 target_link_libraries(mirall ${QT_LIBRARIES})
 target_link_libraries(mirall ${QT_LIBRARIES})
+if(CSYNC_FOUND)
+  target_link_libraries(mirall ${CSYNC_LIBRARY})
+endif(CSYNC_FOUND)
 
 

+ 13 - 1
src/mirall/application.cpp

@@ -28,6 +28,9 @@
 #include "mirall/folderwizard.h"
 #include "mirall/folderwizard.h"
 #include "mirall/networklocation.h"
 #include "mirall/networklocation.h"
 #include "mirall/unisonfolder.h"
 #include "mirall/unisonfolder.h"
+#ifdef WITH_CSYNC
+#include "mirall/csyncfolder.h"
+#endif
 #include "mirall/inotify.h"
 #include "mirall/inotify.h"
 
 
 namespace Mirall {
 namespace Mirall {
@@ -195,12 +198,21 @@ void Application::setupFolderFromConfigFile(const QString &file) {
     QVariant backend = settings.value("folder/backend");
     QVariant backend = settings.value("folder/backend");
     if (!backend.isNull()) {
     if (!backend.isNull()) {
         if (backend.toString() == "unison") {
         if (backend.toString() == "unison") {
-
             folder = new UnisonFolder(file,
             folder = new UnisonFolder(file,
                                       path.toString(),
                                       path.toString(),
                                       settings.value("backend:unison/secondPath").toString(),
                                       settings.value("backend:unison/secondPath").toString(),
                                       this);
                                       this);
         }
         }
+        else if (backend.toString() == "csync") {
+#ifdef WITH_CSYNC
+            folder = new CSyncFolder(file,
+                                     path.toString(),
+                                     settings.value("backend:csync/secondPath").toString(),
+                                     this);
+#else
+            qCritical() << "* csync suport not enabled!! ignoring:" << file;
+#endif
+        }
         else {
         else {
             qWarning() << "unknown backend" << backend;
             qWarning() << "unknown backend" << backend;
             return;
             return;

+ 125 - 0
src/mirall/csyncfolder.cpp

@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include <QDebug>
+#include <QDir>
+#include <QMutexLocker>
+#include <QThread>
+#include <QStringList>
+#include <QTextStream>
+
+#include "csync.h"
+
+#include "mirall/csyncfolder.h"
+
+namespace Mirall {
+
+CSyncThread::CSyncThread(const QString &source, const QString &target)
+    : _source(source)
+    , _target(target)
+{
+
+}
+
+CSyncThread::~CSyncThread()
+{
+
+}
+
+void CSyncThread::run()
+{
+    CSYNC *csync;
+
+    if ( csync_create(&csync,
+                      _source.toLocal8Bit().data(),
+                      _target.toLocal8Bit().data()) != 0) {
+        // handle error
+        qCritical() << "csync_create error";
+        return;
+    }
+
+    if (csync_init(csync) != 0) {
+        qCritical() << "csync_init error";
+        return;
+    }
+
+    if (csync_update(csync) != 0) {
+        qCritical() << "csync_update error";
+        return;
+    }
+
+    if (csync_reconcile(csync) != 0) {
+        qCritical() << "csync_reconcile error";
+        return;
+    }
+
+    if (csync_propagate(csync) != 0) {
+        qCritical() << "csync_propagate error";
+        return;
+    }
+
+    if (csync_destroy(csync) != 0) {
+        qCritical() << "csync_destroy error";
+        return;
+    }
+}
+
+CSyncFolder::CSyncFolder(const QString &alias,
+                         const QString &path,
+                         const QString &secondPath,
+                         QObject *parent)
+      : Folder(alias, path, parent)
+      , _secondPath(secondPath)
+{
+}
+
+CSyncFolder::~CSyncFolder()
+{
+}
+
+bool CSyncFolder::isBusy() const
+{
+    return false;
+}
+
+QString CSyncFolder::secondPath() const
+{
+    return _secondPath;
+}
+
+void CSyncFolder::startSync(const QStringList &pathList)
+{
+    //QMutexLocker locker(&_syncMutex);
+    CSyncThread *csync = new CSyncThread(path(), secondPath());
+    QObject::connect(csync, SIGNAL(started()), SLOT(slotCSyncStarted()));
+    QObject::connect(csync, SIGNAL(finished()), SLOT(slotCSyncFinished()));
+    csync->start();
+}
+
+void CSyncFolder::slotCSyncStarted()
+{
+    qDebug() << "* csync thread started";
+    emit syncStarted();
+}
+
+void CSyncFolder::slotCSyncFinished()
+{
+    qDebug() << "* csync thread finished";
+    // TODO delete thread
+    emit syncFinished();
+}
+
+} // ns
+
+#include "csyncfolder.moc"

+ 61 - 0
src/mirall/csyncfolder.h

@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#ifndef MIRALL_CSYNCFOLDER_H
+#define MIRALL_CSYNCFOLDER_H
+
+#include <QMutex>
+#include <QThread>
+#include <QStringList>
+
+#include "mirall/folder.h"
+
+class QProcess;
+
+namespace Mirall {
+
+class CSyncThread : public QThread
+{
+public:
+    CSyncThread(const QString &source, const QString &target);
+    ~CSyncThread();
+
+    virtual void run();
+
+private:
+    QString _source;
+    QString _target;
+};
+
+class CSyncFolder : public Folder
+{
+    Q_OBJECT
+public:
+  CSyncFolder(const QString &alias,
+               const QString &path,
+               const QString &secondPath, QObject *parent = 0L);
+    virtual ~CSyncFolder();
+    QString secondPath() const;
+    virtual void startSync(const QStringList &pathList);
+    virtual bool isBusy() const;
+protected slots:
+    void slotCSyncStarted();
+    void slotCSyncFinished();
+private:
+    QString _secondPath;
+};
+
+}
+
+#endif

+ 1 - 0
src/mirall/folderwatcher.cpp

@@ -46,6 +46,7 @@ FolderWatcher::FolderWatcher(const QString &root, QObject *parent)
 {
 {
     // this is not the best place for this
     // this is not the best place for this
     addIgnore("/**/.unison*");
     addIgnore("/**/.unison*");
+    addIgnore("*csync_timediff.ctmp*");
 
 
     _processTimer->setSingleShot(true);
     _processTimer->setSingleShot(true);
     QObject::connect(_processTimer, SIGNAL(timeout()), this, SLOT(slotProcessTimerTimeout()));
     QObject::connect(_processTimer, SIGNAL(timeout()), this, SLOT(slotProcessTimerTimeout()));