[Pkg-owncloud-commits] [owncloud-client] 47/333: move the file system helpers in their own file
Sandro Knauß
hefee-guest at moszumanska.debian.org
Thu Apr 17 23:16:32 UTC 2014
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit f7419094f3215a1eace2a49496b200b1e5e0edb1
Author: Olivier Goffart <ogoffart at woboq.com>
Date: Tue Feb 18 12:54:40 2014 +0100
move the file system helpers in their own file
---
src/CMakeLists.txt | 1 +
src/mirall/filesystem.cpp | 72 +++++++++++++++++++++++++++++++++++++++
src/mirall/filesystem.h | 35 +++++++++++++++++++
src/mirall/owncloudpropagator_p.h | 8 -----
src/mirall/propagator_legacy.cpp | 13 ++++---
src/mirall/propagator_qnam.cpp | 12 +++----
src/mirall/propagatorjobs.cpp | 33 ------------------
7 files changed, 119 insertions(+), 55 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 554b8f1..dc7c051 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -79,6 +79,7 @@ set(libsync_SRCS
mirall/owncloudtheme.cpp
mirall/logger.cpp
mirall/utility.cpp
+ mirall/filesystem.cpp
mirall/connectionvalidator.cpp
mirall/progressdispatcher.cpp
mirall/mirallaccessmanager.cpp
diff --git a/src/mirall/filesystem.cpp b/src/mirall/filesystem.cpp
new file mode 100644
index 0000000..c6422b3
--- /dev/null
+++ b/src/mirall/filesystem.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) by Daniel Molkentin <danimo at owncloud.com>
+ *
+ * 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; version 2 of the License.
+ *
+ * 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 "filesystem.h"
+#include <QFile>
+#include <QDebug>
+
+// We use some internals of csync:
+extern "C" int c_utimes(const char *, const struct timeval *);
+extern "C" void csync_win32_set_file_hidden( const char *file, bool h );
+
+namespace Mirall {
+
+bool FileSystem::fileEquals(const QString& fn1, const QString& fn2)
+{
+ // compare two files with given filename and return true if they have the same content
+ QFile f1(fn1);
+ QFile f2(fn2);
+ if (!f1.open(QIODevice::ReadOnly) || !f2.open(QIODevice::ReadOnly)) {
+ qDebug() << "fileEquals: Failed to open " << fn1 << "or" << fn2;
+ return false;
+ }
+
+ if (f1.size() != f2.size()) {
+ return false;
+ }
+
+ const int BufferSize = 16 * 1024;
+ char buffer1[BufferSize];
+ char buffer2[BufferSize];
+ do {
+ int r = f1.read(buffer1, BufferSize);
+ if (f2.read(buffer2, BufferSize) != r) {
+ // this should normaly not happen: the file are supposed to have the same size.
+ return false;
+ }
+ if (r <= 0) {
+ return true;
+ }
+ if (memcmp(buffer1, buffer2, r) != 0) {
+ return false;
+ }
+ } while (true);
+ return false;
+}
+
+void FileSystem::setFileHidden(const QString& filename, bool hidden)
+{
+ return csync_win32_set_file_hidden(filename.toUtf8().constData(), hidden);
+}
+
+void FileSystem::setModTime(const QString& filename, time_t modTime)
+{
+ struct timeval times[2];
+ times[0].tv_sec = times[1].tv_sec = modTime;
+ times[0].tv_usec = times[1].tv_usec = 0;
+ c_utimes(filename.toUtf8().data(), times);
+}
+
+
+
+}
\ No newline at end of file
diff --git a/src/mirall/filesystem.h b/src/mirall/filesystem.h
new file mode 100644
index 0000000..27f5e7a
--- /dev/null
+++ b/src/mirall/filesystem.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) by Olivier Goffart <ogoffart at owncloud.com>
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ */
+
+#pragma once
+
+#include <QString>
+#include <ctime>
+
+namespace Mirall {
+
+/**
+ * This file contains file system helper.
+ */
+
+namespace FileSystem {
+
+/** compare two files with given filename and return true if they have the same content */
+bool fileEquals(const QString &fn1, const QString &fn2);
+
+/** Mark the file as hidden (only has effects on windows) */
+void setFileHidden(const QString& filename, bool hidden);
+
+void setModTime(const QString &filename, time_t modTime);
+
+}}
diff --git a/src/mirall/owncloudpropagator_p.h b/src/mirall/owncloudpropagator_p.h
index dd0fda8..3f98f66 100644
--- a/src/mirall/owncloudpropagator_p.h
+++ b/src/mirall/owncloudpropagator_p.h
@@ -15,16 +15,8 @@
#pragma once
-// We use some internals of csync:
-extern "C" int c_utimes(const char *, const struct timeval *);
-extern "C" void csync_win32_set_file_hidden( const char *file, bool h );
-
-
namespace Mirall {
-/** compare two files with given filename and return true if they have the same content */
-bool fileEquals(const QString &fn1, const QString &fn2);
-
inline QByteArray parseEtag(const char *header) {
if (!header)
return QByteArray();
diff --git a/src/mirall/propagator_legacy.cpp b/src/mirall/propagator_legacy.cpp
index da3ff15..8c9c236 100644
--- a/src/mirall/propagator_legacy.cpp
+++ b/src/mirall/propagator_legacy.cpp
@@ -19,6 +19,7 @@
#include "utility.h"
#include "syncjournaldb.h"
#include "syncjournalfilerecord.h"
+#include "filesystem.h"
#include <httpbf.h>
#include <qfile.h>
#include <qdir.h>
@@ -479,7 +480,7 @@ void PropagateDownloadFileLegacy::start()
return;
}
- csync_win32_set_file_hidden(tmpFile.fileName().toUtf8().constData(), true);
+ FileSystem::setFileHidden(tmpFile.fileName(), true);
{
SyncJournalDb::DownloadInfo pi;
@@ -565,7 +566,7 @@ void PropagateDownloadFileLegacy::start()
bool isConflict = _item._instruction == CSYNC_INSTRUCTION_CONFLICT
- && !fileEquals(fn, tmpFile.fileName()); // compare the files to see if there was an actual conflict.
+ && !FileSystem::fileEquals(fn, tmpFile.fileName()); // compare the files to see if there was an actual conflict.
//In case of conflict, make a backup of the old file
if (isConflict) {
QFile f(fn);
@@ -590,7 +591,7 @@ void PropagateDownloadFileLegacy::start()
tmpFile.setPermissions(existingFile.permissions());
}
- csync_win32_set_file_hidden(tmpFile.fileName().toUtf8().constData(), false);
+ FileSystem::setFileHidden(tmpFile.fileName(), false);
#ifndef Q_OS_WIN
bool success;
@@ -626,10 +627,8 @@ void PropagateDownloadFileLegacy::start()
return;
}
#endif
- struct timeval times[2];
- times[0].tv_sec = times[1].tv_sec = _item._modtime;
- times[0].tv_usec = times[1].tv_usec = 0;
- c_utimes(fn.toUtf8().data(), times);
+
+ FileSystem::setModTime(fn, _item._modtime);
_propagator->_journal->setFileRecord(SyncJournalFileRecord(_item, fn));
_propagator->_journal->setDownloadInfo(_item._file, SyncJournalDb::DownloadInfo());
diff --git a/src/mirall/propagator_qnam.cpp b/src/mirall/propagator_qnam.cpp
index ee7a776..256b483 100644
--- a/src/mirall/propagator_qnam.cpp
+++ b/src/mirall/propagator_qnam.cpp
@@ -18,6 +18,7 @@
#include "syncjournaldb.h"
#include "syncjournalfilerecord.h"
#include "utility.h"
+#include "filesystem.h"
#include <QNetworkAccessManager>
#include <QFileInfo>
#include <cmath>
@@ -354,7 +355,7 @@ void PropagateDownloadFileQNAM::start()
return;
}
- csync_win32_set_file_hidden(_tmpFile.fileName().toUtf8().constData(), true);
+ FileSystem::setFileHidden(_tmpFile.fileName(), true);
{
SyncJournalDb::DownloadInfo pi;
@@ -426,7 +427,7 @@ void PropagateDownloadFileQNAM::downloadFinished()
bool isConflict = _item._instruction == CSYNC_INSTRUCTION_CONFLICT
- && !fileEquals(fn, _tmpFile.fileName()); // compare the files to see if there was an actual conflict.
+ && !FileSystem::fileEquals(fn, _tmpFile.fileName()); // compare the files to see if there was an actual conflict.
//In case of conflict, make a backup of the old file
if (isConflict) {
QFile f(fn);
@@ -451,7 +452,7 @@ void PropagateDownloadFileQNAM::downloadFinished()
_tmpFile.setPermissions(existingFile.permissions());
}
- csync_win32_set_file_hidden(_tmpFile.fileName().toUtf8().constData(), false);
+ FileSystem::setFileHidden(_tmpFile.fileName(), false);
//FIXME: duplicated code.
#ifndef Q_OS_WIN
@@ -488,10 +489,7 @@ void PropagateDownloadFileQNAM::downloadFinished()
return;
}
#endif
- struct timeval times[2];
- times[0].tv_sec = times[1].tv_sec = _item._modtime;
- times[0].tv_usec = times[1].tv_usec = 0;
- c_utimes(fn.toUtf8().data(), times);
+ FileSystem::setModTime(fn, _item._modtime);
_propagator->_journal->setFileRecord(SyncJournalFileRecord(_item, fn));
_propagator->_journal->setDownloadInfo(_item._file, SyncJournalDb::DownloadInfo());
diff --git a/src/mirall/propagatorjobs.cpp b/src/mirall/propagatorjobs.cpp
index 2c5d4b3..26b6c49 100644
--- a/src/mirall/propagatorjobs.cpp
+++ b/src/mirall/propagatorjobs.cpp
@@ -101,39 +101,6 @@ void PropagateNeonJob::slotRestoreJobCompleted(const SyncFileItem& item )
}
}
-
-// compare two files with given filename and return true if they have the same content
-bool fileEquals(const QString &fn1, const QString &fn2) {
- QFile f1(fn1);
- QFile f2(fn2);
- if (!f1.open(QIODevice::ReadOnly) || !f2.open(QIODevice::ReadOnly)) {
- qDebug() << "fileEquals: Failed to open " << fn1 << "or" << fn2;
- return false;
- }
-
- if (f1.size() != f2.size()) {
- return false;
- }
-
- const int BufferSize = 16 * 1024;
- char buffer1[BufferSize];
- char buffer2[BufferSize];
- do {
- int r = f1.read(buffer1, BufferSize);
- if (f2.read(buffer2, BufferSize) != r) {
- // this should normaly not happen: the file are supposed to have the same size.
- return false;
- }
- if (r <= 0) {
- return true;
- }
- if (memcmp(buffer1, buffer2, r) != 0) {
- return false;
- }
- } while (true);
- return false;
-}
-
// Code copied from Qt5's QDir::removeRecursively
static bool removeRecursively(const QString &path)
{
--
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