Welcome to mirror list, hosted at ThFree Co, Russian Federation.

localdiscoverytracker.cpp « libsync « src - github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cfc626a80839e58d022efc4d681fc14d43eb9e77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * Copyright (C) by Christian Kamm <mail@ckamm.de>
 *
 * 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; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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 "localdiscoverytracker.h"

#include "syncfileitem.h"

#include <QLoggingCategory>

using namespace OCC;

Q_LOGGING_CATEGORY(lcLocalDiscoveryTracker, "sync.localdiscoverytracker", QtInfoMsg)

LocalDiscoveryTracker::LocalDiscoveryTracker()
{
}

void LocalDiscoveryTracker::addTouchedPath(const QString &relativePath)
{
    qCDebug(lcLocalDiscoveryTracker) << "inserted touched" << relativePath;
    _localDiscoveryPaths.insert(relativePath);
}

void LocalDiscoveryTracker::startSyncFullDiscovery()
{
    _localDiscoveryPaths.clear();
    _previousLocalDiscoveryPaths.clear();
    qCDebug(lcLocalDiscoveryTracker) << "full discovery";
}

void LocalDiscoveryTracker::startSyncPartialDiscovery()
{
    if (lcLocalDiscoveryTracker().isDebugEnabled()) {
        QStringList paths;
        for (auto &path : _localDiscoveryPaths)
            paths.append(path);
        qCDebug(lcLocalDiscoveryTracker) << "partial discovery with paths: " << paths;
    }

    _previousLocalDiscoveryPaths = std::move(_localDiscoveryPaths);
    _localDiscoveryPaths.clear();
}

const std::set<QString> &LocalDiscoveryTracker::localDiscoveryPaths() const
{
    return _localDiscoveryPaths;
}

void LocalDiscoveryTracker::slotItemCompleted(const SyncFileItemPtr &item)
{
    // For successes, we want to wipe the file from the list to ensure we don't
    // rediscover it even if this overall sync fails.
    //
    // For failures, we want to add the file to the list so the next sync
    // will be able to retry it.

    switch (item->_status) {
    case SyncFileItem::NoStatus:
        // we can't use the flags operator with CSYNC_INSTRUCTION_NONE
        if (item->_instruction != CSYNC_INSTRUCTION_NONE && item->_instruction != CSYNC_INSTRUCTION_UPDATE_METADATA) {
            break;
        }
        Q_FALLTHROUGH();
    case SyncFileItem::Success:
        Q_FALLTHROUGH();
    case SyncFileItem::FileIgnored:
        Q_FALLTHROUGH();
    case SyncFileItem::Restoration:
        Q_FALLTHROUGH();
    case SyncFileItem::Conflict:
        Q_FALLTHROUGH();
    case OCC::SyncFileItem::Message:
        if (_previousLocalDiscoveryPaths.erase(item->_file)) {
            qCDebug(lcLocalDiscoveryTracker) << "wiped successful item" << item->_file;
        }
        if (!item->_renameTarget.isEmpty() && _previousLocalDiscoveryPaths.erase(item->_renameTarget)) {
            qCDebug(lcLocalDiscoveryTracker) << "wiped successful item" << item->_renameTarget;
        }
        return;
    case OCC::SyncFileItem::FatalError:
        Q_FALLTHROUGH();
    case OCC::SyncFileItem::NormalError:
        Q_FALLTHROUGH();
    case OCC::SyncFileItem::SoftError:
        Q_FALLTHROUGH();
    case OCC::SyncFileItem::DetailError:
        Q_FALLTHROUGH();
    case OCC::SyncFileItem::BlacklistedError:
        Q_FALLTHROUGH();
    case OCC::SyncFileItem::Excluded:
        break;
    case SyncFileItem::StatusCount:
        Q_UNREACHABLE();
    }

    _localDiscoveryPaths.insert(item->_file);
    qCDebug(lcLocalDiscoveryTracker) << "inserted error item" << item->_file;
}

void LocalDiscoveryTracker::slotSyncFinished(bool success)
{
    if (success) {
        qCDebug(lcLocalDiscoveryTracker) << "sync success, forgetting last sync's local discovery path list";
    } else {
        // On overall-failure we can't forget about last sync's local discovery
        // paths yet, reuse them for the next sync again.
        // C++17: Could use std::set::merge().
        _localDiscoveryPaths.insert(
            _previousLocalDiscoveryPaths.begin(), _previousLocalDiscoveryPaths.end());
        qCDebug(lcLocalDiscoveryTracker) << "sync failed, keeping last sync's local discovery path list";
    }
    _previousLocalDiscoveryPaths.clear();
}