27 return static_cast<FileType>(int(x) | int(y));
30 return static_cast<FileType>(int(x) & int(y));
49 std::function<
void(std::string_view)> reportProgress);
73 unsigned amountScanned;
77 Entry(
const Sha1Sum& s, time_t
t, std::string_view f)
78 : filename(f), time(
t),
sum(s)
82 Entry(
const Sha1Sum& s,
const char*
t, std::string_view f)
83 : filename(f), timeStr(
t),
sum(s)
85 assert(timeStr !=
nullptr);
89 void setTime(time_t
t);
93 std::string_view filename;
94 const char* timeStr =
nullptr;
101 using Sha1Index = std::vector<Index>;
103 class FilenameIndexHelper {
105 FilenameIndexHelper(
const Pool& p) : pool(p) {}
106 [[nodiscard]] std::string_view
get(std::string_view s)
const {
return s; }
107 [[nodiscard]] std::string_view
get(Index idx)
const {
return pool[idx].filename; }
111 struct FilenameIndexHash : FilenameIndexHelper {
112 FilenameIndexHash(
const Pool& p) : FilenameIndexHelper(p) {}
113 template<
typename T> [[nodiscard]]
auto operator()(T
t)
const {
115 return hasher(
get(
t));
118 struct FilenameIndexEqual : FilenameIndexHelper {
119 FilenameIndexEqual(
const Pool& p) : FilenameIndexHelper(p) {}
120 template<
typename T1,
typename T2>
121 [[nodiscard]]
bool operator()(T1 x, T2 y)
const {
126 using FilenameIndex =
SimpleHashSet<Index, Index(-1), FilenameIndexHash, FilenameIndexEqual>;
129 void insert(
const Sha1Sum&
sum, time_t time,
const std::string& filename);
130 [[nodiscard]] Sha1Index::iterator getSha1Iterator(Index idx, Entry& entry);
131 void remove(Sha1Index::iterator it);
132 void remove(Index idx);
133 void remove(Index idx, Entry& entry);
134 bool adjustSha1(Sha1Index::iterator it, Entry& entry,
const Sha1Sum& newSum);
135 bool adjustSha1(Index idx, Entry& entry,
const Sha1Sum& newSum);
138 void writeSha1sums();
140 [[nodiscard]] File getFromPool(
const Sha1Sum& sha1sum);
141 [[nodiscard]] File scanDirectory(
142 const Sha1Sum& sha1sum,
143 const std::string& directory,
144 std::string_view poolPath,
145 ScanProgress& progress);
146 [[nodiscard]] File scanFile(
147 const Sha1Sum& sha1sum,
148 const std::string& filename,
150 std::string_view poolPath,
151 ScanProgress& progress);
152 [[nodiscard]] Sha1Sum calcSha1sum(File& file);
153 [[nodiscard]] std::pair<Index, Entry*> findInDatabase(std::string_view filename);
156 std::string fileCache;
158 std::function<void(std::string_view)> reportProgress;
160 MemBuffer<char> fileMem;
161 std::vector<std::string> stringBuffer;
165 FilenameIndex filenameIndex{FilenameIndexHash(pool), FilenameIndexEqual(pool)};
168 bool needWrite =
false;
Sha1Sum getSha1Sum(File &file)
Calculate sha1sum for the given File object.
FilePoolCore(std::string fileCache, std::function< Directories()> getDirectories, std::function< void(std::string_view)> reportProgress)
File getFile(FileType fileType, const Sha1Sum &sha1sum)
Search file with the given sha1sum.
void abort()
This is only meaningful to call from within the 'reportProgress' callback (constructor parameter).
std::vector< Dir > Directories
This class represents the result of a sha1 calculation (a 160-bit value).
constexpr time_t INVALID_TIME_T
uint64_t getTime()
Get current (real) time in us.
This file implemented 3 utility functions:
FileType operator&(FileType x, FileType y)
const T & get(const Event &event)
FileType & operator|=(FileType &x, FileType y)
FileType operator|(FileType x, FileType y)
auto sum(InputRange &&range, Proj proj={})