Skip to content
Snippets Groups Projects
Commit b8213add authored by Wouter Deconinck's avatar Wouter Deconinck
Browse files

Resolve "Allow for FileLoader to use a fs::recursive_directory_iterator to find the cached file"

parent 854b17c4
No related branches found
No related tags found
2 merge requests!329Master into deathvalley,!320Resolve "Allow for FileLoader to use a fs::recursive_directory_iterator to find the cached file"
...@@ -100,35 +100,45 @@ long load_file( ...@@ -100,35 +100,45 @@ long load_file(
return 0; return 0;
} }
// if hash does not exist, we must retrieve file from cache or url // if hash does not exist, we try to retrieve file from cache
if (!fs::exists(hash_path)) { if (!fs::exists(hash_path)) {
// recursive loop into cache directory
fs::path cache_path(cache); fs::path cache_path(cache);
fs::path cache_hash_path(cache_path / hash); printout(INFO, "FileLoader", "Cache " + cache_path.string());
if (fs::exists(cache_hash_path)) { if (fs::exists(cache_path)) {
// if cache/hash exists for (auto const& dir_entry: fs::recursive_directory_iterator(cache_path)) {
// symlink hash to cache/hash if (!dir_entry.is_directory()) continue;
printout(INFO, "FileLoader", "File " + file + " with hash " + hash + " found in " + cache); fs::path cache_dir_path = cache_path / dir_entry;
try { printout(INFO, "FileLoader", "Checking " + cache_dir_path.string());
fs::create_symlink(cache_hash_path, hash_path); fs::path cache_hash_path = cache_dir_path / hash;
} catch (const fs::filesystem_error&) { if (fs::exists(cache_hash_path)) {
printout(ERROR, "FileLoader", "unable to link from " + hash_path.string() + " to " + cache_hash_path.string()); // symlink hash to cache/.../hash
printout(ERROR, "FileLoader", "check permissions and retry"); printout(INFO, "FileLoader", "File " + file + " with hash " + hash + " found in " + cache_hash_path.string());
std::quick_exit(1); try {
} fs::create_symlink(cache_hash_path, hash_path);
} else { } catch (const fs::filesystem_error&) {
// if cache/hash doesn't exists printout(ERROR, "FileLoader", "unable to link from " + hash_path.string() + " to " + cache_hash_path.string());
cmd = fmt::format(cmd, url, hash_path.c_str()); // TODO: Use c++20 std::fmt printout(ERROR, "FileLoader", "check permissions and retry");
printout(INFO, "FileLoader", "Downloading " + file + " as hash " + hash + " with " + cmd); std::quick_exit(1);
// run cmd }
auto ret = std::system(cmd.c_str()); break;
if (!fs::exists(hash_path)) { }
printout(ERROR, "FileLoader", "unable to run cmd " + cmd);
printout(ERROR, "FileLoader", "check command and retry");
std::quick_exit(1);
} }
} }
} }
// hash_path now exists
// if hash does not exist, we try to retrieve file from url
if (!fs::exists(hash_path)) {
cmd = fmt::format(cmd, url, hash_path.c_str()); // TODO: Use c++20 std::fmt
printout(INFO, "FileLoader", "Downloading " + file + " as hash " + hash + " with " + cmd);
// run cmd
auto ret = std::system(cmd.c_str());
if (!fs::exists(hash_path)) {
printout(ERROR, "FileLoader", "unable to run cmd " + cmd);
printout(ERROR, "FileLoader", "check command and retry");
std::quick_exit(1);
}
}
// check if file already exists // check if file already exists
if (fs::exists(file_path)) { if (fs::exists(file_path)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment