2013-10-03 17:27:29 +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.
|
2013-10-03 17:27:29 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "syncjournalfilerecord.h"
|
2013-10-03 22:00:58 +04:00
|
|
|
#include "syncfileitem.h"
|
2014-01-29 14:39:14 +04:00
|
|
|
#include "utility.h"
|
2015-07-03 17:26:00 +03:00
|
|
|
#include "filesystem.h"
|
2013-10-04 22:29:42 +04:00
|
|
|
|
2017-05-09 15:24:11 +03:00
|
|
|
#include <QLoggingCategory>
|
2013-10-03 22:00:58 +04:00
|
|
|
#include <qfileinfo.h>
|
|
|
|
|
2013-10-04 22:29:42 +04:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
#include <windows.h>
|
|
|
|
#else
|
2013-10-03 22:00:58 +04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
2013-10-03 17:27:29 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2013-10-03 17:27:29 +04:00
|
|
|
|
2017-05-09 15:24:11 +03:00
|
|
|
Q_LOGGING_CATEGORY(lcFileRecord, "sync.database.filerecord", QtInfoMsg)
|
|
|
|
|
2013-10-03 17:27:29 +04:00
|
|
|
SyncJournalFileRecord::SyncJournalFileRecord()
|
2015-11-11 11:32:13 +03:00
|
|
|
: _inode(0)
|
|
|
|
, _type(0)
|
|
|
|
, _fileSize(0)
|
|
|
|
, _serverHasIgnoredFiles(false)
|
2013-10-03 17:27:29 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-10-03 22:00:58 +04:00
|
|
|
SyncJournalFileRecord::SyncJournalFileRecord(const SyncFileItem &item, const QString &localFileName)
|
2014-02-04 19:17:58 +04:00
|
|
|
: _path(item._file)
|
|
|
|
, _modtime(Utility::qDateTimeFromTime_t(item._modtime))
|
2014-09-05 15:03:33 +04:00
|
|
|
, _type(item._type)
|
|
|
|
, _etag(item._etag)
|
|
|
|
, _fileId(item._fileId)
|
|
|
|
, _fileSize(item._size)
|
2015-11-11 11:32:13 +03:00
|
|
|
, _remotePerm(item._remotePerm)
|
|
|
|
, _serverHasIgnoredFiles(item._serverHasIgnoredFiles)
|
2017-06-14 13:14:46 +03:00
|
|
|
, _checksumHeader(item._checksumHeader)
|
2013-10-03 22:00:58 +04:00
|
|
|
{
|
2014-05-06 14:55:54 +04:00
|
|
|
// use the "old" inode coming with the item for the case where the
|
|
|
|
// filesystem stat fails. That can happen if the the file was removed
|
|
|
|
// or renamed meanwhile. For the rename case we still need the inode to
|
2015-10-05 06:20:09 +03:00
|
|
|
// detect the rename though.
|
2014-05-06 14:55:54 +04:00
|
|
|
_inode = item._inode;
|
2013-10-03 22:00:58 +04:00
|
|
|
|
2013-10-04 22:29:42 +04:00
|
|
|
#ifdef Q_OS_WIN
|
2014-05-06 14:55:54 +04:00
|
|
|
/* Query the inode:
|
|
|
|
based on code from csync_vio_local.c (csync_vio_local_stat)
|
|
|
|
Get the Windows file id as an inode replacement. */
|
2015-07-03 17:26:00 +03:00
|
|
|
|
|
|
|
HANDLE h = CreateFileW((wchar_t *)FileSystem::longWinPath(localFileName).utf16(), 0, FILE_SHARE_READ, NULL, OPEN_EXISTING,
|
2013-10-03 22:00:58 +04:00
|
|
|
FILE_ATTRIBUTE_NORMAL + FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
2014-05-06 14:55:54 +04:00
|
|
|
|
2013-10-03 22:00:58 +04:00
|
|
|
if (h == INVALID_HANDLE_VALUE) {
|
2017-05-09 15:24:11 +03:00
|
|
|
qCWarning(lcFileRecord) << "Failed to query the 'inode' because CreateFileW failed for file " << localFileName;
|
2013-10-03 22:00:58 +04:00
|
|
|
} else {
|
|
|
|
BY_HANDLE_FILE_INFORMATION fileInfo;
|
|
|
|
|
|
|
|
if (GetFileInformationByHandle(h, &fileInfo)) {
|
|
|
|
ULARGE_INTEGER FileIndex;
|
|
|
|
FileIndex.HighPart = fileInfo.nFileIndexHigh;
|
|
|
|
FileIndex.LowPart = fileInfo.nFileIndexLow;
|
|
|
|
FileIndex.QuadPart &= 0x0000FFFFFFFFFFFF;
|
|
|
|
|
|
|
|
/* printf("Index: %I64i\n", FileIndex.QuadPart); */
|
|
|
|
|
|
|
|
_inode = FileIndex.QuadPart;
|
|
|
|
} else {
|
2017-05-09 15:24:11 +03:00
|
|
|
qCWarning(lcFileRecord) << "Failed to query the 'inode' for file " << localFileName;
|
2013-10-03 22:00:58 +04:00
|
|
|
}
|
2013-12-03 13:06:53 +04:00
|
|
|
CloseHandle(h);
|
2013-10-03 22:00:58 +04:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
struct stat sb;
|
|
|
|
if (stat(QFile::encodeName(localFileName).constData(), &sb) < 0) {
|
2017-05-09 15:24:11 +03:00
|
|
|
qCWarning(lcFileRecord) << "Failed to query the 'inode' for file " << localFileName;
|
2013-10-03 22:00:58 +04:00
|
|
|
} else {
|
|
|
|
_inode = sb.st_ino;
|
|
|
|
}
|
|
|
|
#endif
|
2017-05-09 15:24:11 +03:00
|
|
|
qCDebug(lcFileRecord) << localFileName << "Retrieved inode " << _inode << "(previous item inode: " << item._inode << ")";
|
2013-10-03 22:00:58 +04:00
|
|
|
}
|
|
|
|
|
2015-11-10 16:26:25 +03:00
|
|
|
SyncFileItem SyncJournalFileRecord::toSyncFileItem()
|
|
|
|
{
|
|
|
|
SyncFileItem item;
|
|
|
|
item._file = _path;
|
|
|
|
item._inode = _inode;
|
|
|
|
item._modtime = Utility::qDateTimeToTime_t(_modtime);
|
|
|
|
item._type = static_cast<SyncFileItem::Type>(_type);
|
|
|
|
item._etag = _etag;
|
|
|
|
item._fileId = _fileId;
|
|
|
|
item._size = _fileSize;
|
|
|
|
item._remotePerm = _remotePerm;
|
|
|
|
item._serverHasIgnoredFiles = _serverHasIgnoredFiles;
|
2017-06-14 13:14:46 +03:00
|
|
|
item._checksumHeader = _checksumHeader;
|
2015-11-10 16:26:25 +03:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2015-01-16 12:17:19 +03:00
|
|
|
bool SyncJournalErrorBlacklistRecord::isValid() const
|
2014-10-09 16:49:51 +04:00
|
|
|
{
|
|
|
|
return !_file.isEmpty()
|
2014-11-08 13:11:25 +03:00
|
|
|
&& (!_lastTryEtag.isEmpty() || _lastTryModtime != 0)
|
2017-01-13 16:44:45 +03:00
|
|
|
&& _lastTryTime > 0;
|
2014-10-09 16:49:51 +04:00
|
|
|
}
|
|
|
|
|
2014-10-23 17:15:47 +04:00
|
|
|
bool operator==(const SyncJournalFileRecord &lhs,
|
|
|
|
const SyncJournalFileRecord &rhs)
|
|
|
|
{
|
|
|
|
return lhs._path == rhs._path
|
|
|
|
&& lhs._inode == rhs._inode
|
2015-11-25 23:11:58 +03:00
|
|
|
&& lhs._modtime.toTime_t() == rhs._modtime.toTime_t()
|
2014-10-23 17:15:47 +04:00
|
|
|
&& lhs._type == rhs._type
|
|
|
|
&& lhs._etag == rhs._etag
|
|
|
|
&& lhs._fileId == rhs._fileId
|
2015-10-28 13:00:03 +03:00
|
|
|
&& lhs._fileSize == rhs._fileSize
|
2014-10-23 17:15:47 +04:00
|
|
|
&& lhs._remotePerm == rhs._remotePerm
|
2015-10-28 13:00:03 +03:00
|
|
|
&& lhs._serverHasIgnoredFiles == rhs._serverHasIgnoredFiles
|
2017-06-14 13:14:46 +03:00
|
|
|
&& lhs._checksumHeader == rhs._checksumHeader;
|
2014-10-23 17:15:47 +04:00
|
|
|
}
|
2013-10-03 17:27:29 +04:00
|
|
|
}
|