desktop/src/gui/syncrunfilelog.cpp

188 lines
5.4 KiB
C++
Raw Normal View History

/*
* 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; 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 <QRegExp>
#include "syncrunfilelog.h"
#include "utility.h"
2014-04-02 14:36:32 +00:00
#include "filesystem.h"
2014-03-28 09:13:35 +00:00
#include <qfileinfo.h>
2014-11-09 21:34:07 +00:00
namespace OCC {
SyncRunFileLog::SyncRunFileLog()
{
}
QString SyncRunFileLog::dateTimeStr( const QDateTime& dt )
{
return dt.toString(Qt::ISODate);
}
QString SyncRunFileLog::directionToStr( SyncFileItem::Direction dir )
{
QString re("N");
if( dir == SyncFileItem::Up ) {
re = QLatin1String("Up");
} else if( dir == SyncFileItem::Down ) {
re = QLatin1String("Down");
}
return re;
}
QString SyncRunFileLog::instructionToStr( csync_instructions_e inst )
{
QString re;
switch( inst ) {
case CSYNC_INSTRUCTION_NONE:
re = "INST_NONE";
break;
case CSYNC_INSTRUCTION_EVAL:
re = "INST_EVAL";
break;
case CSYNC_INSTRUCTION_REMOVE:
re = "INST_REMOVE";
break;
case CSYNC_INSTRUCTION_RENAME:
re = "INST_RENAME";
break;
case CSYNC_INSTRUCTION_EVAL_RENAME:
re = "INST_EVAL_RENAME";
break;
case CSYNC_INSTRUCTION_NEW:
re = "INST_NEW";
break;
case CSYNC_INSTRUCTION_CONFLICT:
re = "INST_CONFLICT";
break;
case CSYNC_INSTRUCTION_IGNORE:
re = "INST_IGNORE";
break;
case CSYNC_INSTRUCTION_SYNC:
re = "INST_SYNC";
break;
case CSYNC_INSTRUCTION_STAT_ERROR:
re = "INST_STAT_ERR";
break;
case CSYNC_INSTRUCTION_ERROR:
re = "INST_ERROR";
break;
case CSYNC_INSTRUCTION_TYPE_CHANGE:
re = "INST_TYPE_CHANGE";
break;
csync: Use an explicit instruction for should_update_metadata The current way of tracking the need to update the metadata without propagation using a separate flag makes it difficult to track priorities between the local and remote tree. The logic is also difficult to logically cover since the possibilities matrix isn't 100% covered, leaving the flag only used in a few situations (mostly involving folders, but not only). The reason we need to change this is to be able to track the sync state of files for overlay icons. The instruction alone can't be used since CSYNC_INSTRUCTION_SYNC is used for folders even though they won't be propagated. Removing this logic is however not possible without using something else than CSYNC_INSTRUCTION_NONE since too many codepath interpret (rightfully) this as meaning "nothing to do". This patch adds a new CSYNC_INSTRUCTION_UPDATE_METADATA instruction to let the update and reconcile steps tell the SyncEngine to update the metadata of a file without any propagation. Other flags are left to be interpretted by the implementation as implicitly needing metadata update or not, as this was already the case for most file propagation jobs. For example, CSYNC_INSTRUCTION_NEW for directories now also implicitly update the metadata. Since it's not impossible for folders to emit CSYNC_INSTRUCTION_SYNC or CSYNC_INSTRUCTION_CONFLICT, the corresponding code paths in the sync engine have been removed. Since the reconcile step can now know if the local tree needs metadata update while the remote side might want propagation, the localMetadataUpdate logic in SyncEngine::treewalkFile now simply use a CSYNC_INSTRUCTION_UPDATE_METADATA for the local side, which is now implemented as a different database query.
2016-08-15 12:17:51 +00:00
case CSYNC_INSTRUCTION_UPDATE_METADATA:
re = "INST_METADATA";
break;
}
return re;
}
void SyncRunFileLog::start(const QString &folderPath)
{
2014-03-28 09:13:35 +00:00
const qint64 logfileMaxSize = 1024*1024; // 1MiB
2014-04-02 14:36:32 +00:00
// Note; this name is ignored in csync_exclude.c
const QString filename = folderPath + QLatin1String(".owncloudsync.log");
2014-03-28 09:13:35 +00:00
// When the file is too big, just rename it to an old name.
QFileInfo info(filename);
bool exists = info.exists();
if (exists && info.size() > logfileMaxSize) {
exists = false;
2014-03-28 09:13:35 +00:00
QString newFilename = filename + QLatin1String(".1");
QFile::remove(newFilename);
QFile::rename(filename, newFilename);
}
_file.reset(new QFile(filename));
_file->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
_out.setDevice( _file.data() );
if (!exists) {
// We are creating a new file, add the note.
_out << "# timestamp | duration | file | instruction | dir | modtime | etag | "
"size | fileId | status | errorString | http result code | "
"other size | other modtime | other etag | other fileId | "
"other instruction" << endl;
2014-04-02 14:36:32 +00:00
FileSystem::setFileHidden(filename, true);
}
_totalDuration.start();
_lapDuration.start();
_out << "#=#=#=# Syncrun started " << dateTimeStr(QDateTime::currentDateTime()) << endl;
}
void SyncRunFileLog::logItem( const SyncFileItem& item )
{
// don't log the directory items that are in the list
if( item._direction == SyncFileItem::None ) {
return;
}
QString ts = QString::fromAscii(item._responseTimeStamp);
if( ts.length() > 6 ) {
QRegExp rx("(\\d\\d:\\d\\d:\\d\\d)");
if( ts.contains(rx) ) {
ts = rx.cap(0);
}
}
const QChar L = QLatin1Char('|');
_out << ts << L;
_out << QString::number(item._requestDuration) << L;
if( item.log._instruction != CSYNC_INSTRUCTION_RENAME ) {
_out << item._file << L;
} else {
_out << item._file << QLatin1String(" -> ") << item._renameTarget << L;
}
_out << instructionToStr( item.log._instruction ) << L;
_out << directionToStr( item._direction ) << L;
_out << QString::number(item.log._modtime) << L;
_out << item.log._etag << L;
_out << QString::number(item.log._size) << L;
_out << item.log._fileId << L;
_out << item._status << L;
_out << item._errorString << L;
_out << QString::number(item._httpErrorCode) << L;
_out << QString::number(item.log._other_size) << L;
_out << QString::number(item.log._other_modtime) << L;
_out << item.log._other_etag << L;
_out << item.log._other_fileId << L;
_out << instructionToStr(item.log._other_instruction) << L;
_out << endl;
}
void SyncRunFileLog::logLap(const QString& name)
{
_out << "#=#=#=#=# " << name << " " << dateTimeStr(QDateTime::currentDateTime())
<< " (last step: " << _lapDuration.restart() << " msec"
<< ", total: " << _totalDuration.elapsed() << " msec)" << endl;
}
void SyncRunFileLog::finish()
{
_out << "#=#=#=# Syncrun finished " << dateTimeStr(QDateTime::currentDateTime())
<< " (last step: " << _lapDuration.elapsed() << " msec"
<< ", total: " << _totalDuration.elapsed() << " msec)" << endl;
_file->close();
}
}