summaryrefslogtreecommitdiff
path: root/FreeFileSync/Source/base/synchronization.h
blob: c0c5df35c8c9782dc131b437fe526309da496315 (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
// *****************************************************************************
// * 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 "config.h"
#include "file_hierarchy.h"
#include "process_callback.h"


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

    template <SelectedSide side>
    int createCount() const { return SelectParam<side>::ref(createLeft_, createRight_); }
    int createCount() const { return createLeft_ + createRight_; }

    template <SelectedSide side>
    int updateCount() const { return SelectParam<side>::ref(updateLeft_, updateRight_); }
    int updateCount() const { return updateLeft_ + updateRight_; }

    template <SelectedSide side>
    int deleteCount() const { return SelectParam<side>::ref(deleteLeft_, deleteRight_); }
    int deleteCount() const { return deleteLeft_ + deleteRight_; }

    template <SelectedSide side>
    bool expectPhysicalDeletion() const { return SelectParam<side>::ref(physicalDeleteLeft_, physicalDeleteRight_); }

    int conflictCount() const { return static_cast<int>(conflictMsgs_.size()); }

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

    struct ConflictInfo
    {
        Zstring relPath;
        std::wstring msg;
    };
    const std::vector<ConflictInfo>& getConflicts() const { return conflictMsgs_; }

private:
    void recurse(const ContainerObject& hierObj);

    void processFile  (const FilePair& file);
    void processLink  (const SymlinkPair& link);
    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; //
    std::vector<ConflictInfo> conflictMsgs_; //conflict texts to display as a warning message
    int64_t bytesToProcess_ = 0;
    size_t rowsTotal_ = 0;
};


struct FolderPairSyncCfg
{
    DirectionConfig::Variant syncVariant;
    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