mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 23:28:14 +03:00
Save the progress db once a chunk has been upload
Allow to resume when we cancel the sync
This commit is contained in:
parent
313832de8d
commit
746b86a1dd
2 changed files with 23 additions and 15 deletions
|
@ -235,17 +235,30 @@ csync_instructions_e OwncloudPropagator::remoteMkdir(const SyncFileItem &item)
|
|||
}
|
||||
|
||||
// Log callback for httpbf
|
||||
static void _log_callback(const char *func, const char *text)
|
||||
static void _log_callback(const char *func, const char *text, void*)
|
||||
{
|
||||
qDebug() << func << text;
|
||||
}
|
||||
|
||||
// abort callback for httpbf
|
||||
// FIXME: a bit a pitty we need to use a global variable here.
|
||||
static QAtomicInt *_user_want_abort_ptr;
|
||||
static int _user_want_abort()
|
||||
static int _user_want_abort(void *userData)
|
||||
{
|
||||
return _user_want_abort_ptr->fetchAndAddRelaxed(0);
|
||||
return static_cast<OwncloudPropagator *>(userData)->_abortRequested->fetchAndAddRelaxed(0);
|
||||
}
|
||||
|
||||
// callback from httpbf when a chunk is finished
|
||||
void OwncloudPropagator::chunk_finished_cb(hbf_transfer_s *trans, int chunk, void* userdata)
|
||||
{
|
||||
OwncloudPropagator *that = static_cast<OwncloudPropagator *>(userdata);
|
||||
Q_ASSERT(that);
|
||||
if (trans->block_cnt > 1) {
|
||||
SyncJournalDb::UploadInfo pi;
|
||||
pi._valid = true;
|
||||
pi._chunk = chunk + 1; // next chunk to start with
|
||||
pi._transferid = trans->transfer_id;
|
||||
pi._modtime = QDateTime::fromTime_t(trans->modtime);
|
||||
that->_journal->setUploadInfo(that->_currentFile, pi);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -271,9 +284,10 @@ csync_instructions_e OwncloudPropagator::uploadFile(const SyncFileItem &item)
|
|||
do {
|
||||
Hbf_State state = HBF_SUCCESS;
|
||||
QScopedPointer<hbf_transfer_t, ScopedPointerHelpers> trans(hbf_init_transfer(uri.data()));
|
||||
trans->user_data = this;
|
||||
hbf_set_log_callback(trans.data(), _log_callback);
|
||||
_user_want_abort_ptr = _abortRequested;
|
||||
hbf_set_abort_callback(trans.data(), _user_want_abort);
|
||||
trans.data()->chunk_finished_cb = chunk_finished_cb;
|
||||
finished = true;
|
||||
Q_ASSERT(trans);
|
||||
state = hbf_splitlist(trans.data(), file.handle());
|
||||
|
@ -329,15 +343,6 @@ csync_instructions_e OwncloudPropagator::uploadFile(const SyncFileItem &item)
|
|||
// FIXME: find out the error class.
|
||||
//_httpStatusCode = hbf_fail_http_code(trans.data());
|
||||
_status = SyncFileItem::NormalError;
|
||||
|
||||
if (trans->start_id > 0) {
|
||||
SyncJournalDb::UploadInfo pi;
|
||||
pi._valid = true;
|
||||
pi._chunk = trans->start_id;
|
||||
pi._transferid = trans->transfer_id;
|
||||
pi._modtime = QDateTime::fromTime_t(item._modtime);
|
||||
_journal->setUploadInfo(item._file, pi);
|
||||
}
|
||||
return CSYNC_INSTRUCTION_ERROR;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "syncfileitem.h"
|
||||
#include "progressdispatcher.h"
|
||||
|
||||
struct hbf_transfer_s;
|
||||
struct ne_session_s;
|
||||
struct ne_decompress_s;
|
||||
|
||||
|
@ -70,6 +71,8 @@ class OwncloudPropagator : public QObject {
|
|||
static void notify_status_cb (void *userdata, ne_session_status status,
|
||||
const ne_session_status_info *info);
|
||||
|
||||
static void chunk_finished_cb(hbf_transfer_s *,int, void *userdata);
|
||||
|
||||
public:
|
||||
OwncloudPropagator(ne_session_s *session, const QString &localDir, const QString &remoteDir,
|
||||
SyncJournalDb *progressDb, QAtomicInt *abortRequested)
|
||||
|
|
Loading…
Reference in a new issue