26import org.jau.fs.CopyOptions;
27import org.jau.fs.FileStats;
28import org.jau.fs.FileUtil;
29import org.jau.fs.TraverseEvent;
30import org.jau.fs.TraverseOptions;
31import org.jau.io.PrintUtil;
32import org.junit.Assert;
34import jau.test.junit.util.JunitTracer;
37 public static final String
image_file =
"test_data.sqfs";
38 public static final String
root =
"test_data";
46 public static final String
project_root2b =
"../../../../../jaulib/test_data";
54 if( path_stats.
exists() ) {
58 if( path_stats.
exists() ) {
62 if( path_stats.
exists() ) {
66 if( path_stats.
exists() ) {
73 if( path_stats.
exists() ) {
77 if( path_stats.
exists() ) {
81 if( path_stats.
exists() ) {
85 if( path_stats.
exists() ) {
92 if( path_stats.
exists() ) {
96 if( path_stats.
exists() ) {
130 if( element_stats.
is_link() ) {
131 if( element_stats.
exists() ) {
142 if( !element_stats.
exists() ) {
145 if( element_stats.
is_file() ) {
146 if( element_stats.
is_link() ) {
155 }
else if( element_stats.
is_dir() ) {
156 if( element_stats.
is_link() ) {
165 public boolean equals(
final Object other) {
166 if(
this == other ) {
187 final StringBuilder res =
new StringBuilder();
188 res.append(
"- traverse_options ").append(
topts).append(
"\n");
189 res.append(
"- total_real ").append(
total_real).append(
"\n");
192 res.append(
"- total_no_access ").append(
total_no_access).append(
"\n");
194 res.append(
"- total_file_bytes ").append(String.format(
"%,d",
total_file_bytes)).append(
"\n");
195 res.append(
"- files_real ").append(
files_real).append(
"\n");
196 res.append(
"- files_sym_link ").append(
files_sym_link).append(
"\n");
197 res.append(
"- dirs_real ").append(
dirs_real).append(
"\n");
198 res.append(
"- dirs_sym_link ").append(
dirs_sym_link).append(
"\n");
199 return res.toString();
213 stats.
add(item_stats);
218 static class source_visitor_params {
220 public String source_folder_path;
222 public boolean dest_is_vfat;
223 public boolean opt_drop_dest_links;
225 public source_visitor_params(
final String t,
final String sfp,
final FileStats d,
final boolean dest_is_vfat_,
final boolean opt_drop_dest_links_) {
227 source_folder_path = sfp;
229 dest_is_vfat = dest_is_vfat_;
230 opt_drop_dest_links = opt_drop_dest_links_;
234 static class dest_visitor_params {
236 public String source_folder_path;
237 public String dest_folder_path;
238 public String source_basename;
239 public FileStats stats;
240 public boolean dest_is_vfat;
241 public boolean match;
242 public dest_visitor_params(
final String t,
final String sfp,
final String dfp,
final String sb,
final FileStats s,
final boolean dest_is_vfat_) {
244 source_folder_path = sfp;
245 dest_folder_path = dfp;
246 source_basename = sb;
248 dest_is_vfat = dest_is_vfat_;
256 final boolean dest_is_vfat) {
257 Assert.assertTrue( source.
exists() );
258 Assert.assertTrue( source.
is_dir() );
260 final boolean dest_is_parent;
261 final String dest_root;
264 if( dest_stats.
exists() ) {
267 Assert.assertTrue( dest_stats.
is_dir() );
269 dest_is_parent =
false;
272 dest_is_parent =
true;
277 dest_is_parent =
false;
281 PrintUtil.
fprintf_td(System.err,
"%s: source %s, dest[arg %s, is_parent %b, dest_root %s], copts %s, dest_is_vfat %b\n",
282 title, source, dest, dest_is_parent, dest_root, copts, dest_is_vfat);
290 Assert.assertTrue(
true == dest_stats.
exists() );
291 Assert.assertTrue(
true == dest_stats.
ok() );
292 Assert.assertTrue(
true == dest_stats.
is_dir() );
305 Assert.assertTrue(
true ==
FileUtil.
visit(source, topts, pv_orig) );
306 Assert.assertTrue(
true ==
FileUtil.
visit(dest_stats, topts, pv_copy) );
310 PrintUtil.
fprintf_td(System.err,
"%s: destination visitor stats\n%s\n", title, stats_copy);
319 Assert.assertTrue( 9 - source_added_dead_links == stats.
files_sym_link );
320 Assert.assertTrue( 3 == stats.
dirs_real );
323 if( ( !opt_follow_links && !opt_drop_dest_links ) ||
328 Assert.assertTrue( 7 == stats_copy.
total_real );
334 Assert.assertTrue( 4 == stats_copy.
files_real );
336 Assert.assertTrue( 3 == stats_copy.
dirs_real );
338 }
else if( opt_drop_dest_links ) {
340 Assert.assertTrue( 7 == stats_copy.
total_real );
346 Assert.assertTrue( 4 == stats_copy.
files_real );
348 Assert.assertTrue( 3 == stats_copy.
dirs_real );
350 }
else if( opt_follow_links ) {
352 Assert.assertTrue( 20 == stats_copy.
total_real );
358 Assert.assertTrue( 16 == stats_copy.
files_real );
360 Assert.assertTrue( 4 == stats_copy.
dirs_real );
370 final source_visitor_params svp =
new source_visitor_params(title, source.
path(), dest_stats, dest_is_vfat, opt_drop_dest_links);
374 final dest_visitor_params dvp =
new dest_visitor_params(svp.title, svp.source_folder_path, svp.dest.path(),
FileUtil.
basename(element_stats1.
path() ), element_stats1, svp.dest_is_vfat);
378 final String path2 = element_stats2.
path();
380 final String source_folder_basename =
FileUtil.
basename( dvp.source_folder_path );
381 if( basename2.equals( dvp.source_basename ) ||
382 ( source_folder_basename.equals( dvp.source_basename ) && dvp.dest_folder_path.equals( path2 ) )
385 boolean attr_equal, bit_equal;
386 if(
"README_slink08_relext.txt".equals(basename2) || 0 == basename2.indexOf(
"dead_link") ) {
389 attr_equal = element_stats2.
is_link() &&
394 if( !dvp.dest_is_vfat ) {
397 element_stats2.
mode().
equals( dvp.stats.mode() ) &&
399 element_stats2.
mtime().equals( dvp.stats.mtime() ) &&
400 element_stats2.
uid() == dvp.stats.uid() &&
401 element_stats2.
gid() == dvp.stats.gid() &&
402 element_stats2.
size() == dvp.stats.size();
406 final long td_ms = 5000;
411 Math.abs( element_stats2.
mtime().toEpochMilli() - dvp.stats.mtime().toEpochMilli() ) <= td_ms &&
412 element_stats2.
uid() == dvp.stats.uid() &&
414 element_stats2.
size() == dvp.stats.size();
416 if( dvp.stats.is_file() ) {
422 dvp.match = attr_equal && bit_equal;
423 PrintUtil.
fprintf_td(System.err,
"%s.check: '%s', match [attr %b, bit %b -> %b]\n\t source %s\n\t dest__ %s\n\n",
424 dvp.title, basename2, attr_equal, bit_equal, dvp.match,
434 final boolean ignore = element_stats1.
is_link() && svp.opt_drop_dest_links;
436 svp.title, ignore ?
"Ignored" :
"Error", dvp.source_basename, element_stats1);
447 Assert.assertTrue(
true ==
FileUtil.
visit(source, topts, pv1) );
PathStatsVisitor(final VisitorStats stats_)
boolean visit(final TraverseEvent tevt, final FileStats item_stats, final long depth)
void add(final FileStats element_stats)
VisitorStats(final TraverseOptions topts_)
boolean equals(final Object other)
int total_sym_links_existing
int total_sym_links_not_existing
static final FileStats getTestDataImageFile()
static String getTestDataRelDir()
static final String project_root_ext
static final String project_root1a
static final String project_root2b
static final String project_root1b
static final String project_root2a
static final FileStats getTestDataDirStats()
void testxx_copy_r_p(final String title, final FileStats source, final int source_added_dead_links, final String dest, final CopyOptions copts, final boolean dest_is_vfat)
static final String image_file
static final String dest_fs_vfat
Filesystem copy options used to copy() path elements.
boolean isSet(final Bit bit)
String basename()
Return the basename, shall not be empty nor contain a dirname.
boolean equals(final Object other)
Platform agnostic representation of POSIX ::lstat() and ::stat() for a given pathname.
String path()
Returns the unix path representation.
boolean is_file()
Returns true if entity is a file, might be in combination with is_link().
Instant mtime()
Returns the last modification time of this element since Unix Epoch.
boolean ok()
Returns true if no error occurred.
boolean exists()
Returns true if entity does not exist, exclusive bit.
boolean has_access()
Returns true if entity gives no access to user, exclusive bit.
int gid()
Returns the group id, owning the element.
boolean is_link()
Returns true if entity is a symbolic link, might be in combination with is_file(),...
DirItem item()
Returns the dir_item.
FMode mode()
Returns the FMode, file type and mode.
boolean is_dir()
Returns true if entity is a directory, might be in combination with is_link().
int uid()
Returns the user id, owning the element.
long size()
Returns the size in bytes of this element if is_file(), otherwise zero.
Native file types and functionality.
static boolean copy(final String source_path, final String dest_path, final CopyOptions copts)
Copy the given source_path to dest_path using copy_options.
static native String basename(final String path)
Return stripped leading directory components from given path separated by /.
static native boolean compare(final String source1, final String source2, final boolean verbose)
Compare the bytes of both files, denoted by source1 and source2.
static boolean visit(final String path, final TraverseOptions topts, final PathVisitor visitor)
Visit element(s) of a given path, see traverse_options for detailed settings.
Filesystem traverse options used to visit() path elements.
TraverseOptions set(final Bit bit)
Sets the given bit and returns this instance for chaining.
boolean isSet(final Bit bit)
static void fprintf_td(final PrintStream out, final String format, final Object ... args)
Convenient PrintStream#printf(String, Object...) invocation, prepending the elapsedTimeMillis() times...
follow_symlinks
Copy referenced symbolic linked files or directories instead of just the symbolic link with property ...
ignore_symlink_errors
Ignore errors from erroneous symlinks, e.g.
into_existing_dir
Copy source dir content into an already existing destination directory as if destination directory di...
Filesystem traverse event used to call path_visitor for path elements from visit().
follow_symlinks
Traverse through symbolic linked directories if traverse_options::recursive is set,...
dir_entry
Visit the content's parent directory at entry.
recursive
Traverse through directories, i.e.
Path visitor for FileUtil#visit(FileStats, TraverseOptions, PathVisitor).