Allow hash of current directory
This commit is contained in:
@@ -92,11 +92,27 @@ uint64_t hash_directory_recursive(const std::string &path) {
|
||||
return hash;
|
||||
}
|
||||
|
||||
uint64_t hash_path(const std::string &path) {
|
||||
if (!std::filesystem::exists(path)) {
|
||||
std::cerr << "Path does not exist: " << path << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (std::filesystem::is_directory(path)) {
|
||||
return hash_directory_recursive(path);
|
||||
} else if (std::filesystem::is_regular_file(path)) {
|
||||
return hash_file(path);
|
||||
} else {
|
||||
std::cerr << "Path is neither a file nor a directory: " << path << std::endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void hash_demo(const std::string & path)
|
||||
{
|
||||
std::cout << "Hashing directory: " << path << std::endl;
|
||||
std::cout << "Hashing path: " << path << std::endl;
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
XXH64_hash_t hash = hash_directory_recursive(path);
|
||||
XXH64_hash_t hash = hash_path(path);
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
||||
std::cout << "Hash: " << hash << " (took " << duration.count() << "ms)" << std::endl;
|
||||
@@ -107,7 +123,7 @@ int hash_demo_raw(const std::string & path)
|
||||
if (!std::filesystem::exists(path)) {
|
||||
std::cout << 0 <<std::endl; return 1;
|
||||
}
|
||||
XXH64_hash_t hash = hash_directory_recursive(path);
|
||||
XXH64_hash_t hash = hash_path(path);
|
||||
std::cout << hash << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
@@ -10,6 +10,8 @@ namespace dropshell {
|
||||
|
||||
uint64_t hash_directory_recursive(const std::string &path);
|
||||
|
||||
uint64_t hash_path(const std::string &path);
|
||||
|
||||
void hash_demo(const std::string & path);
|
||||
|
||||
int hash_demo_raw(const std::string & path);
|
||||
|
Reference in New Issue
Block a user