summaryrefslogtreecommitdiff
path: root/lib/parallel_scan.h
blob: b75184289f496e2ac259990016e3dbf5c48c7650 (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
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html       *
// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved        *
// **************************************************************************

#ifndef PARALLEL_SCAN_H_INCLUDED
#define PARALLEL_SCAN_H_INCLUDED

#include <map>
#include <set>
#include "hard_filter.h"
#include "../structures.h"
#include "../file_hierarchy.h"

namespace zen
{
struct DirectoryKey
{
    DirectoryKey(const Zstring& dirnameFull,
                 const HardFilter::FilterRef& filter,
                 SymLinkHandling handleSymlinks) :
        dirnameFull_(dirnameFull),
        filter_(filter),
        handleSymlinks_(handleSymlinks) {}

    Zstring dirnameFull_;
    HardFilter::FilterRef filter_; //filter interface: always bound by design!
    SymLinkHandling handleSymlinks_;
};

inline
bool operator<(const DirectoryKey& lhs, const DirectoryKey& rhs)
{
    if (lhs.handleSymlinks_ != rhs.handleSymlinks_)
        return lhs.handleSymlinks_ < rhs.handleSymlinks_;

    const int cmpName = cmpFileName(lhs.dirnameFull_, rhs.dirnameFull_);
    if (cmpName != 0)
        return cmpName < 0;

    return *lhs.filter_ < *rhs.filter_;
}


struct DirectoryValue
{
    DirContainer dirCont;
    std::set<Zstring> failedDirReads;  //relative postfixed names (or empty string for root) for directories that could not be read (completely), e.g. access denied, or temporal network drop
	std::set<Zstring> failedItemReads; //relative postfixed names (never empty) for failure to read single file/dir/symlink 
};


class FillBufferCallback
{
public:
    virtual ~FillBufferCallback() {}

    enum HandleError
    {
        ON_ERROR_RETRY,
        ON_ERROR_IGNORE
    };
    virtual HandleError reportError (const std::wstring& msg) = 0;                 //may throw!
    virtual void        reportStatus(const std::wstring& msg, int itemsTotal) = 0; //
};

//attention: ensure directory filtering is applied later to exclude filtered directories which have been kept as parent folders

void fillBuffer(const std::set<DirectoryKey>& keysToRead, //in
                std::map<DirectoryKey, DirectoryValue>& buf, //out
                FillBufferCallback& callback,
                size_t updateInterval); //unit: [ms]
}

#endif // PARALLEL_SCAN_H_INCLUDED
bgstack15