summaryrefslogtreecommitdiff
path: root/FreeFileSync/Source/base/synchronization.h
blob: 6a4f4b0d51a40d406d3551b02d0b57dad3b213cb (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
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under    *
// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0          *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************

#ifndef SYNCHRONIZATION_H_8913470815943295
#define SYNCHRONIZATION_H_8913470815943295

#include <chrono>
#include "structures.h"
#include "file_hierarchy.h"
#include "process_callback.h"


namespace fff
{
class SyncStatistics //count *logical* operations, (create, update, delete + bytes), *not* disk accesses!
{
    //-> note the fundamental difference compared to counting disk accesses!
public:
    explicit SyncStatistics(const FolderComparison& folderCmp);
    explicit SyncStatistics(const ContainerObject& hierObj);
    explicit SyncStatistics(const FilePair& file);

    template <SelectSide side>
    int createCount() const { return selectParam<side>(createLeft_, createRight_); }
    int createCount() const { return createLeft_ + createRight_; }

    template <SelectSide side>
    int updateCount() const { return selectParam<side>(updateLeft_, updateRight_); }
    int updateCount() const { return updateLeft_ + updateRight_; }

    template <SelectSide side>
    int deleteCount() const { return selectParam<side>(deleteLeft_, deleteRight_); }
    int deleteCount() const { return deleteLeft_ + deleteRight_; }

    template <SelectSide side>
    bool expectPhysicalDeletion() const { return selectParam<side>(physicalDeleteLeft_, physicalDeleteRight_); }

    int64_t getBytesToProcess() const { return bytesToProcess_; }
    size_t  rowCount         () const { return rowsTotal_; }

    struct ConflictInfo
    {
        Zstring relPath;
        std::wstring msg;
    };
    const std::vector<ConflictInfo>& getConflictsPreview() const { return conflictsPreview_; }
    int conflictCount() const { return conflictCount_; }

private:
    void recurse(const ContainerObject& hierObj);

    void processFile  (const FilePair& file);
    void processLink  (const SymlinkPair& symlink);
    void processFolder(const FolderPair& folder);

    int createLeft_  = 0;
    int createRight_ = 0;
    int updateLeft_  = 0;
    int updateRight_ = 0;
    int deleteLeft_  = 0;
    int deleteRight_ = 0;
    bool physicalDeleteLeft_  = false; //at least 1 item will be deleted; considers most "update" cases which also delete items
    bool physicalDeleteRight_ = false; //

    int64_t bytesToProcess_ = 0;
    size_t rowsTotal_ = 0;

    int conflictCount_ = 0;
    std::vector<ConflictInfo> conflictsPreview_; //conflict texts to display as a warning message
    //limit conflict count! e.g. there may be hundred thousands of "same date but a different size"
};


struct FolderPairSyncCfg
{
    SyncVariant syncVar;
    bool saveSyncDB; //save database if in automatic mode or dection of moved files is active
    DeletionPolicy handleDeletion;
    Zstring versioningFolderPhrase; //unresolved directory names as entered by user!
    VersioningStyle versioningStyle;
    int versionMaxAgeDays;
    int versionCountMin;
    int versionCountMax;
};
std::vector<FolderPairSyncCfg> extractSyncCfg(const MainConfiguration& mainCfg);


//FFS core routine:
void synchronize(const std::chrono::system_clock::time_point& syncStartTime,
                 bool verifyCopiedFiles,
                 bool copyLockedFiles,
                 bool copyFilePermissions,
                 bool failSafeFileCopy,
                 bool runWithBackgroundPriority,
                 const std::vector<FolderPairSyncCfg>& syncConfig, //CONTRACT: syncConfig and folderCmp correspond row-wise!
                 FolderComparison& folderCmp,                      //
                 WarningDialogs& warnings,
                 ProcessCallback& callback);
}

#endif //SYNCHRONIZATION_H_8913470815943295
bgstack15