зеркало из https://github.com/nextcloud/desktop.git
SyncJournalDB: Add filesize column to metadata.
* Alter table to include column. * Make get/set in SyncJournalDB store and load it. * Make csync recover the stat_t's size member from it.
This commit is contained in:
Родитель
dc1e73dcb7
Коммит
4e20a02fe5
|
@ -279,6 +279,9 @@ static int _csync_file_stat_from_metadata_table( csync_file_stat_t **st, sqlite3
|
|||
(char*) sqlite3_column_text(stmt, 11),
|
||||
REMOTE_PERM_BUF_SIZE);
|
||||
}
|
||||
if(column_count > 12 && sqlite3_column_int64(stmt,12)) {
|
||||
(*st)->size = sqlite3_column_int64(stmt, 12);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if( rc != SQLITE_DONE ) {
|
||||
|
@ -431,7 +434,7 @@ char *csync_statedb_get_etag( CSYNC *ctx, uint64_t jHash ) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
#define BELOW_PATH_QUERY "SELECT phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm FROM metadata WHERE pathlen>? AND path LIKE(?)"
|
||||
#define BELOW_PATH_QUERY "SELECT phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm, filesize FROM metadata WHERE pathlen>? AND path LIKE(?)"
|
||||
|
||||
int csync_statedb_get_below_path( CSYNC *ctx, const char *path ) {
|
||||
int rc;
|
||||
|
|
|
@ -283,13 +283,13 @@ bool SyncJournalDb::checkConnect()
|
|||
}
|
||||
|
||||
_getFileRecordQuery.reset(new SqlQuery(_db));
|
||||
_getFileRecordQuery->prepare("SELECT path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm FROM "
|
||||
_getFileRecordQuery->prepare("SELECT path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm, filesize FROM "
|
||||
"metadata WHERE phash=?1" );
|
||||
|
||||
_setFileRecordQuery.reset(new SqlQuery(_db) );
|
||||
_setFileRecordQuery->prepare("INSERT OR REPLACE INTO metadata "
|
||||
"(phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm) "
|
||||
"VALUES (?1 , ?2, ?3 , ?4 , ?5 , ?6 , ?7, ?8 , ?9 , ?10, ?11, ?12);" );
|
||||
"(phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm, filesize) "
|
||||
"VALUES (?1 , ?2, ?3 , ?4 , ?5 , ?6 , ?7, ?8 , ?9 , ?10, ?11, ?12, ?13);" );
|
||||
|
||||
_getDownloadInfoQuery.reset(new SqlQuery(_db) );
|
||||
_getDownloadInfoQuery->prepare( "SELECT tmpfile, etag, errorcount FROM "
|
||||
|
@ -412,6 +412,16 @@ bool SyncJournalDb::updateMetadataTableStructure()
|
|||
}
|
||||
commitInternal("update database structure (remotePerm)");
|
||||
}
|
||||
if( columns.indexOf(QLatin1String("filesize")) == -1 )
|
||||
{
|
||||
SqlQuery query(_db);
|
||||
query.prepare("ALTER TABLE metadata ADD COLUMN filesize BIGINT;");
|
||||
if( !query.exec()) {
|
||||
sqlFail("updateDatabaseStructure: add column filesize", query);
|
||||
re = false;
|
||||
}
|
||||
commitInternal("update database structure: add filesize col");
|
||||
}
|
||||
|
||||
if( 1 ) {
|
||||
SqlQuery query(_db);
|
||||
|
@ -547,6 +557,7 @@ bool SyncJournalDb::setFileRecord( const SyncJournalFileRecord& _record )
|
|||
_setFileRecordQuery->bindValue(10, etag );
|
||||
_setFileRecordQuery->bindValue(11, fileId );
|
||||
_setFileRecordQuery->bindValue(12, remotePerm );
|
||||
_setFileRecordQuery->bindValue(13, record._fileSize );
|
||||
|
||||
if( !_setFileRecordQuery->exec() ) {
|
||||
qWarning() << "Error SQL statement setFileRecord: " << _setFileRecordQuery->lastQuery() << " :"
|
||||
|
@ -557,7 +568,7 @@ bool SyncJournalDb::setFileRecord( const SyncJournalFileRecord& _record )
|
|||
qDebug() << _setFileRecordQuery->lastQuery() << phash << plen << record._path << record._inode
|
||||
<< record._mode
|
||||
<< QString::number(Utility::qDateTimeToTime_t(record._modtime)) << QString::number(record._type)
|
||||
<< record._etag << record._fileId << record._remotePerm;
|
||||
<< record._etag << record._fileId << record._remotePerm << record._fileSize;
|
||||
|
||||
_setFileRecordQuery->reset();
|
||||
return true;
|
||||
|
@ -635,6 +646,7 @@ SyncJournalFileRecord SyncJournalDb::getFileRecord( const QString& filename )
|
|||
rec._etag = _getFileRecordQuery->baValue(7);
|
||||
rec._fileId = _getFileRecordQuery->baValue(8);
|
||||
rec._remotePerm = _getFileRecordQuery->baValue(9);
|
||||
rec._fileSize = _getFileRecordQuery->int64Value(10);
|
||||
} else {
|
||||
QString err = _getFileRecordQuery->error();
|
||||
qDebug() << "No journal entry found for " << filename;
|
||||
|
|
|
@ -33,8 +33,8 @@ SyncJournalFileRecord::SyncJournalFileRecord()
|
|||
|
||||
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), _remotePerm(item._remotePerm),
|
||||
_mode(0)
|
||||
_type(item._type), _etag(item._etag), _fileId(item._fileId), _fileSize(item._size),
|
||||
_remotePerm(item._remotePerm), _mode(0)
|
||||
{
|
||||
// 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
|
||||
|
@ -149,7 +149,8 @@ bool operator==(const SyncJournalFileRecord & lhs,
|
|||
&& lhs._etag == rhs._etag
|
||||
&& lhs._fileId == rhs._fileId
|
||||
&& lhs._remotePerm == rhs._remotePerm
|
||||
&& lhs._mode == rhs._mode;
|
||||
&& lhs._mode == rhs._mode
|
||||
&& lhs._fileSize == rhs._fileSize;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
int _type;
|
||||
QByteArray _etag;
|
||||
QByteArray _fileId;
|
||||
qint64 _fileSize;
|
||||
QByteArray _remotePerm;
|
||||
int _mode;
|
||||
};
|
||||
|
|
|
@ -59,6 +59,7 @@ private slots:
|
|||
record._fileId = "abcd";
|
||||
record._remotePerm = "744";
|
||||
record._mode = -17;
|
||||
record._fileSize = 213089055;
|
||||
QVERIFY(_db.setFileRecord(record));
|
||||
|
||||
SyncJournalFileRecord storedRecord = _db.getFileRecord("foo");
|
||||
|
|
Загрузка…
Ссылка в новой задаче