nextcloud-desktop/src/mirall/syncjournalfilerecord.cpp

87 lines
2.7 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; 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 "syncjournalfilerecord.h"
2013-10-03 22:00:58 +04:00
#include "syncfileitem.h"
#include "utility.h"
2013-10-04 22:29:42 +04:00
2013-10-03 22:00:58 +04:00
#include <qfileinfo.h>
#include <qdebug.h>
2013-10-03 22:00:58 +04:00
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
namespace Mirall {
SyncJournalFileRecord::SyncJournalFileRecord()
2013-12-06 17:11:51 +04:00
:_inode(0), _type(0), _uid(0), _gid(0), _mode(0)
{
}
2013-10-03 22:00:58 +04:00
SyncJournalFileRecord::SyncJournalFileRecord(const SyncFileItem &item, const QString &localFileName)
: _path(item._file), _modtime(Utility::qDateTimeFromTime_t(item._modtime)),
_type(item._type), _etag(item._etag), _fileId(item._fileId),
_uid(0), _gid(0), _mode(0)
2013-10-03 22:00:58 +04:00
{
// Query the inode:
// based on code from csync_vio_local.c (csync_vio_local_stat)
2013-10-04 22:29:42 +04:00
#ifdef Q_OS_WIN
2013-10-03 22:00:58 +04:00
/* Get the Windows file id as an inode replacement. */
HANDLE h = CreateFileW( (wchar_t*)localFileName.utf16(), 0, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL+FILE_FLAG_BACKUP_SEMANTICS, NULL );
if( h == INVALID_HANDLE_VALUE ) {
_inode = 0;
qWarning() << "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 {
qWarning() << "Failed to query the 'inode' for file " << localFileName;
_inode = 0;
2013-10-03 22:00:58 +04:00
}
CloseHandle(h);
2013-10-03 22:00:58 +04:00
}
#else
struct stat sb;
if( stat(QFile::encodeName(localFileName).constData(), &sb) < 0) {
qWarning() << "Failed to query the 'inode' for file " << localFileName;
_inode = 0;
2013-10-03 22:00:58 +04:00
} else {
_inode = sb.st_ino;
}
#endif
}
SyncJournalBlacklistRecord::SyncJournalBlacklistRecord(const SyncFileItem& item, int retries)
:_retryCount(retries), _errorString(item._errorString), _lastTryModtime(item._modtime)
, _lastTryEtag(item._etag), _file(item._file)
{
}
}