owncloudpropagator.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. /*
  2. * Copyright (C) by Olivier Goffart <ogoffart@owncloud.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. */
  14. #ifndef OWNCLOUDPROPAGATOR_H
  15. #define OWNCLOUDPROPAGATOR_H
  16. #include <QHash>
  17. #include <QObject>
  18. #include <QMap>
  19. #include <QElapsedTimer>
  20. #include <QTimer>
  21. #include <QPointer>
  22. #include <QIODevice>
  23. #include <QMutex>
  24. #include "csync.h"
  25. #include "syncfileitem.h"
  26. #include "common/syncjournaldb.h"
  27. #include "bandwidthmanager.h"
  28. #include "accountfwd.h"
  29. #include "syncoptions.h"
  30. #include <deque>
  31. namespace OCC {
  32. Q_DECLARE_LOGGING_CATEGORY(lcPropagator)
  33. /** Free disk space threshold below which syncs will abort and not even start.
  34. */
  35. qint64 criticalFreeSpaceLimit();
  36. /** The client will not intentionally reduce the available free disk space below
  37. * this limit.
  38. *
  39. * Uploads will still run and downloads that are small enough will continue too.
  40. */
  41. qint64 freeSpaceLimit();
  42. void blacklistUpdate(SyncJournalDb *journal, SyncFileItem &item);
  43. class SyncJournalDb;
  44. class OwncloudPropagator;
  45. class PropagatorCompositeJob;
  46. /**
  47. * @brief the base class of propagator jobs
  48. *
  49. * This can either be a job, or a container for jobs.
  50. * If it is a composite job, it then inherits from PropagateDirectory
  51. *
  52. * @ingroup libsync
  53. */
  54. class PropagatorJob : public QObject
  55. {
  56. Q_OBJECT
  57. public:
  58. explicit PropagatorJob(OwncloudPropagator *propagator);
  59. enum AbortType {
  60. Synchronous,
  61. Asynchronous
  62. };
  63. Q_ENUM(AbortType)
  64. enum JobState {
  65. NotYetStarted,
  66. Running,
  67. Finished
  68. };
  69. JobState _state;
  70. Q_ENUM(JobState)
  71. enum JobParallelism {
  72. /** Jobs can be run in parallel to this job */
  73. FullParallelism,
  74. /** No other job shall be started until this one has finished.
  75. So this job is guaranteed to finish before any jobs below it
  76. are executed. */
  77. WaitForFinished,
  78. };
  79. Q_ENUM(JobParallelism)
  80. virtual JobParallelism parallelism() { return FullParallelism; }
  81. /**
  82. * For "small" jobs
  83. */
  84. virtual bool isLikelyFinishedQuickly() { return false; }
  85. /** The space that the running jobs need to complete but don't actually use yet.
  86. *
  87. * Note that this does *not* include the disk space that's already
  88. * in use by running jobs for things like a download-in-progress.
  89. */
  90. [[nodiscard]] virtual qint64 committedDiskSpace() const { return 0; }
  91. /** Set the associated composite job
  92. *
  93. * Used only from PropagatorCompositeJob itself, when a job is added
  94. * and from PropagateDirectory to associate the subJobs with the first
  95. * job.
  96. */
  97. void setAssociatedComposite(PropagatorCompositeJob *job) { _associatedComposite = job; }
  98. public slots:
  99. /*
  100. * Asynchronous abort requires emit of abortFinished() signal,
  101. * while synchronous is expected to abort immedietaly.
  102. */
  103. virtual void abort(PropagatorJob::AbortType abortType) {
  104. if (abortType == AbortType::Asynchronous)
  105. emit abortFinished();
  106. }
  107. /** Starts this job, or a new subjob
  108. * returns true if a job was started.
  109. */
  110. virtual bool scheduleSelfOrChild() = 0;
  111. signals:
  112. /**
  113. * Emitted when the job is fully finished
  114. */
  115. void finished(SyncFileItem::Status);
  116. /**
  117. * Emitted when the abort is fully finished
  118. */
  119. void abortFinished(SyncFileItem::Status status = SyncFileItem::NormalError);
  120. protected:
  121. [[nodiscard]] OwncloudPropagator *propagator() const;
  122. /** If this job gets added to a composite job, this will point to the parent.
  123. *
  124. * For the PropagateDirectory::_firstJob it will point to
  125. * PropagateDirectory::_subJobs.
  126. *
  127. * That can be useful for jobs that want to spawn follow-up jobs without
  128. * becoming composite jobs themselves.
  129. */
  130. PropagatorCompositeJob *_associatedComposite = nullptr;
  131. };
  132. /*
  133. * Abstract class to propagate a single item
  134. */
  135. class PropagateItemJob : public PropagatorJob
  136. {
  137. Q_OBJECT
  138. protected:
  139. virtual void done(SyncFileItem::Status status, const QString &errorString = QString());
  140. /*
  141. * set a custom restore job message that is used if the restore job succeeded.
  142. * It is displayed in the activity view.
  143. */
  144. [[nodiscard]] QString restoreJobMsg() const
  145. {
  146. return _item->_isRestoration ? _item->_errorString : QString();
  147. }
  148. void setRestoreJobMsg(const QString &msg = QString())
  149. {
  150. _item->_isRestoration = true;
  151. _item->_errorString = msg;
  152. }
  153. [[nodiscard]] bool hasEncryptedAncestor() const;
  154. protected slots:
  155. void slotRestoreJobFinished(SyncFileItem::Status status);
  156. private:
  157. QScopedPointer<PropagateItemJob> _restoreJob;
  158. JobParallelism _parallelism;
  159. public:
  160. PropagateItemJob(OwncloudPropagator *propagator, const SyncFileItemPtr &item)
  161. : PropagatorJob(propagator)
  162. , _parallelism(FullParallelism)
  163. , _item(item)
  164. {
  165. // we should always execute jobs that process the E2EE API calls as sequential jobs
  166. // TODO: In fact, we must make sure Lock/Unlock are not colliding and always wait for each other to complete. So, we could refactor this "_parallelism" later
  167. // so every "PropagateItemJob" that will potentially execute Lock job on E2EE folder will get executed sequentially.
  168. // As an alternative, we could optimize Lock/Unlock calls, so we do a batch-write on one folder and only lock and unlock a folder once per batch.
  169. _parallelism = (_item->_isEncrypted || hasEncryptedAncestor()) ? WaitForFinished : FullParallelism;
  170. }
  171. ~PropagateItemJob() override;
  172. bool scheduleSelfOrChild() override
  173. {
  174. if (_state != NotYetStarted) {
  175. return false;
  176. }
  177. qCInfo(lcPropagator) << "Starting" << _item->_instruction << "propagation of" << _item->destination() << "by" << this;
  178. _state = Running;
  179. QMetaObject::invokeMethod(this, "start"); // We could be in a different thread (neon jobs)
  180. return true;
  181. }
  182. JobParallelism parallelism() override { return _parallelism; }
  183. SyncFileItemPtr _item;
  184. public slots:
  185. virtual void start() = 0;
  186. };
  187. /**
  188. * @brief Job that runs subjobs. It becomes finished only when all subjobs are finished.
  189. * @ingroup libsync
  190. */
  191. class PropagatorCompositeJob : public PropagatorJob
  192. {
  193. Q_OBJECT
  194. public:
  195. QVector<PropagatorJob *> _jobsToDo;
  196. SyncFileItemVector _tasksToDo;
  197. QVector<PropagatorJob *> _runningJobs;
  198. SyncFileItem::Status _hasError; // NoStatus, or NormalError / SoftError if there was an error
  199. quint64 _abortsCount;
  200. explicit PropagatorCompositeJob(OwncloudPropagator *propagator)
  201. : PropagatorJob(propagator)
  202. , _hasError(SyncFileItem::NoStatus), _abortsCount(0)
  203. {
  204. }
  205. // Don't delete jobs in _jobsToDo and _runningJobs: they have parents
  206. // that will be responsible for cleanup. Deleting them here would risk
  207. // deleting something that has already been deleted by a shared parent.
  208. ~PropagatorCompositeJob() override = default;
  209. void appendJob(PropagatorJob *job);
  210. void appendTask(const SyncFileItemPtr &item)
  211. {
  212. _tasksToDo.append(item);
  213. }
  214. bool scheduleSelfOrChild() override;
  215. JobParallelism parallelism() override;
  216. /*
  217. * Abort synchronously or asynchronously - some jobs
  218. * require to be finished without immediete abort (abort on job might
  219. * cause conflicts/duplicated files - owncloud/client/issues/5949)
  220. */
  221. void abort(PropagatorJob::AbortType abortType) override
  222. {
  223. if (!_runningJobs.empty()) {
  224. _abortsCount = _runningJobs.size();
  225. foreach (PropagatorJob *j, _runningJobs) {
  226. if (abortType == AbortType::Asynchronous) {
  227. connect(j, &PropagatorJob::abortFinished,
  228. this, &PropagatorCompositeJob::slotSubJobAbortFinished);
  229. }
  230. j->abort(abortType);
  231. }
  232. } else if (abortType == AbortType::Asynchronous){
  233. emit abortFinished();
  234. }
  235. }
  236. [[nodiscard]] qint64 committedDiskSpace() const override;
  237. private slots:
  238. void slotSubJobAbortFinished();
  239. bool possiblyRunNextJob(OCC::PropagatorJob *next)
  240. {
  241. if (next->_state == NotYetStarted) {
  242. connect(next, &PropagatorJob::finished, this, &PropagatorCompositeJob::slotSubJobFinished);
  243. }
  244. return next->scheduleSelfOrChild();
  245. }
  246. void slotSubJobFinished(OCC::SyncFileItem::Status status);
  247. void finalize();
  248. };
  249. /**
  250. * @brief Propagate a directory, and all its sub entries.
  251. * @ingroup libsync
  252. */
  253. class OWNCLOUDSYNC_EXPORT PropagateDirectory : public PropagatorJob
  254. {
  255. Q_OBJECT
  256. public:
  257. SyncFileItemPtr _item;
  258. // e.g: create the directory
  259. QScopedPointer<PropagateItemJob> _firstJob;
  260. PropagatorCompositeJob _subJobs;
  261. explicit PropagateDirectory(OwncloudPropagator *propagator, const SyncFileItemPtr &item);
  262. void appendJob(PropagatorJob *job)
  263. {
  264. _subJobs.appendJob(job);
  265. }
  266. void appendTask(const SyncFileItemPtr &item)
  267. {
  268. _subJobs.appendTask(item);
  269. }
  270. bool scheduleSelfOrChild() override;
  271. JobParallelism parallelism() override;
  272. void abort(PropagatorJob::AbortType abortType) override
  273. {
  274. if (_firstJob)
  275. // Force first job to abort synchronously
  276. // even if caller allows async abort (asyncAbort)
  277. _firstJob->abort(AbortType::Synchronous);
  278. if (abortType == AbortType::Asynchronous){
  279. connect(&_subJobs, &PropagatorCompositeJob::abortFinished, this, &PropagateDirectory::abortFinished);
  280. }
  281. _subJobs.abort(abortType);
  282. }
  283. void increaseAffectedCount()
  284. {
  285. _firstJob->_item->_affectedItems++;
  286. }
  287. [[nodiscard]] qint64 committedDiskSpace() const override
  288. {
  289. return _subJobs.committedDiskSpace();
  290. }
  291. private slots:
  292. void slotFirstJobFinished(OCC::SyncFileItem::Status status);
  293. virtual void slotSubJobsFinished(OCC::SyncFileItem::Status status);
  294. };
  295. /**
  296. * @brief Propagate the root directory, and all its sub entries.
  297. * @ingroup libsync
  298. *
  299. * Primary difference to PropagateDirectory is that it keeps track of directory
  300. * deletions that must happen at the very end.
  301. */
  302. class OWNCLOUDSYNC_EXPORT PropagateRootDirectory : public PropagateDirectory
  303. {
  304. Q_OBJECT
  305. public:
  306. explicit PropagateRootDirectory(OwncloudPropagator *propagator);
  307. bool scheduleSelfOrChild() override;
  308. JobParallelism parallelism() override;
  309. void abort(PropagatorJob::AbortType abortType) override;
  310. [[nodiscard]] qint64 committedDiskSpace() const override;
  311. public slots:
  312. void appendDirDeletionJob(OCC::PropagatorJob *job);
  313. private slots:
  314. void slotSubJobsFinished(OCC::SyncFileItem::Status status) override;
  315. void slotDirDeletionJobsFinished(OCC::SyncFileItem::Status status);
  316. private:
  317. bool scheduleDelayedJobs();
  318. PropagatorCompositeJob _dirDeletionJobs;
  319. SyncFileItem::Status _errorStatus = SyncFileItem::Status::NoStatus;
  320. };
  321. /**
  322. * @brief Dummy job that just mark it as completed and ignored
  323. * @ingroup libsync
  324. */
  325. class PropagateIgnoreJob : public PropagateItemJob
  326. {
  327. Q_OBJECT
  328. public:
  329. PropagateIgnoreJob(OwncloudPropagator *propagator, const SyncFileItemPtr &item)
  330. : PropagateItemJob(propagator, item)
  331. {
  332. }
  333. void start() override;
  334. };
  335. class PropagateUploadFileCommon;
  336. class OWNCLOUDSYNC_EXPORT OwncloudPropagator : public QObject
  337. {
  338. Q_OBJECT
  339. public:
  340. SyncJournalDb *const _journal;
  341. bool _finishedEmited; // used to ensure that finished is only emitted once
  342. public:
  343. OwncloudPropagator(AccountPtr account, const QString &localDir,
  344. const QString &remoteFolder, SyncJournalDb *progressDb,
  345. QSet<QString> &bulkUploadBlackList)
  346. : _journal(progressDb)
  347. , _finishedEmited(false)
  348. , _bandwidthManager(this)
  349. , _anotherSyncNeeded(false)
  350. , _chunkSize(10 * 1000 * 1000) // 10 MB, overridden in setSyncOptions
  351. , _account(account)
  352. , _localDir((localDir.endsWith(QChar('/'))) ? localDir : localDir + '/')
  353. , _remoteFolder((remoteFolder.endsWith(QChar('/'))) ? remoteFolder : remoteFolder + '/')
  354. , _bulkUploadBlackList(bulkUploadBlackList)
  355. {
  356. qRegisterMetaType<PropagatorJob::AbortType>("PropagatorJob::AbortType");
  357. }
  358. ~OwncloudPropagator() override;
  359. void start(SyncFileItemVector &&_syncedItems);
  360. void startDirectoryPropagation(const SyncFileItemPtr &item,
  361. QStack<QPair<QString, PropagateDirectory*>> &directories,
  362. QVector<PropagatorJob *> &directoriesToRemove,
  363. QString &removedDirectory,
  364. const SyncFileItemVector &items);
  365. void startFilePropagation(const SyncFileItemPtr &item,
  366. QStack<QPair<QString, PropagateDirectory*>> &directories,
  367. QVector<PropagatorJob *> &directoriesToRemove,
  368. QString &removedDirectory,
  369. QString &maybeConflictDirectory);
  370. [[nodiscard]] const SyncOptions &syncOptions() const;
  371. void setSyncOptions(const SyncOptions &syncOptions);
  372. int _downloadLimit = 0;
  373. int _uploadLimit = 0;
  374. BandwidthManager _bandwidthManager;
  375. bool _abortRequested = false;
  376. /** The list of currently active jobs.
  377. This list contains the jobs that are currently using ressources and is used purely to
  378. know how many jobs there is currently running for the scheduler.
  379. Jobs add themself to the list when they do an assynchronous operation.
  380. Jobs can be several time on the list (example, when several chunks are uploaded in parallel)
  381. */
  382. QList<PropagateItemJob *> _activeJobList;
  383. /** We detected that another sync is required after this one */
  384. bool _anotherSyncNeeded;
  385. /** Per-folder quota guesses.
  386. *
  387. * This starts out empty. When an upload in a folder fails due to insufficent
  388. * remote quota, the quota guess is updated to be attempted_size-1 at maximum.
  389. *
  390. * Note that it will usually just an upper limit for the actual quota - but
  391. * since the quota on the server might change at any time it can sometimes be
  392. * wrong in the other direction as well.
  393. *
  394. * This allows skipping of uploads that have a very high likelihood of failure.
  395. */
  396. QHash<QString, qint64> _folderQuota;
  397. /* the maximum number of jobs using bandwidth (uploads or downloads, in parallel) */
  398. int maximumActiveTransferJob();
  399. /** The size to use for upload chunks.
  400. *
  401. * Will be dynamically adjusted after each chunk upload finishes
  402. * if Capabilities::desiredChunkUploadDuration has a target
  403. * chunk-upload duration set.
  404. */
  405. qint64 _chunkSize;
  406. qint64 smallFileSize();
  407. /* The maximum number of active jobs in parallel */
  408. int hardMaximumActiveJob();
  409. /** Check whether a download would clash with an existing file
  410. * in filesystems that are only case-preserving.
  411. */
  412. bool localFileNameClash(const QString &relfile);
  413. /** Check whether a file is properly accessible for upload.
  414. *
  415. * It is possible to create files with filenames that differ
  416. * only by case in NTFS, but most operations such as stat and
  417. * open only target one of these by default.
  418. *
  419. * When that happens, we want to avoid uploading incorrect data
  420. * and give up on the file.
  421. */
  422. bool hasCaseClashAccessibilityProblem(const QString &relfile);
  423. Q_REQUIRED_RESULT QString fullLocalPath(const QString &tmp_file_name) const;
  424. [[nodiscard]] QString localPath() const;
  425. /**
  426. * Returns the full remote path including the folder root of a
  427. * folder sync path.
  428. */
  429. Q_REQUIRED_RESULT QString fullRemotePath(const QString &tmp_file_name) const;
  430. [[nodiscard]] QString remotePath() const;
  431. /** Creates the job for an item.
  432. */
  433. PropagateItemJob *createJob(const SyncFileItemPtr &item);
  434. void scheduleNextJob();
  435. void reportProgress(const SyncFileItem &, qint64 bytes);
  436. void abort()
  437. {
  438. if (_abortRequested)
  439. return;
  440. _abortRequested = true;
  441. if (_rootJob) {
  442. // Connect to abortFinished which signals that abort has been asynchronously finished
  443. connect(_rootJob.data(), &PropagateDirectory::abortFinished, this, &OwncloudPropagator::emitFinished);
  444. // Use Queued Connection because we're possibly already in an item's finished stack
  445. QMetaObject::invokeMethod(_rootJob.data(), "abort", Qt::QueuedConnection,
  446. Q_ARG(PropagatorJob::AbortType, PropagatorJob::AbortType::Asynchronous));
  447. // Give asynchronous abort 5000 msec to finish on its own
  448. QTimer::singleShot(5000, this, SLOT(abortTimeout()));
  449. } else {
  450. // No root job, call emitFinished
  451. emitFinished(SyncFileItem::NormalError);
  452. }
  453. }
  454. [[nodiscard]] AccountPtr account() const;
  455. enum DiskSpaceResult {
  456. DiskSpaceOk,
  457. DiskSpaceFailure,
  458. DiskSpaceCritical
  459. };
  460. /** Checks whether there's enough disk space available to complete
  461. * all jobs that are currently running.
  462. */
  463. [[nodiscard]] DiskSpaceResult diskSpaceCheck() const;
  464. /** Handles a conflict by renaming the file 'item'.
  465. *
  466. * Sets up conflict records.
  467. *
  468. * It also creates a new upload job in composite if the item that's
  469. * moved away is a file and conflict uploads are requested.
  470. *
  471. * Returns true on success, false and error on error.
  472. */
  473. bool createConflict(const SyncFileItemPtr &item,
  474. PropagatorCompositeJob *composite, QString *error);
  475. /** Handles a case clash conflict by renaming the file 'item'.
  476. *
  477. * Sets up conflict records.
  478. *
  479. * Returns true on success, false and error on error.
  480. */
  481. OCC::Optional<QString> createCaseClashConflict(const SyncFileItemPtr &item, const QString &temporaryDownloadedFile);
  482. // Map original path (as in the DB) to target final path
  483. QMap<QString, QString> _renamedDirectories;
  484. [[nodiscard]] QString adjustRenamedPath(const QString &original) const;
  485. /** Update the database for an item.
  486. *
  487. * Typically after a sync operation succeeded. Updates the inode from
  488. * the filesystem.
  489. *
  490. * Will also trigger a Vfs::convertToPlaceholder.
  491. */
  492. Result<Vfs::ConvertToPlaceholderResult, QString> updateMetadata(const SyncFileItem &item);
  493. /** Update the database for an item.
  494. *
  495. * Typically after a sync operation succeeded. Updates the inode from
  496. * the filesystem.
  497. *
  498. * Will also trigger a Vfs::convertToPlaceholder.
  499. */
  500. static Result<Vfs::ConvertToPlaceholderResult, QString> staticUpdateMetadata(const SyncFileItem &item, const QString localDir,
  501. Vfs *vfs, SyncJournalDb * const journal);
  502. Q_REQUIRED_RESULT bool isDelayedUploadItem(const SyncFileItemPtr &item) const;
  503. Q_REQUIRED_RESULT const std::deque<SyncFileItemPtr>& delayedTasks() const
  504. {
  505. return _delayedTasks;
  506. }
  507. void setScheduleDelayedTasks(bool active);
  508. void clearDelayedTasks();
  509. void addToBulkUploadBlackList(const QString &file);
  510. void removeFromBulkUploadBlackList(const QString &file);
  511. [[nodiscard]] bool isInBulkUploadBlackList(const QString &file) const;
  512. private slots:
  513. void abortTimeout()
  514. {
  515. // Abort synchronously and finish
  516. _rootJob.data()->abort(PropagatorJob::AbortType::Synchronous);
  517. emitFinished(SyncFileItem::NormalError);
  518. }
  519. /** Emit the finished signal and make sure it is only emitted once */
  520. void emitFinished(OCC::SyncFileItem::Status status)
  521. {
  522. if (!_finishedEmited)
  523. emit finished(status == SyncFileItem::Success);
  524. _abortRequested = false;
  525. _finishedEmited = true;
  526. }
  527. void scheduleNextJobImpl();
  528. signals:
  529. void newItem(const OCC::SyncFileItemPtr &);
  530. void itemCompleted(const OCC::SyncFileItemPtr &);
  531. void progress(const OCC::SyncFileItem &, qint64 bytes);
  532. void finished(bool success);
  533. /** Emitted when propagation has problems with a locked file. */
  534. void seenLockedFile(const QString &fileName);
  535. /** Emitted when propagation touches a file.
  536. *
  537. * Used to track our own file modifications such that notifications
  538. * from the file watcher about these can be ignored.
  539. */
  540. void touchedFile(const QString &fileName);
  541. void insufficientLocalStorage();
  542. void insufficientRemoteStorage();
  543. private:
  544. std::unique_ptr<PropagateUploadFileCommon> createUploadJob(SyncFileItemPtr item,
  545. bool deleteExisting);
  546. void pushDelayedUploadTask(SyncFileItemPtr item);
  547. void resetDelayedUploadTasks();
  548. static void adjustDeletedFoldersWithNewChildren(SyncFileItemVector &items);
  549. AccountPtr _account;
  550. QScopedPointer<PropagateRootDirectory> _rootJob;
  551. SyncOptions _syncOptions;
  552. bool _jobScheduled = false;
  553. const QString _localDir; // absolute path to the local directory. ends with '/'
  554. const QString _remoteFolder; // remote folder, ends with '/'
  555. std::deque<SyncFileItemPtr> _delayedTasks;
  556. bool _scheduleDelayedTasks = false;
  557. QSet<QString> &_bulkUploadBlackList;
  558. static bool _allowDelayedUpload;
  559. };
  560. /**
  561. * @brief Job that wait for all the poll jobs to be completed
  562. * @ingroup libsync
  563. */
  564. class CleanupPollsJob : public QObject
  565. {
  566. Q_OBJECT
  567. QVector<SyncJournalDb::PollInfo> _pollInfos;
  568. AccountPtr _account;
  569. SyncJournalDb *_journal;
  570. QString _localPath;
  571. QSharedPointer<Vfs> _vfs;
  572. public:
  573. explicit CleanupPollsJob(AccountPtr account,
  574. SyncJournalDb *journal,
  575. const QString &localPath,
  576. const QSharedPointer<Vfs> &vfs,
  577. QObject *parent = nullptr)
  578. : QObject(parent)
  579. , _pollInfos(journal->getPollInfos())
  580. , _account(account)
  581. , _journal(journal)
  582. , _localPath(localPath)
  583. , _vfs(vfs)
  584. {
  585. }
  586. ~CleanupPollsJob() override;
  587. /**
  588. * Start the job. After the job is completed, it will emit either finished or aborted, and it
  589. * will destroy itself.
  590. */
  591. void start();
  592. signals:
  593. void finished();
  594. void aborted(const QString &error);
  595. private slots:
  596. void slotPollFinished();
  597. };
  598. }
  599. #endif