53 std::function<
void(std::string_view,
float)> reportProgress);
77 unsigned amountScanned = 0;
82 Entry(
const Sha1Sum& s, time_t
t, std::string_view f)
83 : filename(f), time(
t),
sum(s)
87 Entry(
const Sha1Sum& s,
const char*
t, std::string_view f)
88 : filename(f), timeStr(
t),
sum(s)
90 assert(timeStr !=
nullptr);
94 void setTime(time_t
t);
98 std::string_view filename;
99 const char* timeStr =
nullptr;
106 using Sha1Index = std::vector<Index>;
108 class FilenameIndexHelper {
110 explicit FilenameIndexHelper(
const Pool& p) : pool(p) {}
111 [[nodiscard]] std::string_view get(std::string_view s)
const {
return s; }
112 [[nodiscard]] std::string_view get(Index idx)
const {
return pool[idx].filename; }
116 struct FilenameIndexHash : FilenameIndexHelper {
117 using FilenameIndexHelper::FilenameIndexHelper;
118 template<
typename T> [[nodiscard]]
auto operator()(T
t)
const {
120 return hasher(get(
t));
123 struct FilenameIndexEqual : FilenameIndexHelper {
124 using FilenameIndexHelper::FilenameIndexHelper;
125 template<
typename T1,
typename T2>
126 [[nodiscard]]
bool operator()(T1 x, T2 y)
const {
127 return get(x) == get(y);
131 using FilenameIndex =
SimpleHashSet<Index(-1), FilenameIndexHash, FilenameIndexEqual>;
134 void insert(
const Sha1Sum&
sum, time_t time,
const std::string& filename);
135 [[nodiscard]] Sha1Index::iterator getSha1Iterator(Index idx,
const Entry& entry);
136 void remove(Sha1Index::iterator it);
137 void remove(Index idx);
138 void remove(Index idx,
const Entry& entry);
139 bool adjustSha1(Sha1Index::iterator it, Entry& entry,
const Sha1Sum& newSum);
140 bool adjustSha1(Index idx, Entry& entry,
const Sha1Sum& newSum);
143 void writeSha1sums();
145 [[nodiscard]] File getFromPool(
const Sha1Sum& sha1sum);
146 [[nodiscard]] File scanDirectory(
147 const Sha1Sum& sha1sum,
148 const std::string& directory,
149 std::string_view poolPath,
150 ScanProgress& progress);
151 [[nodiscard]] File scanFile(
152 const Sha1Sum& sha1sum,
153 const std::string& filename,
155 std::string_view poolPath,
156 ScanProgress& progress);
157 [[nodiscard]] Sha1Sum calcSha1sum(File& file)
const;
158 [[nodiscard]] std::pair<Index, Entry*> findInDatabase(std::string_view filename);
161 std::string fileCache;
163 std::function<void(std::string_view,
float)> reportProgress;
165 MemBuffer<char> fileMem;
166 std::vector<std::string> stringBuffer;
170 FilenameIndex filenameIndex{FilenameIndexHash(pool), FilenameIndexEqual(pool)};
173 bool needWrite =
false;