27import java.time.Instant;
28import java.time.ZoneOffset;
29import java.time.temporal.ChronoUnit;
31import org.jau.fs.CopyOptions;
32import org.jau.fs.DirItem;
33import org.jau.fs.FMode;
34import org.jau.fs.FileStats;
35import org.jau.fs.FileUtil;
36import org.jau.fs.TraverseEvent;
37import org.jau.fs.TraverseOptions;
38import org.jau.io.ByteOutStream_File;
39import org.jau.io.PrintUtil;
40import org.junit.Assert;
41import org.junit.FixMethodOrder;
43import org.junit.runners.MethodSorters;
45import jau.pkg.PlatformRuntime;
47@FixMethodOrder(MethodSorters.NAME_ASCENDING)
49 static final boolean DEBUG =
false;
51 @Test(timeout = 10000)
52 public final
void test01_cwd() {
56 Assert.assertTrue( 0 < cwd.length() );
57 final int idx = cwd.indexOf(
"/jaulib/");
58 Assert.assertTrue( 0 < idx );
59 Assert.assertTrue( idx < cwd.length() );
60 Assert.assertTrue( idx > 0 );
66 @Test(timeout = 10000)
67 public final
void test02_dirname() {
70 final String pathname0 =
"/";
72 PrintUtil.
println(System.err,
"test02_dirname: cwd "+pathname0+
" -> "+pathname1);
73 Assert.assertTrue( 0 < pathname1.length() );
74 Assert.assertTrue( pathname1.equals(
"/" ) );
78 final String pathname0 =
"lala.txt";
80 PrintUtil.
println(System.err,
"test02_dirname: cwd "+pathname0+
" -> "+pathname1);
81 Assert.assertTrue( 0 < pathname1.length() );
82 Assert.assertTrue( pathname1.equals(
"." ) );
85 final String pathname0 =
"lala";
87 PrintUtil.
println(System.err,
"test02_dirname: cwd "+pathname0+
" -> "+pathname1);
88 Assert.assertTrue( 0 < pathname1.length() );
89 Assert.assertTrue( pathname1.equals(
"." ) );
92 final String pathname0 =
"lala/";
94 PrintUtil.
println(System.err,
"test02_dirname: cwd "+pathname0+
" -> "+pathname1);
95 Assert.assertTrue( 0 < pathname1.length() );
96 Assert.assertTrue( pathname1.equals(
"." ) );
100 final String pathname0 =
"/lala.txt";
102 PrintUtil.
println(System.err,
"test02_dirname: cwd "+pathname0+
" -> "+pathname1);
103 Assert.assertTrue( 0 < pathname1.length() );
104 Assert.assertTrue( pathname1.equals(
"/" ) );
107 final String pathname0 =
"blabla/jaulib/test/sub.txt";
109 PrintUtil.
println(System.err,
"test02_dirname: cwd "+pathname0+
" -> "+pathname1);
110 Assert.assertTrue( 0 < pathname1.length() );
111 Assert.assertTrue( pathname1.equals(
"blabla/jaulib/test" ) );
114 final String pathname0 =
"blabla/jaulib/test/sub";
116 PrintUtil.
println(System.err,
"test02_dirname: cwd "+pathname0+
" -> "+pathname1);
117 Assert.assertTrue( 0 < pathname1.length() );
118 Assert.assertTrue( pathname1.equals(
"blabla/jaulib/test" ) );
121 final String pathname0 =
"blabla/jaulib/test/";
123 PrintUtil.
println(System.err,
"test02_dirname: cwd "+pathname0+
" -> "+pathname1);
124 Assert.assertTrue( 0 < pathname1.length() );
125 Assert.assertTrue( pathname1.equals(
"blabla/jaulib" ) );
128 final String pathname0 =
"blabla/jaulib/test";
130 PrintUtil.
println(System.err,
"test02_dirname: cwd "+pathname0+
" -> "+pathname1);
131 Assert.assertTrue( 0 < pathname1.length() );
132 Assert.assertTrue( pathname1.equals(
"blabla/jaulib" ) );
136 @Test(timeout = 10000)
137 public final
void test03_basename() {
140 final String pathname0 =
"/";
142 PrintUtil.
println(System.err,
"test03_basename: cwd "+pathname0+
" -> "+pathname1);
143 Assert.assertTrue( 0 < pathname1.length() );
144 Assert.assertTrue( pathname1.equals(
"/" ) );
148 final String pathname0 =
"lala.txt";
150 PrintUtil.
println(System.err,
"test03_basename: cwd "+pathname0+
" -> "+pathname1);
151 Assert.assertTrue( 0 < pathname1.length() );
152 Assert.assertTrue( pathname1.equals(
"lala.txt" ) );
155 final String pathname0 =
"lala";
157 PrintUtil.
println(System.err,
"test03_basename: cwd "+pathname0+
" -> "+pathname1);
158 Assert.assertTrue( 0 < pathname1.length() );
159 Assert.assertTrue( pathname1.equals(
"lala" ) );
162 final String pathname0 =
"lala/";
164 PrintUtil.
println(System.err,
"test03_basename: cwd "+pathname0+
" -> "+pathname1);
165 Assert.assertTrue( 0 < pathname1.length() );
166 Assert.assertTrue( pathname1.equals(
"lala" ) );
170 final String pathname0 =
"/lala.txt";
172 PrintUtil.
println(System.err,
"test03_basename: cwd "+pathname0+
" -> "+pathname1);
173 Assert.assertTrue( 0 < pathname1.length() );
174 Assert.assertTrue( pathname1.equals(
"lala.txt" ) );
177 final String pathname0 =
"blabla/jaulib/test/sub.txt";
179 PrintUtil.
println(System.err,
"test03_basename: cwd "+pathname0+
" -> "+pathname1);
180 Assert.assertTrue( 0 < pathname1.length() );
181 Assert.assertTrue( pathname1.equals(
"sub.txt" ) );
185 final String pathname0 =
"blabla/jaulib/test/";
187 PrintUtil.
println(System.err,
"test03_basename: cwd "+pathname0+
" -> "+pathname1);
188 Assert.assertTrue( 0 < pathname1.length() );
189 Assert.assertTrue( pathname1.equals(
"test" ) );
193 final String pathname0 =
"blabla/jaulib/test";
195 PrintUtil.
println(System.err,
"test03_basename: cwd "+pathname0+
" -> "+pathname1);
196 Assert.assertTrue( 0 < pathname1.length() );
197 Assert.assertTrue( pathname1.equals(
"test" ) );
201 @Test(timeout = 10000)
202 public final
void test04_dir_item() {
205 final String dirname_ =
"";
208 Assert.assertTrue(
".".equals( di.
dirname() ) );
209 Assert.assertTrue(
".".equals( di.
basename() ) );
210 Assert.assertTrue(
".".equals( di.
path() ) );
213 final String dirname_ =
".";
216 Assert.assertTrue(
".".equals( di.
dirname() ) );
217 Assert.assertTrue(
".".equals( di.
basename() ) );
218 Assert.assertTrue(
".".equals( di.
path() ) );
221 final String dirname_ =
"/";
224 Assert.assertTrue(
"/".equals( di.
dirname() ) );
225 Assert.assertTrue(
".".equals( di.
basename() ) );
226 Assert.assertTrue(
"/".equals( di.
path() ) );
230 final String path1_ =
"lala";
233 Assert.assertTrue(
".".equals( di.
dirname() ) );
234 Assert.assertTrue(
"lala".equals( di.
basename() ) );
235 Assert.assertTrue(
"lala".equals( di.
path() ) );
238 final String path1_ =
"lala/";
241 Assert.assertTrue(
".".equals( di.
dirname() ) );
242 Assert.assertTrue(
"lala".equals( di.
basename() ) );
243 Assert.assertTrue(
"lala".equals( di.
path() ) );
247 final String path1_ =
"/lala";
250 Assert.assertTrue(
"/".equals( di.
dirname() ) );
251 Assert.assertTrue(
"lala".equals( di.
basename() ) );
252 Assert.assertTrue(
"/lala".equals( di.
path() ) );
256 final String path1_ =
"dir0/lala";
259 Assert.assertTrue(
"dir0".equals( di.
dirname() ) );
260 Assert.assertTrue(
"lala".equals( di.
basename() ) );
261 Assert.assertTrue(
"dir0/lala".equals( di.
path() ) );
264 final String path1_ =
"dir0/lala/";
267 Assert.assertTrue(
"dir0".equals( di.
dirname() ) );
268 Assert.assertTrue(
"lala".equals( di.
basename() ) );
269 Assert.assertTrue(
"dir0/lala".equals( di.
path() ) );
272 final String path1_ =
"/dir0/lala";
275 Assert.assertTrue(
"/dir0".equals( di.
dirname() ) );
276 Assert.assertTrue(
"lala".equals( di.
basename() ) );
277 Assert.assertTrue(
"/dir0/lala".equals( di.
path() ) );
280 final String path1_ =
"/dir0/lala/";
283 Assert.assertTrue(
"/dir0".equals( di.
dirname() ) );
284 Assert.assertTrue(
"lala".equals( di.
basename() ) );
285 Assert.assertTrue(
"/dir0/lala".equals( di.
path() ) );
290 final String path1_ =
"/dir0/../lala";
293 Assert.assertTrue(
"/".equals( di.
dirname() ) );
294 Assert.assertTrue(
"lala".equals( di.
basename() ) );
295 Assert.assertTrue(
"/lala".equals( di.
path() ) );
298 final String path1_ =
"dir0/../lala";
301 Assert.assertTrue(
".".equals( di.
dirname() ) );
302 Assert.assertTrue(
"lala".equals( di.
basename() ) );
303 Assert.assertTrue(
"lala".equals( di.
path() ) );
306 final String path1_ =
"../../lala";
309 Assert.assertTrue(
"../..".equals( di.
dirname() ) );
310 Assert.assertTrue(
"lala".equals( di.
basename() ) );
311 Assert.assertTrue(
"../../lala".equals( di.
path() ) );
314 final String path1_ =
"./../lala";
317 Assert.assertTrue(
"..".equals( di.
dirname() ) );
318 Assert.assertTrue(
"lala".equals( di.
basename() ) );
319 Assert.assertTrue(
"../lala".equals( di.
path() ) );
322 final String path1_ =
"dir0/../../lala";
325 Assert.assertTrue(
"..".equals( di.
dirname() ) );
326 Assert.assertTrue(
"lala".equals( di.
basename() ) );
327 Assert.assertTrue(
"../lala".equals( di.
path() ) );
331 final String path1_ =
"dir0/dir1/../lala";
334 Assert.assertTrue(
"dir0".equals( di.
dirname() ) );
335 Assert.assertTrue(
"lala".equals( di.
basename() ) );
336 Assert.assertTrue(
"dir0/lala".equals( di.
path() ) );
339 final String path1_ =
"/dir0/dir1/../lala/";
342 Assert.assertTrue(
"/dir0".equals( di.
dirname() ) );
343 Assert.assertTrue(
"lala".equals( di.
basename() ) );
344 Assert.assertTrue(
"/dir0/lala".equals( di.
path() ) );
347 final String path1_ =
"dir0/dir1/../bbb/ccc/../lala";
350 Assert.assertTrue(
"dir0/bbb".equals( di.
dirname() ) );
351 Assert.assertTrue(
"lala".equals( di.
basename() ) );
352 Assert.assertTrue(
"dir0/bbb/lala".equals( di.
path() ) );
355 final String path1_ =
"dir0/dir1/bbb/../../lala";
358 Assert.assertTrue(
"dir0".equals( di.
dirname() ) );
359 Assert.assertTrue(
"lala".equals( di.
basename() ) );
360 Assert.assertTrue(
"dir0/lala".equals( di.
path() ) );
363 final String path1_ =
"dir0/dir1/bbb/../../../lala";
366 Assert.assertTrue(
".".equals( di.
dirname() ) );
367 Assert.assertTrue(
"lala".equals( di.
basename() ) );
368 Assert.assertTrue(
"lala".equals( di.
path() ) );
371 final String path1_ =
"dir0/dir1/bbb/../../../../lala";
374 Assert.assertTrue(
"..".equals( di.
dirname() ) );
375 Assert.assertTrue(
"lala".equals( di.
basename() ) );
376 Assert.assertTrue(
"../lala".equals( di.
path() ) );
379 final String path1_ =
"dir0/dir1/bbb/../../lala/..";
382 Assert.assertTrue(
".".equals( di.
dirname() ) );
383 Assert.assertTrue(
"dir0".equals( di.
basename() ) );
384 Assert.assertTrue(
"dir0".equals( di.
path() ) );
387 final String path1_ =
"dir0/./dir1/./bbb/../.././lala";
390 Assert.assertTrue(
"dir0".equals( di.
dirname() ) );
391 Assert.assertTrue(
"lala".equals( di.
basename() ) );
392 Assert.assertTrue(
"dir0/lala".equals( di.
path() ) );
395 final String path1_ =
"dir0/./dir1/./bbb/../.././lala/.";
398 Assert.assertTrue(
"dir0".equals( di.
dirname() ) );
399 Assert.assertTrue(
"lala".equals( di.
basename() ) );
400 Assert.assertTrue(
"dir0/lala".equals( di.
path() ) );
403 final String path1_ =
"./dir0/./dir1/./bbb/../.././lala/.";
406 Assert.assertTrue(
"dir0".equals( di.
dirname() ) );
407 Assert.assertTrue(
"lala".equals( di.
basename() ) );
408 Assert.assertTrue(
"dir0/lala".equals( di.
path() ) );
411 final String path1_ =
"/./dir0/./dir1/./bbb/../.././lala/.";
414 Assert.assertTrue(
"/dir0".equals( di.
dirname() ) );
415 Assert.assertTrue(
"lala".equals( di.
basename() ) );
416 Assert.assertTrue(
"/dir0/lala".equals( di.
path() ) );
420 final String path1_ =
"../../test_data/file_01_slink09R1.txt";
423 Assert.assertTrue(
"../../test_data".equals( di.
dirname() ) );
424 Assert.assertTrue(
"file_01_slink09R1.txt".equals( di.
basename() ) );
425 Assert.assertTrue( path1_.equals( di.
path() ) );
429 final String path1_ =
"../../../jaulib/test_data";
432 Assert.assertTrue(
"../../../jaulib".equals( di.
dirname() ) );
433 Assert.assertTrue(
"test_data".equals( di.
basename() ) );
434 Assert.assertTrue( path1_.equals( di.
path() ) );
438 final String path1_ =
"../../../../jaulib/test_data";
441 Assert.assertTrue(
"../../../../jaulib".equals( di.
dirname() ) );
442 Assert.assertTrue(
"test_data".equals( di.
basename() ) );
443 Assert.assertTrue( path1_.equals( di.
path() ) );
447 final String path1_ =
"././././jaulib/test_data";
450 Assert.assertTrue(
"jaulib".equals( di.
dirname() ) );
451 Assert.assertTrue(
"test_data".equals( di.
basename() ) );
452 Assert.assertTrue(
"jaulib/test_data".equals( di.
path() ) );
456 final String path1_ =
"a/././././jaulib/test_data";
459 Assert.assertTrue(
"a/jaulib".equals( di.
dirname() ) );
460 Assert.assertTrue(
"test_data".equals( di.
basename() ) );
461 Assert.assertTrue(
"a/jaulib/test_data".equals( di.
path() ) );
466 final String path1_ =
"/../lala";
469 Assert.assertTrue(
"/..".equals( di.
dirname() ) );
470 Assert.assertTrue(
"lala".equals( di.
basename() ) );
471 Assert.assertTrue(
"/../lala".equals( di.
path() ) );
475 @Test(timeout = 10000)
476 public final
void test05_file_stat() {
486 Assert.assertTrue( !stats.
is_dir() );
487 Assert.assertTrue( stats.
is_file() );
488 Assert.assertTrue( !stats.
is_link() );
489 Assert.assertTrue( 15 == stats.
size() );
493 final FileStats proot_stats = getTestDataDirStats();
496 Assert.assertTrue(
true == proot_stats.
exists() );
497 Assert.assertTrue(
true == proot_stats.
is_dir() );
503 Assert.assertTrue( stats.
exists() );
505 Assert.assertTrue( !stats.
is_dir() );
506 Assert.assertTrue( stats.
is_file() );
507 Assert.assertTrue( !stats.
is_link() );
508 Assert.assertTrue( 15 == stats.
size() );
510 final long link_count[] = { 0 };
512 PrintUtil.
fprintf_td(System.err,
"test05_file_stat: 12: final_target (%d link count): %s\n", link_count[0], final_target);
513 Assert.assertTrue( 0 == link_count[0] );
514 Assert.assertTrue( final_target.
equals( stats ) );
518 Assert.assertTrue( stats2.
exists() );
520 Assert.assertTrue( !stats2.
is_dir() );
521 Assert.assertTrue( stats2.
is_file() );
522 Assert.assertTrue( !stats2.
is_link() );
523 Assert.assertTrue( 15 == stats2.
size() );
524 Assert.assertEquals( stats, stats2 );
528 Assert.assertTrue( stats2.
exists() );
530 Assert.assertTrue( !stats2.
is_dir() );
531 Assert.assertTrue( stats2.
is_file() );
532 Assert.assertTrue( !stats2.
is_link() );
533 Assert.assertNotEquals( stats, stats2 );
540 Assert.assertTrue( stats.
exists() );
542 Assert.assertTrue( stats.
is_dir() );
543 Assert.assertTrue( !stats.
is_file() );
544 Assert.assertTrue( !stats.
is_link() );
545 Assert.assertTrue( 0 == stats.
size() );
547 final long link_count[] = { 0 };
549 PrintUtil.
fprintf_td(System.err,
"test05_file_stat: 13: final_target (%d link count): %s\n", link_count[0], final_target);
550 Assert.assertTrue( 0 == link_count[0] );
551 Assert.assertTrue( final_target.
equals( stats ) );
557 Assert.assertTrue( !stats.
exists() );
559 Assert.assertTrue( !stats.
is_dir() );
560 Assert.assertTrue( !stats.
is_file() );
561 Assert.assertTrue( !stats.
is_link() );
562 Assert.assertTrue( 0 == stats.
size() );
564 final long link_count[] = { 0 };
566 PrintUtil.
fprintf_td(System.err,
"test05_file_stat: 14: final_target (%d link count): %s\n", link_count[0], final_target);
567 Assert.assertTrue( 0 == link_count[0] );
568 Assert.assertTrue( final_target.
equals( stats ) );
572 @Test(timeout = 10000)
573 public final
void test06_file_stat_symlinks() {
577 final FileStats proot_stats = getTestDataDirStats();
578 Assert.assertTrue(
true == proot_stats.
exists() );
579 Assert.assertTrue(
true == proot_stats.
is_dir() );
585 Assert.assertTrue( stats.
exists() );
587 Assert.assertTrue( !stats.
is_dir() );
588 Assert.assertTrue( stats.
is_file() );
589 Assert.assertTrue( stats.
is_link() );
590 Assert.assertTrue( 15 == stats.
size() );
594 final long link_count[] = { 0 };
596 PrintUtil.
fprintf_td(System.err,
"- final_target (%d link count): %s\n", link_count[0], final_target);
597 Assert.assertTrue( 1 == link_count[0] );
598 Assert.assertTrue( final_target != stats );
599 Assert.assertTrue( (proot_stats.
path()+
"/file_01.txt").equals( final_target.
path() ) );
603 Assert.assertTrue(
null != link_target );
605 Assert.assertTrue( final_target.
equals( link_target ) );
606 Assert.assertTrue( !link_target.
is_dir() );
607 Assert.assertTrue( link_target.
is_file() );
608 Assert.assertTrue( !link_target.
is_link() );
610 Assert.assertTrue(
null == link_target.
link_target() );
616 Assert.assertTrue( stats.
exists() );
618 Assert.assertTrue( !stats.
is_dir() );
619 Assert.assertTrue( stats.
is_file() );
620 Assert.assertTrue( stats.
is_link() );
621 Assert.assertTrue( 20 < stats.
size() );
625 final long link_count[] = { 0 };
627 PrintUtil.
fprintf_td(System.err,
"- final_target (%d link count): %s\n", link_count[0], final_target);
628 Assert.assertTrue( 1 == link_count[0] );
629 Assert.assertTrue( final_target != stats );
630 Assert.assertTrue(
"/etc/fstab".equals( final_target.
path() ) );
634 Assert.assertTrue(
null != link_target );
636 Assert.assertTrue( final_target.
equals( link_target ) );
637 Assert.assertTrue( !link_target.
is_dir() );
638 Assert.assertTrue( link_target.
is_file() );
639 Assert.assertTrue( !link_target.
is_link() );
641 Assert.assertTrue(
null == link_target.
link_target() );
647 Assert.assertTrue( stats.
exists() );
649 Assert.assertTrue( !stats.
is_dir() );
650 Assert.assertTrue( stats.
is_file() );
651 Assert.assertTrue( stats.
is_link() );
652 Assert.assertTrue( 15 == stats.
size() );
654 Assert.assertTrue(
"file_01_slink09R1.txt".equals( stats.
link_target_path() ) );
656 final long link_count[] = { 0 };
658 PrintUtil.
fprintf_td(System.err,
"- final_target (%d link count): %s\n", link_count[0], final_target);
659 Assert.assertTrue( 3 == link_count[0] );
660 Assert.assertTrue( final_target != stats );
661 Assert.assertTrue( (proot_stats.
path()+
"/file_01.txt").equals( final_target.
path() ) );
666 Assert.assertTrue( final_target != link_target1 );
667 Assert.assertTrue( (proot_stats.
path()+
"/file_01_slink09R1.txt").equals( link_target1.
path() ) );
668 Assert.assertTrue( 15 == link_target1.
size() );
669 Assert.assertTrue( !link_target1.
is_dir() );
670 Assert.assertTrue( link_target1.
is_file() );
671 Assert.assertTrue( link_target1.
is_link() );
673 Assert.assertTrue(
"file_01_slink01.txt".equals( link_target1.
link_target_path() ) );
676 Assert.assertTrue(
null != link_target2 );
678 Assert.assertTrue( final_target != link_target2 );
679 Assert.assertTrue( link_target1 != link_target2 );
680 Assert.assertTrue( (proot_stats.
path()+
"/file_01_slink01.txt").equals( link_target2.
path() ) );
681 Assert.assertTrue( 15 == link_target2.
size() );
682 Assert.assertTrue( !link_target2.
is_dir() );
683 Assert.assertTrue( link_target2.
is_file() );
684 Assert.assertTrue( link_target2.
is_link() );
686 Assert.assertTrue(
"file_01.txt".equals( link_target2.
link_target_path() ) );
689 Assert.assertTrue(
null != link_target3 );
691 Assert.assertTrue( final_target.
equals( link_target3 ) );
692 Assert.assertTrue( link_target1 != link_target3 );
693 Assert.assertTrue( link_target2 != link_target3 );
694 Assert.assertTrue( 15 == link_target3.
size() );
695 Assert.assertTrue( !link_target3.
is_dir() );
696 Assert.assertTrue( link_target3.
is_file() );
697 Assert.assertTrue( !link_target3.
is_link() );
699 Assert.assertTrue(
null == link_target3.
link_target() );
706 Assert.assertTrue( !stats.
exists() );
708 Assert.assertTrue( !stats.
is_dir() );
709 Assert.assertTrue( !stats.
is_file() );
710 Assert.assertTrue( stats.
is_link() );
711 Assert.assertTrue( 0 == stats.
size() );
713 Assert.assertTrue(
"not_existing_file".equals( stats.
link_target_path() ) );
716 final long link_count[] = { 0 };
718 PrintUtil.
fprintf_td(System.err,
"- final_target (%d link count): %s\n", link_count[0], final_target);
719 Assert.assertTrue( 0 == link_count[0] );
720 Assert.assertTrue( final_target.
equals( stats ) );
726 Assert.assertTrue( !stats.
exists() );
728 Assert.assertTrue( !stats.
is_dir() );
729 Assert.assertTrue( !stats.
is_file() );
730 Assert.assertTrue( stats.
is_link() );
731 Assert.assertTrue( 0 == stats.
size() );
736 final long link_count[] = { 0 };
738 PrintUtil.
fprintf_td(System.err,
"- final_target (%d link count): %s\n", link_count[0], final_target);
739 Assert.assertTrue( 0 == link_count[0] );
740 Assert.assertTrue( final_target.
equals( stats ) );
744 static void test_file_stat_fd_item(
final FMode.
Bit exp_type,
final int fd,
final String named_fd1,
final String named_fd_link) {
745 PrintUtil.
fprintf_td(System.err,
"test_file_stat_fd_item: expect '%s', fd %d, name_fd1 '%s', make_fd_link '%s'\n", exp_type, fd, named_fd1, named_fd_link);
749 Assert.assertTrue( stats.
exists() );
752 Assert.assertTrue( !stats.
is_block() );
753 Assert.assertTrue( !stats.
is_dir() );
755 PrintUtil.
fprintf_td(System.err,
"INFO: Not matching expected type '%s': fd: %s\n", exp_type, stats);
757 Assert.assertTrue( stats.
has_fd() );
758 Assert.assertEquals( fd, stats.
fd() );
760 Assert.assertEquals( 0, stats.
size() );
763 if( !named_fd1.isEmpty() ) {
764 final FileStats stats =
new FileStats(named_fd1);
765 PrintUtil.fprintf_td(System.err,
"fd_1: %s\n", stats);
766 Assert.assertTrue( stats.exists() );
767 Assert.assertTrue( stats.has_access() );
768 Assert.assertTrue( !stats.is_socket() );
769 Assert.assertTrue( !stats.is_block() );
770 Assert.assertTrue( !stats.is_dir() );
771 if( !stats.type_mode().isSet(exp_type) ) {
772 PrintUtil.fprintf_td(System.err,
"INFO: Not matching expected type '%s': fd: %s\n", exp_type, stats);
774 Assert.assertTrue( stats.has_fd() );
775 Assert.assertEquals( fd, stats.fd() );
776 if( !stats.is_file() ) {
777 Assert.assertEquals( 0, stats.size() );
780 if( !named_fd_link.isEmpty() ) {
781 final FileStats stats =
new FileStats(named_fd_link);
782 PrintUtil.fprintf_td(System.err,
"fd_link: %s\n", stats);
783 Assert.assertTrue( stats.exists() );
784 Assert.assertTrue( stats.has_access() );
785 Assert.assertTrue( !stats.is_socket() );
786 Assert.assertTrue( !stats.is_block() );
787 Assert.assertTrue( !stats.is_dir() );
788 if( !stats.type_mode().isSet(exp_type) ) {
789 PrintUtil.fprintf_td(System.err,
"INFO: Not matching expected type '%s': fd: %s\n", exp_type, stats);
791 Assert.assertTrue( stats.has_fd() );
792 Assert.assertEquals( fd, stats.fd() );
793 if( !stats.is_file() ) {
794 Assert.assertEquals( 0, stats.size() );
797 final long link_count[] = { 0 };
798 final FileStats final_target = stats.final_target(link_count);
799 Assert.assertNotNull( final_target );
800 PrintUtil.fprintf_td(System.err,
"- final_target (%d link count): %s\n", link_count[0], final_target);
801 Assert.assertTrue( 1 <= link_count[0] );
802 Assert.assertTrue( 2 >= link_count[0] );
806 @Test(timeout = 10000)
807 public
void test07_file_stat_fd() {
811 final String fd_stdin_1 =
"/dev/fd/0";
812 final String fd_stdout_1 =
"/dev/fd/1";
813 final String fd_stderr_1 =
"/dev/fd/2";
815 final String fd_stdin_l =
"/dev/stdin";
816 final String fd_stdout_l =
"/dev/stdout";
817 final String fd_stderr_l =
"/dev/stderr";
819 test_file_stat_fd_item(
FMode.
Bit.
chr, 0, fd_stdin_1, fd_stdin_l);
820 test_file_stat_fd_item(
FMode.
Bit.
chr, 1, fd_stdout_1, fd_stdout_l);
821 test_file_stat_fd_item(
FMode.
Bit.
chr, 2, fd_stderr_1, fd_stderr_l);
824 final int fd = fos.
fd();
827 Assert.assertTrue( 0 <= fd );
830 }
catch(
final Exception e ) {
835 @Test(timeout = 10000)
836 public final
void test10_mkdir() {
844 Assert.assertTrue( !root_stats.
exists() );
846 Assert.assertTrue( !root_stats.
is_dir() );
847 Assert.assertTrue( !root_stats.
is_file() );
848 Assert.assertTrue( !root_stats.
is_link() );
851 Assert.assertTrue(
true ==
FileUtil.
mkdir(root, mode_def_dir) );
855 Assert.assertTrue( root_stats.
exists() );
857 Assert.assertTrue( root_stats.
is_dir() );
858 Assert.assertTrue( !root_stats.
is_file() );
859 Assert.assertTrue( !root_stats.
is_link() );
865 @Test(timeout = 10000)
866 public
void test11_touch() {
869 final String file_01 = root+
"/data01.txt";
870 final String file_02 = root+
"/data02.txt";
875 Assert.assertTrue( root_stats.
exists() );
877 Assert.assertTrue( root_stats.
is_dir() );
878 Assert.assertTrue( !root_stats.
is_file() );
879 Assert.assertTrue( !root_stats.
is_link() );
884 final Instant now = Instant.now();
887 final Instant btime = file_stats.
btime();
888 final Instant atime = file_stats.
atime();
889 final long atime_td_ms = atime.until(now, ChronoUnit.MILLIS);
890 final Instant mtime = file_stats.
mtime();
891 final long mtime_td_ms = mtime.until(now, ChronoUnit.MILLIS);
894 PrintUtil.
println(System.err,
"atime: "+atime.atZone(ZoneOffset.UTC)+
", td_now "+atime_td_ms+
"ms");
895 PrintUtil.
println(System.err,
"mtime: "+mtime.atZone(ZoneOffset.UTC)+
", td_now "+mtime_td_ms+
"ms");
896 Assert.assertTrue( file_stats.
exists() );
898 Assert.assertTrue( !file_stats.
is_dir() );
899 Assert.assertTrue( file_stats.
is_file() );
900 Assert.assertTrue( !file_stats.
is_link() );
902 Assert.assertTrue( 1000 >= atime_td_ms );
905 Assert.assertTrue( 1000 >= mtime_td_ms );
911 final Instant now = Instant.now();
913 final Instant btime_pre = file_stats_pre.
btime();
914 final Instant atime_pre = file_stats_pre.
atime();
915 final long atime_td_ms = atime_pre.until(now, ChronoUnit.MILLIS);
916 final Instant mtime_pre = file_stats_pre.
mtime();
917 final long mtime_td_ms = mtime_pre.until(now, ChronoUnit.MILLIS);
919 PrintUtil.
println(System.err,
"btime.pre: "+btime_pre.atZone(ZoneOffset.UTC));
920 PrintUtil.
println(System.err,
"atime.pre: "+atime_pre.atZone(ZoneOffset.UTC)+
", td_now "+atime_td_ms+
"ms");
921 PrintUtil.
println(System.err,
"mtime.pre: "+mtime_pre.atZone(ZoneOffset.UTC)+
", td_now "+mtime_td_ms+
"ms");
923 Assert.assertTrue( 1000 >= atime_td_ms );
926 Assert.assertTrue( 1000 >= mtime_td_ms );
930 final Instant ts_20200101 = Instant.ofEpochSecond(1577836800);
931 final Instant atime_set = ts_20200101.plus( 1, ChronoUnit.DAYS).plus(10, ChronoUnit.HOURS);
932 final Instant mtime_set = ts_20200101.plus( 31, ChronoUnit.DAYS).plus(10, ChronoUnit.HOURS);
933 PrintUtil.
println(System.err,
"atime.set: "+atime_set.atZone(ZoneOffset.UTC)+
", "+atime_set.atZone(ZoneOffset.UTC));
934 PrintUtil.
println(System.err,
"mtime.set: "+mtime_set.atZone(ZoneOffset.UTC)+
", "+mtime_set.atZone(ZoneOffset.UTC));
938 final Instant atime_post = file_stats_post.
atime();
939 final Instant mtime_post = file_stats_post.
mtime();
940 PrintUtil.
println(System.err,
"atime.post: "+atime_post.atZone(ZoneOffset.UTC)+
", "+atime_post.atZone(ZoneOffset.UTC));
941 PrintUtil.
println(System.err,
"mtime.post: "+mtime_post.atZone(ZoneOffset.UTC)+
", "+mtime_post.atZone(ZoneOffset.UTC));
944 Assert.assertTrue( file_stats_post.
exists() );
945 Assert.assertTrue( file_stats_post.
has_access() );
946 Assert.assertTrue( !file_stats_post.
is_dir() );
947 Assert.assertTrue( file_stats_post.
is_file() );
948 Assert.assertTrue( !file_stats_post.
is_link() );
950 Assert.assertTrue( atime_set.equals( file_stats_post.
atime() ) );
953 Assert.assertTrue( mtime_set.equals( file_stats_post.
mtime() ) );
961 @Test(timeout = 10000)
962 public
void test20_visit() {
966 final String sub_dir1 = root+
"/sub1";
967 final String sub_dir2 = root+
"/sub2";
968 final String sub_dir3 = root+
"/sub1/sub3";
990 Assert.assertTrue(
true ==
FileUtil.
visit(root, topts_R_FSL_PDL, pv) );
991 PrintUtil.
fprintf_td(System.err,
"test20_visit[R, FSL, PDL]: %s\n%s\n", topts_R_FSL_PDL, stats_R_FSL_PDL);
992 Assert.assertTrue( 12 == stats_R_FSL_PDL.
total_real );
998 Assert.assertTrue( 8 == stats_R_FSL_PDL.
files_real );
1000 Assert.assertTrue( 4 == stats_R_FSL_PDL.
dirs_real );
1010 Assert.assertTrue(
true ==
FileUtil.
visit(root, topts_R_FSL, pv) );
1011 PrintUtil.
fprintf_td(System.err,
"test20_visit[R, FSL]: %s\n%s\n", topts_R_FSL, stats_R_FSL);
1012 Assert.assertTrue( stats_R_FSL_PDL.
equals( stats_R_FSL ) );
1017 @Test(timeout = 10000)
1018 public
void test22_visit_symlinks() {
1022 final FileStats proot_stats = getTestDataDirStats();
1023 Assert.assertTrue(
true == proot_stats.
exists() );
1024 Assert.assertTrue(
true == proot_stats.
is_dir() );
1034 Assert.assertTrue(
true ==
FileUtil.
visit(proot_stats, topts, pv) );
1044 Assert.assertTrue( 3 == stats.
dirs_real );
1057 Assert.assertTrue(
true ==
FileUtil.
visit(proot_stats, topts, pv) );
1067 Assert.assertTrue( 3 == stats.
dirs_real );
1086 stats.
add(item_stats);
1091 Assert.assertTrue(
true ==
FileUtil.
visit(proot_stats, topts, pv_flat) );
1101 Assert.assertTrue( 2 == stats.
dirs_real );
1106 @Test(timeout = 10000)
1107 public
void test30_copy_file2dir() {
1111 final FileStats root_orig_stats = getTestDataDirStats();
1112 Assert.assertTrue(
true == root_orig_stats.
exists() );
1113 Assert.assertTrue(
true == root_orig_stats.
is_dir() );
1115 final String root_copy = root+
"_copy_test30";
1123 Assert.assertTrue(
true == stats.
exists() );
1124 Assert.assertTrue(
true == stats.
ok() );
1125 Assert.assertTrue(
true == stats.
is_dir() );
1131 Assert.assertTrue(
true == source1_stats.
exists() );
1132 Assert.assertTrue(
true == source1_stats.
ok() );
1133 Assert.assertTrue(
true == source1_stats.
is_file() );
1143 Assert.assertTrue(
false == dest_stats.
exists() );
1145 Assert.assertTrue(
true ==
FileUtil.
copy(source1_stats.
path(), root_copy, copts) );
1148 PrintUtil.
fprintf_td(System.err,
"test30_copy_file2dir: 01: dest.post: %s\n", dest_stats);
1149 Assert.assertTrue(
true == dest_stats.
exists() );
1150 Assert.assertTrue(
true == dest_stats.
ok() );
1151 Assert.assertTrue(
true == dest_stats.
is_file() );
1152 Assert.assertTrue( source1_stats.
size() == dest_stats.
size() );
1153 Assert.assertTrue( source1_stats.
mode().
equals( dest_stats.
mode() ) );
1164 Assert.assertTrue(
true == dest_stats.
exists() );
1165 Assert.assertTrue(
true == dest_stats.
ok() );
1166 Assert.assertTrue(
true == dest_stats.
is_file() );
1168 Assert.assertTrue(
false ==
FileUtil.
copy(source1_stats.
path(), root_copy, copts) );
1177 PrintUtil.
fprintf_td(System.err,
"test30_copy_file2dir: 03: source: %s\n", source1_stats);
1181 Assert.assertTrue(
true == dest_stats.
exists() );
1182 Assert.assertTrue(
true == dest_stats.
ok() );
1183 Assert.assertTrue(
true == dest_stats.
is_file() );
1184 Assert.assertTrue( source1_stats.
size() == dest_stats.
size() );
1185 Assert.assertTrue( source1_stats.
mode().
equals( dest_stats.
mode() ) );
1187 Assert.assertTrue(
true ==
FileUtil.
copy(source1_stats.
path(), root_copy, copts) );
1190 PrintUtil.
fprintf_td(System.err,
"test30_copy_file2dir: 03: dest.post: %s\n", dest_stats);
1191 Assert.assertTrue(
true == dest_stats.
exists() );
1192 Assert.assertTrue(
true == dest_stats.
ok() );
1193 Assert.assertTrue(
true == dest_stats.
is_file() );
1194 Assert.assertTrue( source1_stats.
size() == dest_stats.
size() );
1195 Assert.assertTrue( source1_stats.
mode().
equals( dest_stats.
mode() ) );
1201 @Test(timeout = 10000)
1202 public
void test31_copy_file2file() {
1206 final FileStats root_orig_stats = getTestDataDirStats();
1207 Assert.assertTrue(
true == root_orig_stats.
exists() );
1208 Assert.assertTrue(
true == root_orig_stats.
is_dir() );
1210 final String root_copy = root+
"_copy_test31";
1218 Assert.assertTrue(
true == stats.
exists() );
1219 Assert.assertTrue(
true == stats.
ok() );
1220 Assert.assertTrue(
true == stats.
is_dir() );
1226 Assert.assertTrue(
true == source1_stats.
exists() );
1227 Assert.assertTrue(
true == source1_stats.
ok() );
1228 Assert.assertTrue(
true == source1_stats.
is_file() );
1233 Assert.assertTrue(
true == source2_stats.
exists() );
1234 Assert.assertTrue(
true == source2_stats.
ok() );
1235 Assert.assertTrue(
true == source2_stats.
is_file() );
1236 Assert.assertTrue(
true == source2_stats.
is_link() );
1245 PrintUtil.
fprintf_td(System.err,
"test31_copy_file2file: 10: dest.pre: %s\n", dest_stats);
1246 Assert.assertTrue(
false == dest_stats.
exists() );
1248 Assert.assertTrue(
true ==
FileUtil.
copy(source1_stats.
path(), root_copy+
"/file_10.txt", copts) );
1252 PrintUtil.
fprintf_td(System.err,
"test31_copy_file2file: 10: dest.post: %s\n", dest_stats);
1253 Assert.assertTrue(
true == dest_stats.
exists() );
1254 Assert.assertTrue(
true == dest_stats.
ok() );
1255 Assert.assertTrue(
true == dest_stats.
is_file() );
1256 Assert.assertTrue( source1_stats.
size() == dest_stats.
size() );
1257 Assert.assertTrue( source1_stats.
mode().
equals( dest_stats.
mode() ) );
1267 PrintUtil.
fprintf_td(System.err,
"test31_copy_file2file: 11: dest.pre: %s\n", dest_stats);
1268 Assert.assertTrue(
true == dest_stats.
exists() );
1269 Assert.assertTrue(
true == dest_stats.
ok() );
1270 Assert.assertTrue(
true == dest_stats.
is_file() );
1272 Assert.assertTrue(
false ==
FileUtil.
copy(source1_stats.
path(), root_copy+
"/file_10.txt", copts) );
1284 PrintUtil.
fprintf_td(System.err,
"test31_copy_file2file: 12: dest.pre: %s\n", dest_stats);
1285 Assert.assertTrue(
true == dest_stats.
exists() );
1286 Assert.assertTrue(
true == dest_stats.
ok() );
1287 Assert.assertTrue(
true == dest_stats.
is_file() );
1288 Assert.assertTrue( source1_stats.
size() == dest_stats.
size() );
1289 Assert.assertTrue( source1_stats.
mode().
equals( dest_stats.
mode() ) );
1291 Assert.assertTrue(
true ==
FileUtil.
copy(source2_stats.
path(), root_copy+
"/file_10.txt", copts) );
1295 PrintUtil.
fprintf_td(System.err,
"test31_copy_file2file: 12: dest.post: %s\n", dest_stats);
1296 Assert.assertTrue(
true == dest_stats.
exists() );
1297 Assert.assertTrue(
true == dest_stats.
ok() );
1298 Assert.assertTrue(
true == dest_stats.
is_file() );
1299 Assert.assertTrue(
false == dest_stats.
is_link() );
1300 Assert.assertTrue( source2_stats.
size() == dest_stats.
size() );
1307 @Test(timeout = 10000)
1308 public
void test40_copy_ext_r_p() {
1312 final FileStats root_orig_stats = getTestDataDirStats();
1313 Assert.assertTrue(
true == root_orig_stats.
exists() );
1314 Assert.assertTrue(
true == root_orig_stats.
is_dir() );
1322 final String root_copy = root+
"_copy_test40";
1324 testxx_copy_r_p(
"test40_copy_ext_r_p", root_orig_stats, 0 , root_copy, copts,
false );
1328 @Test(timeout = 10000)
1329 public
void test41_copy_ext_r_p_below() {
1333 final FileStats root_orig_stats = getTestDataDirStats();
1334 Assert.assertTrue(
true == root_orig_stats.
exists() );
1335 Assert.assertTrue(
true == root_orig_stats.
is_dir() );
1343 final String root_copy_parent = root+
"_copy_test41_parent";
1346 testxx_copy_r_p(
"test41_copy_ext_r_p_below", root_orig_stats, 0 , root_copy_parent, copts,
false );
1350 @Test(timeout = 10000)
1351 public
void test42_copy_ext_r_p_into() {
1355 final FileStats root_orig_stats = getTestDataDirStats();
1356 Assert.assertTrue(
true == root_orig_stats.
exists() );
1357 Assert.assertTrue(
true == root_orig_stats.
is_dir() );
1366 final String root_copy = root+
"_copy_test42_into";
1369 testxx_copy_r_p(
"test42_copy_ext_r_p_into", root_orig_stats, 0 , root_copy, copts,
false );
1373 @Test(timeout = 10000)
1374 public
void test43_copy_ext_r_p_over() {
1378 final FileStats root_orig_stats = getTestDataDirStats();
1379 Assert.assertTrue(
true == root_orig_stats.
exists() );
1380 Assert.assertTrue(
true == root_orig_stats.
is_dir() );
1388 final String root_copy = root+
"_copy_test43_over";
1391 final String root_copy_sub = root_copy+
"/"+root_orig_stats.
item().
basename();
1393 testxx_copy_r_p(
"test43_copy_ext_r_p_over", root_orig_stats, 0 , root_copy, copts,
false );
1397 @Test(timeout = 10000)
1398 public
void test49_copy_ext_r_p_vfat() {
1404 if( !dest_fs_vfat_stats.
is_dir() ) {
1405 PrintUtil.
fprintf_td(System.err,
"test49_copy_ext_r_p_vfat: Skipped, no vfat dest-dir %s\n", dest_fs_vfat_stats);
1408 final String dest_vfat_parent = dest_fs_vfat+
"/test49_data_sink";
1411 PrintUtil.
fprintf_td(System.err,
"test49_copy_ext_r_p_vfat: Skipped, couldn't create vfat dest folder %s\n", dest_vfat_parent);
1416 final FileStats root_orig_stats = getTestDataDirStats();
1417 Assert.assertTrue(
true == root_orig_stats.
exists() );
1418 Assert.assertTrue(
true == root_orig_stats.
is_dir() );
1427 final String dest_vfat_dir = dest_vfat_parent+
"/"+root;
1428 testxx_copy_r_p(
"test49_copy_ext_r_p_vfat", root_orig_stats, 0 , dest_vfat_dir, copts,
true );
1432 @Test(timeout = 10000)
1433 public
void test50_copy_ext_r_p_fsl() {
1437 final FileStats root_orig_stats = getTestDataDirStats();
1438 Assert.assertTrue(
true == root_orig_stats.
exists() );
1439 Assert.assertTrue(
true == root_orig_stats.
is_dir() );
1441 final String root_copy = root+
"_copy_test50";
1451 Assert.assertTrue(
true ==
FileUtil.
copy(root_orig_stats.
path(), root_copy, copts) );
1454 Assert.assertTrue(
true == root_copy_stats.
exists() );
1455 Assert.assertTrue(
true == root_copy_stats.
ok() );
1456 Assert.assertTrue(
true == root_copy_stats.
is_dir() );
1474 Assert.assertTrue(
true ==
FileUtil.
visit(root_orig_stats, topts_orig, pv_orig) );
1475 Assert.assertTrue(
true ==
FileUtil.
visit(root_copy_stats, topts_copy, pv_copy) );
1477 PrintUtil.
fprintf_td(System.err,
"test50_copy_ext_r_p_fsl: copy %s, traverse_orig %s, traverse_copy %s\n", copts, topts_orig, topts_copy);
1479 PrintUtil.
fprintf_td(System.err,
"test50_copy_ext_r_p_fsl: source visitor stats\n%s\n", stats);
1480 PrintUtil.
fprintf_td(System.err,
"test50_copy_ext_r_p_fsl: destination visitor stats\n%s\n", stats_copy);
1490 Assert.assertTrue( 3 == stats.
dirs_real );
1493 Assert.assertTrue( 20 == stats_copy.
total_real );
1499 Assert.assertTrue( 16 == stats_copy.
files_real );
1501 Assert.assertTrue( 4 == stats_copy.
dirs_real );
1505 final String root_copy_renamed = root+
"_copy_test50_renamed";
1507 Assert.assertTrue(
true ==
FileUtil.
rename(root_copy, root_copy_renamed) );
1510 Assert.assertTrue(
false == root_copy_stats2.
exists() );
1513 Assert.assertTrue(
true == root_copy_renamed_stats.
exists() );
1514 Assert.assertTrue(
true == root_copy_renamed_stats.
ok() );
1515 Assert.assertTrue(
true == root_copy_renamed_stats.
is_dir() );
1525 Assert.assertTrue(
true ==
FileUtil.
visit(root_copy_renamed_stats, topts_copy, pv_copy) );
1527 PrintUtil.
fprintf_td(System.err,
"test50_copy_ext_r_p_fsl: renamed: traverse_copy %s\n", topts_copy);
1529 PrintUtil.
fprintf_td(System.err,
"test50_copy_ext_r_p_fsl: renamed: visitor stats\n%s\n", stats_copy);
1531 Assert.assertTrue( 20 == stats_copy.
total_real );
1537 Assert.assertTrue( 16 == stats_copy.
files_real );
1539 Assert.assertTrue( 4 == stats_copy.
dirs_real );
1546 public static void main(
final String args[]) {
void add(final FileStats element_stats)
boolean equals(final Object other)
int total_sym_links_existing
int total_sym_links_not_existing
static void main(final String args[])
Filesystem copy options used to copy() path elements.
CopyOptions set(final Bit bit)
Sets the given bit and returns this instance for chaining.
Representing a directory item split into dirname() and basename().
String basename()
Return the basename, shall not be empty nor contain a dirname.
String dirname()
Returns the dirname, shall not be empty and denotes .
String path()
Returns a full unix path representation combining dirname() and basename().
Generic file type and POSIX protection mode bits as used in file_stats, touch(), mkdir() etc.
static final FMode def_file
Default file protection bit: Safe default: POSIX S_IRUSR | S_IWUSR | S_IRGRP or read_usr | write_usr ...
boolean isSet(final Bit bit)
boolean equals(final Object other)
static final FMode def_dir
Default directory protection bit: Safe default: POSIX S_IRWXU | S_IRGRP | S_IXGRP or rwx_usr | read_g...
Platform agnostic representation of POSIX ::lstat() and ::stat() for a given pathname.
boolean equals(final Object other)
int fd()
Returns the file descriptor if has_fd(), otherwise -1 for no file descriptor.
String path()
Returns the unix path representation.
Field fields()
Returns the retrieved field_t fields.
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.
FileStats final_target(final long link_count[])
Returns the final target element, either a pointer to this instance if not a symbolic-link or the fin...
boolean has_access()
Returns true if entity gives no access to user, exclusive bit.
FMode prot_mode()
Returns the POSIX protection bit portion of fmode_t, i.e.
boolean is_link()
Returns true if entity is a symbolic link, might be in combination with is_file(),...
String link_target_path()
Returns the stored link-target path this symbolic-link points to if instance is a symbolic-link,...
DirItem item()
Returns the dir_item.
FileStats link_target()
Returns the link-target this symbolic-link points to if instance is a symbolic-link,...
FMode mode()
Returns the FMode, file type and mode.
boolean is_socket()
Returns true if entity is a socket, might be in combination with is_link().
boolean has_fd()
Returns true if entity has a file descriptor.
Instant btime()
Returns the birth time of this element since Unix Epoch, i.e.
boolean is_block()
Returns true if entity is a block device, might be in combination with is_link().
boolean is_dir()
Returns true if entity is a directory, might be in combination with is_link().
Instant atime()
Returns the last access time of this element since Unix Epoch.
boolean has(final Field.Type bit)
Returns true if the given field_t fields were retrieved, otherwise false.
FMode type_mode()
Returns the type bit portion of fmode_t, i.e.
long size()
Returns the size in bytes of this element if is_file(), otherwise zero.
Native file types and functionality.
static boolean touch(final String path, final Instant atime, final Instant mtime, final FMode mode)
Touch the file with given atime and mtime and create file if not existing yet.
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 dirname(final String path)
Return stripped last component from given path separated by /, excluding the trailing separator /.
static native String basename(final String path)
Return stripped leading directory components from given path separated by /.
static boolean mkdir(final String path, final FMode mode)
Create directory.
static boolean remove(final String path, final TraverseOptions topts)
Remove the given path.
static native void sync()
Synchronizes filesystems, i.e.
static native boolean rename(final String oldpath, final String newpath)
Rename oldpath to newpath using POSIX ::rename(), with the following combinations.
static native String to_named_fd(final int fd)
Returns platform dependent named file descriptor of given file descriptor, if supported.
static native String get_cwd()
Return the current working directory or empty on failure.
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.
static final TraverseOptions recursive
static final TraverseOptions none
File based byte output stream, including named file descriptor.
native int fd()
Returns the file descriptor if is_open(), otherwise -1 for no file descriptor.
void close()
Close the stream if supported by the underlying mechanism and dispose the native instance.
static void fprintf_td(final PrintStream out, final String format, final Object ... args)
Convenient PrintStream#printf(String, Object...) invocation, prepending the elapsedTimeMillis() times...
static void println(final PrintStream out, final String msg)
Convenient PrintStream#println(String) invocation, prepending the elapsedTimeMillis() timestamp.
follow_symlinks
Copy referenced symbolic linked files or directories instead of just the symbolic link with property ...
sync
Ensure data and meta-data file synchronization is performed via ::fsync() after asynchronous copy ope...
recursive
Traverse through directories, i.e.
preserve_all
Preserve uid and gid if allowed and access- and modification-timestamps, i.e.
verbose
Enable verbosity mode, show error messages on stderr.
ignore_symlink_errors
Ignore errors from erroneous symlinks, e.g.
overwrite
Overwrite existing destination files.
into_existing_dir
Copy source dir content into an already existing destination directory as if destination directory di...
file
Type: Entity is a file ), might be in combination with link.
def_dir_prot
Default directory protection bit: Safe default: POSIX S_IRWXU | S_IRGRP | S_IXGRP or rwx_usr | read_g...
chr
Type: Entity is a character device ), might be in combination with link.
Filesystem traverse event used to call path_visitor for path elements from visit().
dir_check_entry
Visiting a directory on entry, see traverse_options::dir_check_entry.
follow_symlinks
Traverse through symbolic linked directories if traverse_options::recursive is set,...
dir_entry
Visit the content's parent directory at entry.
dir_check_entry
Call path_visitor at directory entry, allowing path_visitor to skip traversal of this directory if re...
recursive
Traverse through directories, i.e.
dir_exit
Visit the content's parent directory at exit.