29 const std::string& dest,
31 const bool dest_is_vfat)
33 REQUIRE(
true == source.
exists() );
34 REQUIRE(
true == source.
is_dir() );
37 std::string dest_root;
40 if( dest_stats.
exists() ) {
43 REQUIRE(
true == dest_stats.
is_dir() );
45 dest_is_parent =
false;
48 dest_is_parent =
true;
53 dest_is_parent =
false;
57 jau::fprintf_td(stdout,
"%s: source %s, dest[arg %s, is_parent %d, dest_root %s], copts %s, dest_is_vfat %d\n",
58 title.c_str(), source.
to_string().c_str(),
59 dest.c_str(), dest_is_parent, dest_root.c_str(),
68 REQUIRE(
true == dest_stats.
exists() );
69 REQUIRE(
true == dest_stats.
ok() );
70 REQUIRE(
true == dest_stats.
is_dir() );
76 stats_ptr->
add(element_stats);
107 if( ( !opt_follow_links && !opt_drop_dest_links ) ||
122 }
else if( opt_drop_dest_links ) {
134 }
else if( opt_follow_links ) {
152 struct source_visitor_params {
154 std::string source_folder_path;
157 bool opt_drop_dest_links;
159 struct dest_visitor_params {
161 std::string source_folder_path;
162 std::string dest_folder_path;
163 std::string source_basename;
168 source_visitor_params svp { title, source.
path(), dest_stats, dest_is_vfat, opt_drop_dest_links };
169 const jau::fs::path_visitor pv1 = jau::bind_capref<bool, source_visitor_params, jau::fs::traverse_event, const jau::fs::file_stats&, size_t>(&svp,
174 dest_visitor_params dvp { _svp->title, _svp->source_folder_path, _svp->dest.path(),
jau::fs::basename( element_stats1.
path() ), element_stats1, _svp->dest_is_vfat,
false };
175 const jau::fs::path_visitor pv2 = jau::bind_capref<bool, dest_visitor_params, jau::fs::traverse_event, const jau::fs::file_stats&, size_t>(&dvp,
180 const std::string path2 = element_stats2.
path();
182 const std::string source_folder_basename =
jau::fs::basename( _dvp->source_folder_path );
183 if( basename2 == _dvp->source_basename ||
184 ( source_folder_basename == _dvp->source_basename && _dvp->dest_folder_path == path2 )
187 bool attr_equal, bit_equal;
188 if(
"README_slink08_relext.txt" == basename2 || 0 == basename2.find(
"dead_link") ) {
191 attr_equal = element_stats2.
is_link() &&
196 if( !_dvp->dest_is_vfat ) {
199 element_stats2.
mode() == _dvp->stats.mode() &&
201 element_stats2.
mtime() == _dvp->stats.mtime() &&
202 element_stats2.
uid() == _dvp->stats.uid() &&
203 element_stats2.
gid() == _dvp->stats.gid() &&
204 element_stats2.
size() == _dvp->stats.size();
212 abs( element_stats2.
mtime() - _dvp->stats.mtime() ) <= td &&
213 element_stats2.
uid() == _dvp->stats.uid() &&
215 element_stats2.
size() == _dvp->stats.size();
218 jau::fprintf_td(stdout,
"%s.check: '%s'\n mode %s == %s\n mtime %s == %s, d %s\n uid %s == %s\n gid %s == %s\n size %s == %s\n",
219 _dvp->title.c_str(), basename2.c_str(),
222 element_stats2.
mtime().
to_string().c_str(), _dvp->stats.mtime().to_string().c_str(),
223 abs( element_stats2.
mtime() - _dvp->stats.mtime() ).to_string().c_str(),
229 if( _dvp->stats.is_file() ) {
235 _dvp->match = attr_equal && bit_equal;
236 jau::fprintf_td(stdout,
"%s.check: '%s', match [attr %d, bit %d -> %d]\n\t source %s\n\t dest__ %s\n\n",
237 _dvp->title.c_str(), basename2.c_str(), attr_equal, bit_equal, _dvp->match,
238 _dvp->stats.to_string().c_str(),
247 const bool ignore = element_stats1.
is_link() && _svp->opt_drop_dest_links;
248 jau::fprintf_td(stdout,
"%s.check: %s: '%s', not found!\n\t source %s\n\n",
249 _svp->title.c_str(), ignore ?
"Ignored" :
"Error", dvp.source_basename.c_str(),
const std::string & basename() const noexcept
Return the basename, shall not be empty nor contain a dirname.
Platform agnostic representation of POSIX ::lstat() and ::stat() for a given pathname.
constexpr bool exists() const noexcept
Returns true if entity does not exist, exclusive bit.
const fraction_timespec & mtime() const noexcept
Returns the last modification time of this element since Unix Epoch.
constexpr bool is_link() const noexcept
Returns true if entity is a symbolic link, might be in combination with is_file(),...
gid_t gid() const noexcept
Returns the group id, owning the element.
constexpr bool is_dir() const noexcept
Returns true if entity is a directory, might be in combination with is_link().
const dir_item & item() const noexcept
Returns the dir_item.
uint64_t size() const noexcept
Returns the size in bytes of this element if is_file(), otherwise zero.
constexpr bool ok() const noexcept
Returns true if no error occurred.
fmode_t mode() const noexcept
Returns the fmode_t, file type and mode.
std::string to_string() const noexcept
Returns a comprehensive string representation of this element.
uid_t uid() const noexcept
Returns the user id, owning the element.
std::string path() const noexcept
Returns the unix path representation.
Class template jau::function is a general-purpose static-polymorphic function wrapper.
std::string to_string(const alphabet &v) noexcept
bool copy(const std::string &source_path, const std::string &dest_path, const copy_options copts=copy_options::none) noexcept
Copy the given source_path to dest_path using copy_options.
std::string basename(const std::string_view &path) noexcept
Return stripped leading directory components from given path separated by /.
bool compare(const file_stats &source1, const file_stats &source2, const bool verbose=false) noexcept
Compare the bytes of both files, denoted by source1 and source2.
bool visit(const std::string &path, const traverse_options topts, const path_visitor &visitor, std::vector< int > *dirfds=nullptr) noexcept
Visit element(s) of a given path, see traverse_options for detailed settings.
copy_options
Filesystem copy options used to copy() path elements.
traverse_options
Filesystem traverse options used to visit() path elements.
traverse_event
Filesystem traverse event used to call path_visitor for path elements from visit().
std::string to_string(const fmode_t mask, const bool show_rwx=false) noexcept
Return the string representation of fmode_t.
@ ignore_symlink_errors
Ignore errors from erroneous symlinks, e.g.
@ follow_symlinks
Copy referenced symbolic linked files or directories instead of just the symbolic link with property ...
@ into_existing_dir
Copy source dir content into an already existing destination directory as if destination directory di...
@ dir_entry
Call path_visitor at directory entry.
@ recursive
Traverse through directories, i.e.
jau::function< R(A...)> bind_capref(I *data_ptr, R(*func)(I *, A...)) noexcept
Bind given data by passing the captured reference (pointer) to the value and non-void function to an ...
constexpr T abs(const T x) noexcept
Returns the absolute value of an arithmetic number (w/ branching) in O(1)
std::string to_decstring(const value_type &v, const char separator=',', const nsize_t width=0) noexcept
Produce a decimal string representation of an integral integer value.
constexpr bool is_set(const cpu_family_t mask, const cpu_family_t bit) noexcept
int fprintf_td(const uint64_t elapsed_ms, FILE *stream, const char *format,...) noexcept
Convenient fprintf() invocation, prepending the given elapsed_ms timestamp.
Timespec structure using int64_t for its components in analogy to struct timespec_t on 64-bit platfor...
std::string to_string() const noexcept
Return simple string representation in seconds and nanoseconds.
std::string to_string() const noexcept
int total_sym_links_not_existing
int total_sym_links_existing
void add(const jau::fs::file_stats &element_stats)
void testxx_copy_r_p(const std::string &title, const jau::fs::file_stats &source, const int source_added_dead_links, const std::string &dest, const jau::fs::copy_options copts, const bool dest_is_vfat)