mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 23:28:14 +03:00
SocketAPI: Enhance SyncFileStatus to have share information.
Added a new class SyncFileStatus to reflect that properly.
This commit is contained in:
parent
9dacad99fa
commit
c6deb392fd
6 changed files with 177 additions and 76 deletions
|
@ -87,6 +87,7 @@ set(libsync_SRCS
|
||||||
mirall/clientproxy.cpp
|
mirall/clientproxy.cpp
|
||||||
mirall/syncrunfilelog.cpp
|
mirall/syncrunfilelog.cpp
|
||||||
mirall/cookiejar.cpp
|
mirall/cookiejar.cpp
|
||||||
|
mirall/syncfilestatus.cpp
|
||||||
creds/dummycredentials.cpp
|
creds/dummycredentials.cpp
|
||||||
creds/abstractcredentials.cpp
|
creds/abstractcredentials.cpp
|
||||||
creds/credentialsfactory.cpp
|
creds/credentialsfactory.cpp
|
||||||
|
|
|
@ -373,17 +373,17 @@ void Folder::bubbleUpSyncResult()
|
||||||
qDebug() << "Processing result list and logging took " << timer.elapsed() << " Milliseconds.";
|
qDebug() << "Processing result list and logging took " << timer.elapsed() << " Milliseconds.";
|
||||||
_syncResult.setWarnCount(ignoredItems);
|
_syncResult.setWarnCount(ignoredItems);
|
||||||
|
|
||||||
createGuiLog( firstItemNew._file, FILE_STATUS_NEW, newItems );
|
createGuiLog( firstItemNew._file, SyncFileStatus(SyncFileStatus::STATUS_NEW), newItems );
|
||||||
createGuiLog( firstItemDeleted._file, FILE_STATUS_REMOVE, removedItems );
|
createGuiLog( firstItemDeleted._file, SyncFileStatus(SyncFileStatus::STATUS_REMOVE), removedItems );
|
||||||
createGuiLog( firstItemUpdated._file, FILE_STATUS_UPDATED, updatedItems );
|
createGuiLog( firstItemUpdated._file, SyncFileStatus(SyncFileStatus::STATUS_UPDATED), updatedItems );
|
||||||
|
|
||||||
if( !firstItemRenamed.isEmpty() ) {
|
if( !firstItemRenamed.isEmpty() ) {
|
||||||
SyncFileStatus status = FILE_STATUS_RENAME;
|
SyncFileStatus status(SyncFileStatus::STATUS_RENAME);
|
||||||
// if the path changes it's rather a move
|
// if the path changes it's rather a move
|
||||||
QDir renTarget = QFileInfo(firstItemRenamed._renameTarget).dir();
|
QDir renTarget = QFileInfo(firstItemRenamed._renameTarget).dir();
|
||||||
QDir renSource = QFileInfo(firstItemRenamed._file).dir();
|
QDir renSource = QFileInfo(firstItemRenamed._file).dir();
|
||||||
if(renTarget != renSource) {
|
if(renTarget != renSource) {
|
||||||
status = FILE_STATUS_MOVE;
|
status.set(SyncFileStatus::STATUS_MOVE);
|
||||||
}
|
}
|
||||||
createGuiLog( firstItemRenamed._file, status, renamedItems, firstItemRenamed._renameTarget );
|
createGuiLog( firstItemRenamed._file, status, renamedItems, firstItemRenamed._renameTarget );
|
||||||
}
|
}
|
||||||
|
@ -402,36 +402,36 @@ void Folder::createGuiLog( const QString& filename, SyncFileStatus status, int c
|
||||||
|
|
||||||
// not all possible values of status are evaluated here because the others
|
// not all possible values of status are evaluated here because the others
|
||||||
// are not used in the calling function. Please check there.
|
// are not used in the calling function. Please check there.
|
||||||
switch (status) {
|
switch (status.tag()) {
|
||||||
case FILE_STATUS_REMOVE:
|
case SyncFileStatus::STATUS_REMOVE:
|
||||||
if( count > 1 ) {
|
if( count > 1 ) {
|
||||||
text = tr("%1 and %2 other files have been removed.", "%1 names a file.").arg(file).arg(count-1);
|
text = tr("%1 and %2 other files have been removed.", "%1 names a file.").arg(file).arg(count-1);
|
||||||
} else {
|
} else {
|
||||||
text = tr("%1 has been removed.", "%1 names a file.").arg(file);
|
text = tr("%1 has been removed.", "%1 names a file.").arg(file);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FILE_STATUS_NEW:
|
case SyncFileStatus::STATUS_NEW:
|
||||||
if( count > 1 ) {
|
if( count > 1 ) {
|
||||||
text = tr("%1 and %2 other files have been downloaded.", "%1 names a file.").arg(file).arg(count-1);
|
text = tr("%1 and %2 other files have been downloaded.", "%1 names a file.").arg(file).arg(count-1);
|
||||||
} else {
|
} else {
|
||||||
text = tr("%1 has been downloaded.", "%1 names a file.").arg(file);
|
text = tr("%1 has been downloaded.", "%1 names a file.").arg(file);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FILE_STATUS_UPDATED:
|
case SyncFileStatus::STATUS_UPDATED:
|
||||||
if( count > 1 ) {
|
if( count > 1 ) {
|
||||||
text = tr("%1 and %2 other files have been updated.").arg(file).arg(count-1);
|
text = tr("%1 and %2 other files have been updated.").arg(file).arg(count-1);
|
||||||
} else {
|
} else {
|
||||||
text = tr("%1 has been updated.", "%1 names a file.").arg(file);
|
text = tr("%1 has been updated.", "%1 names a file.").arg(file);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FILE_STATUS_RENAME:
|
case SyncFileStatus::STATUS_RENAME:
|
||||||
if( count > 1 ) {
|
if( count > 1 ) {
|
||||||
text = tr("%1 has been renamed to %2 and %3 other files have been renamed.").arg(file).arg(renameTarget).arg(count-1);
|
text = tr("%1 has been renamed to %2 and %3 other files have been renamed.").arg(file).arg(renameTarget).arg(count-1);
|
||||||
} else {
|
} else {
|
||||||
text = tr("%1 has been renamed to %2.", "%1 and %2 name files.").arg(file).arg(renameTarget);
|
text = tr("%1 has been renamed to %2.", "%1 and %2 name files.").arg(file).arg(renameTarget);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FILE_STATUS_MOVE:
|
case SyncFileStatus::STATUS_MOVE:
|
||||||
if( count > 1 ) {
|
if( count > 1 ) {
|
||||||
text = tr("%1 has been moved to %2 and %3 other files have been moved.").arg(file).arg(renameTarget).arg(count-1);
|
text = tr("%1 has been moved to %2 and %3 other files have been moved.").arg(file).arg(renameTarget).arg(count-1);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "mirall/progressdispatcher.h"
|
#include "mirall/progressdispatcher.h"
|
||||||
#include "mirall/syncjournaldb.h"
|
#include "mirall/syncjournaldb.h"
|
||||||
#include "mirall/clientproxy.h"
|
#include "mirall/clientproxy.h"
|
||||||
|
#include "mirall/syncfilestatus.h"
|
||||||
|
|
||||||
#include <csync.h>
|
#include <csync.h>
|
||||||
|
|
||||||
|
@ -42,23 +43,7 @@ class SyncEngine;
|
||||||
|
|
||||||
class FolderWatcher;
|
class FolderWatcher;
|
||||||
|
|
||||||
enum SyncFileStatus {
|
class OWNCLOUDSYNC_EXPORT Folder : public QObject
|
||||||
FILE_STATUS_NONE,
|
|
||||||
FILE_STATUS_EVAL,
|
|
||||||
FILE_STATUS_REMOVE,
|
|
||||||
FILE_STATUS_RENAME,
|
|
||||||
FILE_STATUS_MOVE,
|
|
||||||
FILE_STATUS_NEW,
|
|
||||||
FILE_STATUS_CONFLICT,
|
|
||||||
FILE_STATUS_IGNORE,
|
|
||||||
FILE_STATUS_SYNC,
|
|
||||||
FILE_STATUS_STAT_ERROR,
|
|
||||||
FILE_STATUS_ERROR,
|
|
||||||
FILE_STATUS_UPDATED,
|
|
||||||
FILE_STATUS_SHARED
|
|
||||||
};
|
|
||||||
|
|
||||||
class Folder : public QObject
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ SyncFileStatus recursiveFolderStatus(Folder *folder, const QString& fileName )
|
||||||
|
|
||||||
const QStringList dirEntries = dir.entryList( QDir::AllEntries | QDir::NoDotAndDotDot );
|
const QStringList dirEntries = dir.entryList( QDir::AllEntries | QDir::NoDotAndDotDot );
|
||||||
|
|
||||||
SyncFileStatus result = FILE_STATUS_SYNC;
|
SyncFileStatus result(SyncFileStatus::STATUS_SYNC);
|
||||||
|
|
||||||
foreach( const QString entry, dirEntries ) {
|
foreach( const QString entry, dirEntries ) {
|
||||||
QFileInfo fi(entry);
|
QFileInfo fi(entry);
|
||||||
|
@ -88,10 +88,10 @@ SyncFileStatus recursiveFolderStatus(Folder *folder, const QString& fileName )
|
||||||
sfs = fileStatus(folder, fs );
|
sfs = fileStatus(folder, fs );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( sfs == FILE_STATUS_STAT_ERROR || sfs == FILE_STATUS_ERROR ) {
|
if( sfs.tag() == SyncFileStatus::STATUS_STAT_ERROR || sfs.tag() == SyncFileStatus::STATUS_ERROR ) {
|
||||||
return FILE_STATUS_ERROR;
|
return SyncFileStatus::STATUS_ERROR;
|
||||||
} else if( sfs == FILE_STATUS_EVAL || sfs == FILE_STATUS_NEW) {
|
} else if( sfs.tag() == SyncFileStatus::STATUS_EVAL || sfs.tag() == SyncFileStatus::STATUS_NEW) {
|
||||||
result = FILE_STATUS_EVAL;
|
result.set(SyncFileStatus::STATUS_EVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -112,12 +112,12 @@ SyncFileStatus fileStatus(Folder *folder, const QString& fileName )
|
||||||
QFileInfo fi(file);
|
QFileInfo fi(file);
|
||||||
|
|
||||||
if( !fi.exists() ) {
|
if( !fi.exists() ) {
|
||||||
return FILE_STATUS_STAT_ERROR;
|
return SyncFileStatus(SyncFileStatus::STATUS_STAT_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// file is ignored?
|
// file is ignored?
|
||||||
if( fi.isSymLink() ) {
|
if( fi.isSymLink() ) {
|
||||||
return FILE_STATUS_IGNORE;
|
return SyncFileStatus(SyncFileStatus::STATUS_IGNORE);
|
||||||
}
|
}
|
||||||
int type = CSYNC_FTW_TYPE_FILE;
|
int type = CSYNC_FTW_TYPE_FILE;
|
||||||
if( fi.isDir() ) {
|
if( fi.isDir() ) {
|
||||||
|
@ -126,28 +126,28 @@ SyncFileStatus fileStatus(Folder *folder, const QString& fileName )
|
||||||
|
|
||||||
CSYNC_EXCLUDE_TYPE excl = csync_excluded(folder->csyncContext(), file.toUtf8(), type);
|
CSYNC_EXCLUDE_TYPE excl = csync_excluded(folder->csyncContext(), file.toUtf8(), type);
|
||||||
if( excl != CSYNC_NOT_EXCLUDED ) {
|
if( excl != CSYNC_NOT_EXCLUDED ) {
|
||||||
return FILE_STATUS_IGNORE;
|
return SyncFileStatus(SyncFileStatus::STATUS_IGNORE);
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncFileStatus stat = FILE_STATUS_NONE;
|
|
||||||
SyncJournalFileRecord rec = folder->journalDb()->getFileRecord(fileName);
|
SyncJournalFileRecord rec = folder->journalDb()->getFileRecord(fileName);
|
||||||
if( !rec.isValid() ) {
|
if( !rec.isValid() ) {
|
||||||
return FILE_STATUS_NEW;
|
return SyncFileStatus(SyncFileStatus::STATUS_NEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SyncFileStatus stat(SyncFileStatus::STATUS_NONE);
|
||||||
if( type == CSYNC_FTW_TYPE_DIR ) {
|
if( type == CSYNC_FTW_TYPE_DIR ) {
|
||||||
// compute recursive status of the directory
|
// compute recursive status of the directory
|
||||||
stat = recursiveFolderStatus( folder, fileName );
|
stat = recursiveFolderStatus( folder, fileName );
|
||||||
} else if(fi.lastModified() != rec._modtime ) {
|
} else if(fi.lastModified() != rec._modtime ) {
|
||||||
// file was locally modified.
|
// file was locally modified.
|
||||||
stat = FILE_STATUS_EVAL;
|
stat.set(SyncFileStatus::STATUS_EVAL);
|
||||||
} else {
|
} else {
|
||||||
stat = FILE_STATUS_SYNC;
|
stat.set(SyncFileStatus::STATUS_SYNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rec._remotePerm.contains("S")) {
|
if (rec._remotePerm.contains("S")) {
|
||||||
// FIXME! that should be an additional flag
|
// FIXME! that should be an additional flag
|
||||||
stat = FILE_STATUS_SHARED;
|
stat.setSharedWithMe(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return stat;
|
return stat;
|
||||||
|
@ -294,44 +294,16 @@ void SocketApi::command_RETRIEVE_FILE_STATUS(const QString& argument, QLocalSock
|
||||||
|
|
||||||
QString statusString;
|
QString statusString;
|
||||||
|
|
||||||
Folder* folder = FolderMan::instance()->folderForPath( argument );
|
Folder* syncFolder = FolderMan::instance()->folderForPath( argument );
|
||||||
|
if (!syncFolder) {
|
||||||
// this can happen in offline mode e.g.: nothing to worry about
|
// this can happen in offline mode e.g.: nothing to worry about
|
||||||
if (!folder) {
|
|
||||||
DEBUG << "folder offline or not watched:" << argument;
|
DEBUG << "folder offline or not watched:" << argument;
|
||||||
statusString = QLatin1String("NOP");
|
statusString = QLatin1String("NOP");
|
||||||
}
|
} else {
|
||||||
|
const QString file = argument.mid(syncFolder->path().length());
|
||||||
|
SyncFileStatus fileStatus = SocketApiHelper::fileStatus(syncFolder, file);
|
||||||
|
|
||||||
if( statusString.isEmpty() ) {
|
statusString = fileStatus.toSocketAPIString();
|
||||||
SyncFileStatus fileStatus = SocketApiHelper::fileStatus(folder, argument.mid(folder->path().length()) );
|
|
||||||
|
|
||||||
switch(fileStatus)
|
|
||||||
{
|
|
||||||
case FILE_STATUS_NONE:
|
|
||||||
statusString = QLatin1String("NONE");
|
|
||||||
break;
|
|
||||||
case FILE_STATUS_EVAL:
|
|
||||||
case FILE_STATUS_NEW:
|
|
||||||
statusString = QLatin1String("NEED_SYNC");
|
|
||||||
break;
|
|
||||||
case FILE_STATUS_IGNORE:
|
|
||||||
statusString = QLatin1String("IGNORE");
|
|
||||||
break;
|
|
||||||
case FILE_STATUS_SYNC:
|
|
||||||
case FILE_STATUS_UPDATED:
|
|
||||||
statusString = QLatin1String("OK");
|
|
||||||
break;
|
|
||||||
case FILE_STATUS_STAT_ERROR:
|
|
||||||
case FILE_STATUS_ERROR:
|
|
||||||
statusString = QLatin1String("ERROR");
|
|
||||||
break;
|
|
||||||
case FILE_STATUS_SHARED:
|
|
||||||
statusString = QLatin1String("SHARED");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
qWarning() << "This status should not be there" << fileStatus;
|
|
||||||
Q_ASSERT(false);
|
|
||||||
statusString = QLatin1String("NONE");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString message = QLatin1String("STATUS:")+statusString+QLatin1Char(':')+argument;
|
QString message = QLatin1String("STATUS:")+statusString+QLatin1Char(':')+argument;
|
||||||
|
|
87
src/mirall/syncfilestatus.cpp
Normal file
87
src/mirall/syncfilestatus.cpp
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) by Klaas Freitag <freitag@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 "mirall/syncfilestatus.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
namespace Mirall {
|
||||||
|
SyncFileStatus::SyncFileStatus()
|
||||||
|
:_tag(STATUS_NONE), _sharedWithMe(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncFileStatus::SyncFileStatus(SyncFileStatusTag tag)
|
||||||
|
:_tag(tag), _sharedWithMe(false)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SyncFileStatus::set(SyncFileStatusTag tag)
|
||||||
|
{
|
||||||
|
_tag = tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncFileStatus::SyncFileStatusTag SyncFileStatus::tag()
|
||||||
|
{
|
||||||
|
return _tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SyncFileStatus::setSharedWithMe(bool isShared)
|
||||||
|
{
|
||||||
|
_sharedWithMe = isShared;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SyncFileStatus::sharedWithMe()
|
||||||
|
{
|
||||||
|
return _sharedWithMe;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString SyncFileStatus::toSocketAPIString() const
|
||||||
|
{
|
||||||
|
QString statusString;
|
||||||
|
|
||||||
|
switch(_tag)
|
||||||
|
{
|
||||||
|
case STATUS_NONE:
|
||||||
|
statusString = QLatin1String("NONE");
|
||||||
|
break;
|
||||||
|
case STATUS_EVAL:
|
||||||
|
statusString = QLatin1String("SYNC");
|
||||||
|
break;
|
||||||
|
case STATUS_NEW:
|
||||||
|
statusString = QLatin1String("NEW");
|
||||||
|
break;
|
||||||
|
case STATUS_IGNORE:
|
||||||
|
statusString = QLatin1String("IGNORE");
|
||||||
|
break;
|
||||||
|
case STATUS_SYNC:
|
||||||
|
case STATUS_UPDATED:
|
||||||
|
statusString = QLatin1String("OK");
|
||||||
|
break;
|
||||||
|
case STATUS_STAT_ERROR:
|
||||||
|
case STATUS_ERROR:
|
||||||
|
statusString = QLatin1String("ERROR");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
qWarning() << "This status should not be here:" << _tag;
|
||||||
|
Q_ASSERT(false);
|
||||||
|
statusString = QLatin1String("NONE");
|
||||||
|
}
|
||||||
|
if(_sharedWithMe) {
|
||||||
|
statusString += QLatin1String("+SWM");
|
||||||
|
}
|
||||||
|
|
||||||
|
return statusString;
|
||||||
|
}
|
||||||
|
}
|
56
src/mirall/syncfilestatus.h
Normal file
56
src/mirall/syncfilestatus.h
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) by Klaas Freitag <freitag@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SYNCFILESTATUS_H
|
||||||
|
#define SYNCFILESTATUS_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
namespace Mirall {
|
||||||
|
|
||||||
|
class SyncFileStatus
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum SyncFileStatusTag {
|
||||||
|
STATUS_NONE,
|
||||||
|
STATUS_EVAL,
|
||||||
|
STATUS_REMOVE,
|
||||||
|
STATUS_RENAME,
|
||||||
|
STATUS_MOVE,
|
||||||
|
STATUS_NEW,
|
||||||
|
STATUS_CONFLICT,
|
||||||
|
STATUS_IGNORE,
|
||||||
|
STATUS_SYNC,
|
||||||
|
STATUS_STAT_ERROR,
|
||||||
|
STATUS_ERROR,
|
||||||
|
STATUS_UPDATED
|
||||||
|
};
|
||||||
|
|
||||||
|
SyncFileStatus();
|
||||||
|
SyncFileStatus(SyncFileStatusTag);
|
||||||
|
|
||||||
|
void set(SyncFileStatusTag tag);
|
||||||
|
SyncFileStatusTag tag();
|
||||||
|
|
||||||
|
void setSharedWithMe( bool isShared );
|
||||||
|
bool sharedWithMe();
|
||||||
|
|
||||||
|
QString toSocketAPIString() const;
|
||||||
|
private:
|
||||||
|
SyncFileStatusTag _tag;
|
||||||
|
bool _sharedWithMe;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SYNCFILESTATUS_H
|
Loading…
Reference in a new issue