mergerfs/src/mfm_dup.cpp

55 lines
1.2 KiB
C++
Raw Normal View History

2025-09-01 01:51:33 -05:00
#include "mfm_options.hpp"
2025-09-01 13:41:00 -05:00
#include "str.hpp"
2025-09-01 01:51:33 -05:00
#include "fmt/core.h"
2025-09-01 13:41:00 -05:00
#include <filesystem>
2025-09-01 01:51:33 -05:00
namespace fs = std::filesystem;
namespace mfm
{
void dup(const Opts::Dup &opts);
}
void
mfm::dup(const Opts::Dup &opts_)
{
2025-09-01 14:09:25 -05:00
std::vector<std::filesystem::path> paths;
2025-09-01 14:10:27 -05:00
paths = opts_.paths;
2025-09-01 14:09:25 -05:00
2025-09-01 14:10:27 -05:00
for(const auto &path : paths)
2025-09-01 01:51:33 -05:00
{
2025-09-01 14:10:52 -05:00
if(fs::is_regular_file(path))
2025-09-01 14:10:27 -05:00
{
}
2025-09-01 14:14:15 -05:00
else if(fs::is_directory(path))
2025-09-01 01:51:33 -05:00
{
2025-09-01 14:10:27 -05:00
auto dir_opts = (fs::directory_options::follow_directory_symlink |
fs::directory_options::skip_permission_denied);
2025-09-01 13:43:53 -05:00
2025-09-01 14:10:27 -05:00
for(const fs::directory_entry &de :
2025-09-01 14:14:49 -05:00
fs::recursive_directory_iterator(path,dir_opts))
2025-09-01 13:45:37 -05:00
{
2025-09-01 14:10:27 -05:00
if(!str::startswith(de.path().filename().string(),".dup_"))
continue;
for(const auto &de :
fs::directory_iterator(de.path().parent_path()))
{
fmt::println("{}",de.path().filename().string());
}
2025-09-01 13:45:37 -05:00
}
2025-09-01 01:51:33 -05:00
}
2025-09-01 14:10:27 -05:00
else
{
2025-09-01 14:14:39 -05:00
//throw std::runtime_error("invalid file type");
fmt::println("invalid file type: {}",path);
2025-09-01 14:10:27 -05:00
}
2025-09-01 01:51:33 -05:00
}
}