Data_deduplication_service
Service that will use hashes to deduplicate files
fileUtils.h
Go to the documentation of this file.
1 
2 
3 #ifndef DATA_DEDUPLICATION_SERVICE_FILEUTILS_H
4 #define DATA_DEDUPLICATION_SERVICE_FILEUTILS_H
5 
6 #include <filesystem>
7 #include <concepts>
8 #include <fstream>
9 #include <unordered_set>
10 
11 #include "expected.hpp"
12 #include "myConcepts.h"
13 
14 
16 namespace file_services {
17 
19  namespace fs = std::filesystem;
20 
21  using myConcepts::gClk;
27  use,
29  create
30  };
31 
40  };
41 
49  Remove
50  };
51 
60  };
61 
67  tl::expected<std::string, int> checkFileExistence(std::string_view filePath);
68 
74  tl::expected<std::string, int> checkDirectoryExistence(std::string_view dirPath);
75 
76  namespace fs = std::filesystem;
77 
78 
79  template<typename T, typename A>
80  requires std::is_same_v<T, A> ||
81  std::is_same_v<T, typename std::remove_const<A>::type> ||
82  std::is_same_v<A, typename std::remove_const<T>::type>
83  int compareBlock(size_t size, T *arr, A *arr2) {
84  int error = 0;
85  for (int arrElem = 0; arrElem < size; ++arrElem) {
86  error += arr[arrElem] != arr2[arrElem];
87  }
88  return error;
89  }
90 
102  std::array<size_t, 4> compareFiles(const fs::path &file1, const fs::path &file2, size_t segmentSize);
103 
115  std::array<size_t, 4> compareDirectories(const fs::path &file1, const fs::path &file2, size_t segmentSize);
116 
122  fs::path getNormalAbs(const fs::path &path);
123 
124 
125 }
126 #endif //DATA_DEDUPLICATION_SERVICE_FILEUTILS_H
file services namespace
Definition: FileService.h:14
std::array< size_t, 4 > compareDirectories(const fs::path &file1, const fs::path &file2, size_t segmentSize)
Definition: fileUtils.cpp:6
rootDirectoryHandlingStrategy
Definition: fileUtils.h:55
@ NoCreateMain
will return an error code
Definition: fileUtils.h:57
@ CreateMain
will create this directory using create_directories
Definition: fileUtils.h:59
dataRetrievalStrategy
Definition: fileUtils.h:45
@ Remove
will delete requested data from database
Definition: fileUtils.h:49
@ Persist
will leave data as is
Definition: fileUtils.h:47
tl::expected< std::string, int > checkFileExistence(std::string_view filePath)
Definition: fileUtils.cpp:101
dataInsetionStrategy
Definition: fileUtils.h:35
@ PreserveOld
will ignore files that already exist
Definition: fileUtils.h:37
@ ReplaceWithNew
will replace file contents
Definition: fileUtils.h:39
tl::expected< std::string, int > checkDirectoryExistence(std::string_view dirPath)
Definition: fileUtils.cpp:123
requires std::is_same_v< T, A > std::is_same_v< T, typename std::remove_const< A >::type > std::is_same_v< A, typename std::remove_const< T >::type > int compareBlock(size_t size, T *arr, A *arr2)
Definition: fileUtils.h:83
dbUsageStrategy
Definition: fileUtils.h:25
@ create
create new database if it doesn't exist
Definition: fileUtils.h:29
@ use
if database exist connection will be established
Definition: fileUtils.h:27
std::array< size_t, 4 > compareFiles(const fs::path &file1, const fs::path &file2, size_t segmentSize)
Definition: fileUtils.cpp:53
fs::path getNormalAbs(const fs::path &path)
char symbolType
Definition: myConcepts.h:20
clockType gClk
Definition: myConcepts.cpp:9