2014-03-26 21:01:26 +04:00
|
|
|
/*
|
|
|
|
* 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
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2014-03-26 21:01:26 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-04-03 18:56:36 +04:00
|
|
|
#include <QRegExp>
|
|
|
|
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "syncrunfilelog.h"
|
|
|
|
#include "utility.h"
|
2014-04-02 18:36:32 +04:00
|
|
|
#include "filesystem.h"
|
2014-03-28 13:13:35 +04:00
|
|
|
#include <qfileinfo.h>
|
2014-03-26 21:01:26 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2014-03-26 21:01:26 +04:00
|
|
|
|
|
|
|
SyncRunFileLog::SyncRunFileLog()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SyncRunFileLog::dateTimeStr(const QDateTime &dt)
|
|
|
|
{
|
|
|
|
return dt.toString(Qt::ISODate);
|
|
|
|
}
|
|
|
|
|
2014-04-03 18:56:36 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-03-26 21:01:26 +04:00
|
|
|
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;
|
2016-01-06 12:01:22 +03:00
|
|
|
case CSYNC_INSTRUCTION_TYPE_CHANGE:
|
|
|
|
re = "INST_TYPE_CHANGE";
|
|
|
|
break;
|
2016-08-15 15:17:51 +03:00
|
|
|
case CSYNC_INSTRUCTION_UPDATE_METADATA:
|
|
|
|
re = "INST_METADATA";
|
|
|
|
break;
|
2014-03-26 21:01:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return re;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-09 15:10:47 +03:00
|
|
|
void SyncRunFileLog::start(const QString &folderPath)
|
2014-03-26 21:01:26 +04:00
|
|
|
{
|
2014-03-28 13:13:35 +04:00
|
|
|
const qint64 logfileMaxSize = 1024 * 1024; // 1MiB
|
2014-04-02 18:36:32 +04:00
|
|
|
|
|
|
|
// Note; this name is ignored in csync_exclude.c
|
|
|
|
const QString filename = folderPath + QLatin1String(".owncloudsync.log");
|
2014-03-28 13:13:35 +04:00
|
|
|
|
|
|
|
// When the file is too big, just rename it to an old name.
|
|
|
|
QFileInfo info(filename);
|
2014-04-02 18:18:09 +04:00
|
|
|
bool exists = info.exists();
|
|
|
|
if (exists && info.size() > logfileMaxSize) {
|
|
|
|
exists = false;
|
2014-03-28 13:13:35 +04:00
|
|
|
QString newFilename = filename + QLatin1String(".1");
|
|
|
|
QFile::remove(newFilename);
|
|
|
|
QFile::rename(filename, newFilename);
|
|
|
|
}
|
|
|
|
_file.reset(new QFile(filename));
|
2014-03-26 21:01:26 +04:00
|
|
|
|
|
|
|
_file->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
|
|
|
|
_out.setDevice(_file.data());
|
|
|
|
|
|
|
|
|
2014-04-02 18:18:09 +04:00
|
|
|
if (!exists) {
|
|
|
|
// We are creating a new file, add the note.
|
2014-04-03 18:56:36 +04:00
|
|
|
_out << "# timestamp | duration | file | instruction | dir | modtime | etag | "
|
2014-04-02 18:18:09 +04:00
|
|
|
"size | fileId | status | errorString | http result code | "
|
|
|
|
"other size | other modtime | other etag | other fileId | "
|
|
|
|
"other instruction"
|
|
|
|
<< endl;
|
2014-04-02 18:36:32 +04:00
|
|
|
|
|
|
|
FileSystem::setFileHidden(filename, true);
|
2014-04-02 18:18:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-09 15:28:15 +03:00
|
|
|
_totalDuration.start();
|
|
|
|
_lapDuration.start();
|
2016-06-09 15:10:47 +03:00
|
|
|
_out << "#=#=#=# Syncrun started " << dateTimeStr(QDateTime::currentDateTime()) << endl;
|
2014-03-26 21:01:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SyncRunFileLog::logItem(const SyncFileItem &item)
|
|
|
|
{
|
|
|
|
// don't log the directory items that are in the list
|
|
|
|
if (item._direction == SyncFileItem::None) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-09 17:52:52 +03:00
|
|
|
QString ts = QString::fromAscii(item._responseTimeStamp);
|
2014-04-03 18:56:36 +04:00
|
|
|
if (ts.length() > 6) {
|
|
|
|
QRegExp rx("(\\d\\d:\\d\\d:\\d\\d)");
|
|
|
|
if (ts.contains(rx)) {
|
|
|
|
ts = rx.cap(0);
|
|
|
|
}
|
|
|
|
}
|
2014-03-26 21:01:26 +04:00
|
|
|
|
2014-03-28 12:27:05 +04:00
|
|
|
const QChar L = QLatin1Char('|');
|
2014-04-03 18:56:36 +04:00
|
|
|
_out << ts << L;
|
2017-01-26 15:39:00 +03:00
|
|
|
_out << L;
|
2017-01-25 16:53:10 +03:00
|
|
|
if (item._instruction != CSYNC_INSTRUCTION_RENAME) {
|
2016-09-05 14:26:49 +03:00
|
|
|
_out << item._file << L;
|
|
|
|
} else {
|
|
|
|
_out << item._file << QLatin1String(" -> ") << item._renameTarget << L;
|
|
|
|
}
|
2017-01-25 16:53:10 +03:00
|
|
|
_out << instructionToStr(item._instruction) << L;
|
2014-04-03 18:56:36 +04:00
|
|
|
_out << directionToStr(item._direction) << L;
|
2017-01-25 16:53:10 +03:00
|
|
|
_out << QString::number(item._modtime) << L;
|
|
|
|
_out << item._etag << L;
|
|
|
|
_out << QString::number(item._size) << L;
|
|
|
|
_out << item._fileId << L;
|
2014-03-26 21:01:26 +04:00
|
|
|
_out << item._status << L;
|
|
|
|
_out << item._errorString << L;
|
|
|
|
_out << QString::number(item._httpErrorCode) << L;
|
2014-04-03 18:56:36 +04:00
|
|
|
_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;
|
2014-03-26 21:01:26 +04:00
|
|
|
|
|
|
|
_out << endl;
|
|
|
|
}
|
|
|
|
|
2016-06-09 15:28:15 +03:00
|
|
|
void SyncRunFileLog::logLap(const QString &name)
|
|
|
|
{
|
|
|
|
_out << "#=#=#=#=# " << name << " " << dateTimeStr(QDateTime::currentDateTime())
|
|
|
|
<< " (last step: " << _lapDuration.restart() << " msec"
|
|
|
|
<< ", total: " << _totalDuration.elapsed() << " msec)" << endl;
|
|
|
|
}
|
|
|
|
|
2016-06-09 15:10:47 +03:00
|
|
|
void SyncRunFileLog::finish()
|
2014-03-26 21:01:26 +04:00
|
|
|
{
|
2016-06-09 15:10:47 +03:00
|
|
|
_out << "#=#=#=# Syncrun finished " << dateTimeStr(QDateTime::currentDateTime())
|
2016-06-09 15:28:15 +03:00
|
|
|
<< " (last step: " << _lapDuration.elapsed() << " msec"
|
|
|
|
<< ", total: " << _totalDuration.elapsed() << " msec)" << endl;
|
2014-03-26 21:01:26 +04:00
|
|
|
_file->close();
|
|
|
|
}
|
|
|
|
}
|