|
@@ -19,7 +19,8 @@ namespace craftlab::fakeraid
|
|
|
std::deque<std::string> GetCurrentDir() const override;
|
|
std::deque<std::string> GetCurrentDir() const override;
|
|
|
bool SetWorkingDirectory(const std::vector<std::string>& path) override;
|
|
bool SetWorkingDirectory(const std::vector<std::string>& path) override;
|
|
|
FileAndSumListByRepositoryIndex ListFiles() override;
|
|
FileAndSumListByRepositoryIndex ListFiles() override;
|
|
|
- FileAndSumListByRepositoryIndex ListFilesRecur() override;
|
|
|
|
|
|
|
+ void ListFilesRecur(FileAndSumListByRepositoryIndex*, bool* threadStopping) override;
|
|
|
|
|
+ size_t CountFilesRecur() override;
|
|
|
void Cd(const std::string& dirName) override;
|
|
void Cd(const std::string& dirName) override;
|
|
|
|
|
|
|
|
std::string BuildCurrentDirPath(const std::string& root, const PathParts& pathParts) const override;
|
|
std::string BuildCurrentDirPath(const std::string& root, const PathParts& pathParts) const override;
|
|
@@ -30,8 +31,8 @@ namespace craftlab::fakeraid
|
|
|
void CopyItems(const std::vector<CopyInstruction>& itemsToCopy) const override;
|
|
void CopyItems(const std::vector<CopyInstruction>& itemsToCopy) const override;
|
|
|
|
|
|
|
|
private:
|
|
private:
|
|
|
- void ListFiles(FileAndSumListByRepositoryIndex& result, const PathParts& currentDir);
|
|
|
|
|
- FileAndSumList ListFiles(const std::string& root, const PathParts& path, int repositoryIndex);
|
|
|
|
|
|
|
+ void ListFiles(FileAndSumListByRepositoryIndex& result, const PathParts& currentDir, bool* threadStopping =nullptr);
|
|
|
|
|
+ FileAndSumList ListFiles(const std::string& root, const PathParts& path, int repositoryIndex, bool* threadStopping =nullptr);
|
|
|
|
|
|
|
|
void CopyItem(const CopyInstruction& dst) const;
|
|
void CopyItem(const CopyInstruction& dst) const;
|
|
|
|
|
|
|
@@ -113,41 +114,66 @@ void Engine::Cd(const std::string& dirName)
|
|
|
currentDir.push_back(dirName);
|
|
currentDir.push_back(dirName);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-FileAndSumList Engine::ListFiles(const std::string& root, const std::deque<std::string>& wd, int repositoryIndex)
|
|
|
|
|
|
|
+FileAndSumList Engine::ListFiles(const std::string& root, const std::deque<std::string>& wd, int repositoryIndex, bool* threadStopping)
|
|
|
{
|
|
{
|
|
|
- FileAndSumList result;
|
|
|
|
|
|
|
+ FileAndSumList result {};
|
|
|
const std::string path = BuildCurrentDirPath(root, wd);
|
|
const std::string path = BuildCurrentDirPath(root, wd);
|
|
|
Crypto cryptoEngine;
|
|
Crypto cryptoEngine;
|
|
|
- for (const std::filesystem::directory_entry& file : std::filesystem::directory_iterator(path))
|
|
|
|
|
|
|
+
|
|
|
|
|
+ std::filesystem::directory_iterator directoryIterator;
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ directoryIterator = std::filesystem::directory_iterator(path);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (std::exception& e)
|
|
|
{
|
|
{
|
|
|
- if (file.is_directory() || file.is_regular_file())
|
|
|
|
|
|
|
+ return result; // FIXME
|
|
|
|
|
+ }
|
|
|
|
|
+ for (const std::filesystem::directory_entry& file : directoryIterator)
|
|
|
|
|
+ {
|
|
|
|
|
+ bool isDirectory = false;
|
|
|
|
|
+ bool isFile = false;
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ isDirectory = file.is_directory();
|
|
|
|
|
+ isFile = file.is_regular_file();
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (std::exception& e)
|
|
|
|
|
+ {}
|
|
|
|
|
+ if (isDirectory || isFile)
|
|
|
{
|
|
{
|
|
|
FileAndSum fileInfos;
|
|
FileAndSum fileInfos;
|
|
|
fileInfos.fileName = file.path().filename().string();
|
|
fileInfos.fileName = file.path().filename().string();
|
|
|
fileInfos.isDir = file.is_directory();
|
|
fileInfos.isDir = file.is_directory();
|
|
|
fileInfos.directory = wd;
|
|
fileInfos.directory = wd;
|
|
|
fileInfos.repositoryIndex = repositoryIndex;
|
|
fileInfos.repositoryIndex = repositoryIndex;
|
|
|
|
|
+
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
cryptoEngine.Compute(path, fileInfos);
|
|
cryptoEngine.Compute(path, fileInfos);
|
|
|
}
|
|
}
|
|
|
catch (std::runtime_error&)
|
|
catch (std::runtime_error&)
|
|
|
- {}
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ }
|
|
|
result.push_back(fileInfos);
|
|
result.push_back(fileInfos);
|
|
|
}
|
|
}
|
|
|
|
|
+ if (threadStopping && *threadStopping)
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void Engine::ListFiles(FileAndSumListByRepositoryIndex& result, const std::deque<std::string>& currentDir)
|
|
|
|
|
|
|
+void Engine::ListFiles(FileAndSumListByRepositoryIndex& result, const std::deque<std::string>& currentDir, bool* threadStopping)
|
|
|
{
|
|
{
|
|
|
int index = 0;
|
|
int index = 0;
|
|
|
for (const auto& i : rootPaths)
|
|
for (const auto& i : rootPaths)
|
|
|
{
|
|
{
|
|
|
- const FileAndSumList files = ListFiles(i, currentDir, index++);
|
|
|
|
|
|
|
+ const FileAndSumList files = ListFiles(i, currentDir, index++, threadStopping);
|
|
|
result.FileAndSumListByRepositoryIndex.push_back(files);
|
|
result.FileAndSumListByRepositoryIndex.push_back(files);
|
|
|
for (const FileAndSum& file : files)
|
|
for (const FileAndSum& file : files)
|
|
|
result.FileList[BuildCurrentDirPath(file)] = file;
|
|
result.FileList[BuildCurrentDirPath(file)] = file;
|
|
|
|
|
+ if (threadStopping && *threadStopping)
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -158,21 +184,20 @@ FileAndSumListByRepositoryIndex Engine::ListFiles()
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-FileAndSumListByRepositoryIndex Engine::ListFilesRecur()
|
|
|
|
|
|
|
+void Engine::ListFilesRecur(FileAndSumListByRepositoryIndex* result, bool* threadStopping)
|
|
|
{
|
|
{
|
|
|
- FileAndSumListByRepositoryIndex result;
|
|
|
|
|
std::deque<PathParts> itemsToDo { currentDir };
|
|
std::deque<PathParts> itemsToDo { currentDir };
|
|
|
|
|
|
|
|
do
|
|
do
|
|
|
{
|
|
{
|
|
|
FileAndSumListByRepositoryIndex newItems;
|
|
FileAndSumListByRepositoryIndex newItems;
|
|
|
const PathParts currentPath = itemsToDo.front();
|
|
const PathParts currentPath = itemsToDo.front();
|
|
|
- ListFiles(newItems, currentPath);
|
|
|
|
|
|
|
+ ListFiles(newItems, currentPath, threadStopping);
|
|
|
itemsToDo.pop_front();
|
|
itemsToDo.pop_front();
|
|
|
- std::copy(newItems.FileAndSumListByRepositoryIndex.begin(), newItems.FileAndSumListByRepositoryIndex.end(), std::back_inserter(result.FileAndSumListByRepositoryIndex));
|
|
|
|
|
|
|
+ std::copy(newItems.FileAndSumListByRepositoryIndex.begin(), newItems.FileAndSumListByRepositoryIndex.end(), std::back_inserter(result->FileAndSumListByRepositoryIndex));
|
|
|
for (const auto& file : newItems.FileList)
|
|
for (const auto& file : newItems.FileList)
|
|
|
{
|
|
{
|
|
|
- result.FileList[file.first] = file.second;
|
|
|
|
|
|
|
+ result->FileList[file.first] = file.second;
|
|
|
if (file.second.isDir)
|
|
if (file.second.isDir)
|
|
|
{
|
|
{
|
|
|
PathParts dirPath = currentPath;
|
|
PathParts dirPath = currentPath;
|
|
@@ -180,6 +205,44 @@ FileAndSumListByRepositoryIndex Engine::ListFilesRecur()
|
|
|
itemsToDo.push_back(dirPath);
|
|
itemsToDo.push_back(dirPath);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ } while (!itemsToDo.empty() && !*threadStopping);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+size_t Engine::CountFilesRecur()
|
|
|
|
|
+{
|
|
|
|
|
+ size_t result =0;
|
|
|
|
|
+ std::deque<std::filesystem::path> itemsToDo;
|
|
|
|
|
+
|
|
|
|
|
+ for (const auto& i: rootPaths)
|
|
|
|
|
+ itemsToDo.push_back(i);
|
|
|
|
|
+
|
|
|
|
|
+ do
|
|
|
|
|
+ {
|
|
|
|
|
+ std::filesystem::directory_iterator directoryIterator;
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ directoryIterator = std::filesystem::directory_iterator(itemsToDo.front());
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (std::exception& e)
|
|
|
|
|
+ {
|
|
|
|
|
+ itemsToDo.pop_front();
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (const std::filesystem::directory_entry& file : directoryIterator)
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (file.is_regular_file())
|
|
|
|
|
+ ++result;
|
|
|
|
|
+ else if (file.is_directory())
|
|
|
|
|
+ {
|
|
|
|
|
+ itemsToDo.push_back(file.path());
|
|
|
|
|
+ ++result;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (std::exception)
|
|
|
|
|
+ {}
|
|
|
|
|
+ }
|
|
|
|
|
+ itemsToDo.pop_front();
|
|
|
} while (!itemsToDo.empty());
|
|
} while (!itemsToDo.empty());
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|