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() {
53 PlatformRuntime.checkInitialized();
54 final String cwd = FileUtil.get_cwd();
55 PrintUtil.println(System.err,
"test01_cwd: cwd "+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() {
68 PlatformRuntime.checkInitialized();
70 final String pathname0 =
"/";
71 final String pathname1 = FileUtil.dirname(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";
79 final String pathname1 = FileUtil.dirname(pathname0);
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";
86 final String pathname1 = FileUtil.dirname(pathname0);
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/";
93 final String pathname1 = FileUtil.dirname(pathname0);
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";
101 final String pathname1 = FileUtil.dirname(pathname0);
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";
108 final String pathname1 = FileUtil.dirname(pathname0);
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";
115 final String pathname1 = FileUtil.dirname(pathname0);
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/";
122 final String pathname1 = FileUtil.dirname(pathname0);
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";
129 final String pathname1 = FileUtil.dirname(pathname0);
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() {
138 PlatformRuntime.checkInitialized();
140 final String pathname0 =
"/";
141 final String pathname1 = FileUtil.basename(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";
149 final String pathname1 = FileUtil.basename(pathname0);
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";
156 final String pathname1 = FileUtil.basename(pathname0);
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/";
163 final String pathname1 = FileUtil.basename(pathname0);
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";
171 final String pathname1 = FileUtil.basename(pathname0);
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";
178 final String pathname1 = FileUtil.basename(pathname0);
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/";
186 final String pathname1 = FileUtil.basename(pathname0);
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";
194 final String pathname1 = FileUtil.basename(pathname0);
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() {
203 PlatformRuntime.checkInitialized();
205 final String dirname_ =
"";
206 final DirItem di =
new DirItem(dirname_);
207 PrintUtil.println(System.err,
"test04_dir_item: 01 '"+dirname_+
"' -> "+di.toString()+
" -> '"+di.path()+
"'\n");
208 Assert.assertTrue(
".".equals( di.dirname() ) );
209 Assert.assertTrue(
".".equals( di.basename() ) );
210 Assert.assertTrue(
".".equals( di.path() ) );
213 final String dirname_ =
".";
214 final DirItem di =
new DirItem(dirname_);
215 PrintUtil.println(System.err,
"test04_dir_item: 02 '"+dirname_+
"' -> "+di.toString()+
" -> '"+di.path()+
"'\n");
216 Assert.assertTrue(
".".equals( di.dirname() ) );
217 Assert.assertTrue(
".".equals( di.basename() ) );
218 Assert.assertTrue(
".".equals( di.path() ) );
221 final String dirname_ =
"/";
222 final DirItem di =
new DirItem(dirname_);
223 PrintUtil.println(System.err,
"test04_dir_item: 03 '"+dirname_+
"' -> "+di.toString()+
" -> '"+di.path()+
"'\n");
224 Assert.assertTrue(
"/".equals( di.dirname() ) );
225 Assert.assertTrue(
".".equals( di.basename() ) );
226 Assert.assertTrue(
"/".equals( di.path() ) );
230 final String path1_ =
"lala";
231 final DirItem di =
new DirItem(path1_);
232 PrintUtil.println(System.err,
"test04_dir_item: 10 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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/";
239 final DirItem di =
new DirItem(path1_);
240 PrintUtil.println(System.err,
"test04_dir_item: 11 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
248 final DirItem di =
new DirItem(path1_);
249 PrintUtil.println(System.err,
"test04_dir_item: 12 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
257 final DirItem di =
new DirItem(path1_);
258 PrintUtil.println(System.err,
"test04_dir_item: 20 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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/";
265 final DirItem di =
new DirItem(path1_);
266 PrintUtil.println(System.err,
"test04_dir_item: 21 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
273 final DirItem di =
new DirItem(path1_);
274 PrintUtil.println(System.err,
"test04_dir_item: 22 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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/";
281 final DirItem di =
new DirItem(path1_);
282 PrintUtil.println(System.err,
"test04_dir_item: 23 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
291 final DirItem di =
new DirItem(path1_);
292 PrintUtil.println(System.err,
"test04_dir_item: 30 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
299 final DirItem di =
new DirItem(path1_);
300 PrintUtil.println(System.err,
"test04_dir_item: 31 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
307 final DirItem di =
new DirItem(path1_);
308 PrintUtil.println(System.err,
"test04_dir_item: 32 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
315 final DirItem di =
new DirItem(path1_);
316 PrintUtil.println(System.err,
"test04_dir_item: 33 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
323 final DirItem di =
new DirItem(path1_);
324 PrintUtil.println(System.err,
"test04_dir_item: 34 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
332 final DirItem di =
new DirItem(path1_);
333 PrintUtil.println(System.err,
"test04_dir_item: 40 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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/";
340 final DirItem di =
new DirItem(path1_);
341 PrintUtil.println(System.err,
"test04_dir_item: 41 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
348 final DirItem di =
new DirItem(path1_);
349 PrintUtil.println(System.err,
"test04_dir_item: 42 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
356 final DirItem di =
new DirItem(path1_);
357 PrintUtil.println(System.err,
"test04_dir_item: 43 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
364 final DirItem di =
new DirItem(path1_);
365 PrintUtil.println(System.err,
"test04_dir_item: 44 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
372 final DirItem di =
new DirItem(path1_);
373 PrintUtil.println(System.err,
"test04_dir_item: 45 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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/..";
380 final DirItem di =
new DirItem(path1_);
381 PrintUtil.println(System.err,
"test04_dir_item: 46 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
388 final DirItem di =
new DirItem(path1_);
389 PrintUtil.println(System.err,
"test04_dir_item: 50 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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/.";
396 final DirItem di =
new DirItem(path1_);
397 PrintUtil.println(System.err,
"test04_dir_item: 51 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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/.";
404 final DirItem di =
new DirItem(path1_);
405 PrintUtil.println(System.err,
"test04_dir_item: 51 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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/.";
412 final DirItem di =
new DirItem(path1_);
413 PrintUtil.println(System.err,
"test04_dir_item: 52 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
421 final DirItem di =
new DirItem(path1_);
422 PrintUtil.println(System.err,
"test04_dir_item: 60 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
430 final DirItem di =
new DirItem(path1_);
431 PrintUtil.println(System.err,
"test04_dir_item: 61 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
439 final DirItem di =
new DirItem(path1_);
440 PrintUtil.println(System.err,
"test04_dir_item: 62 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
448 final DirItem di =
new DirItem(path1_);
449 PrintUtil.println(System.err,
"test04_dir_item: 63 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
457 final DirItem di =
new DirItem(path1_);
458 PrintUtil.println(System.err,
"test04_dir_item: 64 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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";
467 final DirItem di =
new DirItem(path1_);
468 PrintUtil.println(System.err,
"test04_dir_item: 99 '"+path1_+
" -> "+di.toString()+
" -> '"+di.path()+
"'\n");
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() {
477 PlatformRuntime.checkInitialized();
478 PrintUtil.println(System.err,
"test05_file_stat\n");
481 final FileStats stats =
new FileStats(project_root_ext+
"/file_01.txt");
482 PrintUtil.fprintf_td(System.err,
"test05_file_stat: 01: %s\n", stats);
483 PrintUtil.fprintf_td(System.err,
"test05_file_stat: 01: fields %s\n", stats.fields());
484 if( stats.exists() ) {
485 Assert.assertTrue( stats.has_access() );
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();
494 PrintUtil.fprintf_td(System.err,
"test05_file_stat: 11: %s\n", proot_stats);
495 PrintUtil.fprintf_td(System.err,
"test05_file_stat: 11: fields %s\n", proot_stats.fields());
496 Assert.assertTrue(
true == proot_stats.exists() );
497 Assert.assertTrue(
true == proot_stats.is_dir() );
500 final FileStats stats =
new FileStats(proot_stats.path()+
"/file_01.txt");
501 PrintUtil.fprintf_td(System.err,
"test05_file_stat: 12: %s\n", stats);
502 PrintUtil.fprintf_td(System.err,
"test05_file_stat: 12: fields %s\n", stats.fields());
503 Assert.assertTrue( stats.exists() );
504 Assert.assertTrue( stats.has_access() );
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 };
511 final FileStats final_target = stats.final_target(link_count);
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 ) );
517 final FileStats stats2 =
new FileStats(proot_stats.path()+
"/file_01.txt");
518 Assert.assertTrue( stats2.exists() );
519 Assert.assertTrue( stats2.has_access() );
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 );
527 final FileStats stats2 =
new FileStats(proot_stats.path()+
"/dir_01/file_02.txt");
528 Assert.assertTrue( stats2.exists() );
529 Assert.assertTrue( stats2.has_access() );
530 Assert.assertTrue( !stats2.is_dir() );
531 Assert.assertTrue( stats2.is_file() );
532 Assert.assertTrue( !stats2.is_link() );
533 Assert.assertNotEquals( stats, stats2 );
537 final FileStats stats =
new FileStats(proot_stats.path()+
"/dir_01");
538 PrintUtil.fprintf_td(System.err,
"test05_file_stat: 13: %s\n", stats);
539 PrintUtil.fprintf_td(System.err,
"test05_file_stat: 13: fields %s\n", stats.fields());
540 Assert.assertTrue( stats.exists() );
541 Assert.assertTrue( stats.has_access() );
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 };
548 final FileStats final_target = stats.final_target(link_count);
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 ) );
554 final FileStats stats =
new FileStats(proot_stats.path()+
"/does_not_exist");
555 PrintUtil.fprintf_td(System.err,
"test05_file_stat: 14: %s\n", stats);
556 PrintUtil.fprintf_td(System.err,
"test05_file_stat: 14: fields %s\n", stats.fields());
557 Assert.assertTrue( !stats.exists() );
558 Assert.assertTrue( stats.has_access() );
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 };
565 final FileStats final_target = stats.final_target(link_count);
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() {
574 PlatformRuntime.checkInitialized();
575 PrintUtil.println(System.err,
"test06_file_stat_symlinks\n");
577 final FileStats proot_stats = getTestDataDirStats();
578 Assert.assertTrue(
true == proot_stats.exists() );
579 Assert.assertTrue(
true == proot_stats.is_dir() );
582 final FileStats stats =
new FileStats(proot_stats.path()+
"/file_01_slink01.txt");
583 PrintUtil.fprintf_td(System.err,
"test06_file_stat_symlinks: 13: %s\n", stats);
584 PrintUtil.fprintf_td(System.err,
"test06_file_stat_symlinks: 13: fields %s\n", stats.fields());
585 Assert.assertTrue( stats.exists() );
586 Assert.assertTrue( stats.has_access() );
587 Assert.assertTrue( !stats.is_dir() );
588 Assert.assertTrue( stats.is_file() );
589 Assert.assertTrue( stats.is_link() );
590 Assert.assertTrue( 15 == stats.size() );
591 Assert.assertTrue(
null != stats.link_target_path() );
592 Assert.assertTrue(
"file_01.txt".equals( stats.link_target_path() ) );
594 final long link_count[] = { 0 };
595 final FileStats final_target = stats.final_target(link_count);
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() ) );
601 Assert.assertTrue(
null != stats.link_target() );
602 final FileStats link_target = stats.link_target();
603 Assert.assertTrue(
null != link_target );
604 PrintUtil.fprintf_td(System.err,
"- link_target %s\n", 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() );
609 Assert.assertTrue(
null == link_target.link_target_path() );
610 Assert.assertTrue(
null == link_target.link_target() );
613 final FileStats stats =
new FileStats(proot_stats.path()+
"/fstab_slink07_absolute");
614 PrintUtil.fprintf_td(System.err,
"test06_file_stat_symlinks: 14: %s\n", stats);
615 PrintUtil.fprintf_td(System.err,
"test06_file_stat_symlinks: 14: fields %s\n", stats.fields());
616 Assert.assertTrue( stats.exists() );
617 Assert.assertTrue( stats.has_access() );
618 Assert.assertTrue( !stats.is_dir() );
619 Assert.assertTrue( stats.is_file() );
620 Assert.assertTrue( stats.is_link() );
621 Assert.assertTrue( 20 < stats.size() );
622 Assert.assertTrue(
null != stats.link_target_path() );
623 Assert.assertTrue(
"/etc/fstab".equals( stats.link_target_path() ) );
625 final long link_count[] = { 0 };
626 final FileStats final_target = stats.final_target(link_count);
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() ) );
632 Assert.assertTrue(
null != stats.link_target() );
633 final FileStats link_target = stats.link_target();
634 Assert.assertTrue(
null != link_target );
635 PrintUtil.fprintf_td(System.err,
"- link_target %s\n", 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() );
640 Assert.assertTrue(
null == link_target.link_target_path() );
641 Assert.assertTrue(
null == link_target.link_target() );
644 final FileStats stats =
new FileStats(proot_stats.path()+
"/file_01_slink10R2.txt");
645 PrintUtil.fprintf_td(System.err,
"test06_file_stat_symlinks: 20: %s\n", stats);
646 PrintUtil.fprintf_td(System.err,
"test06_file_stat_symlinks: 20: fields %s\n", stats.fields());
647 Assert.assertTrue( stats.exists() );
648 Assert.assertTrue( stats.has_access() );
649 Assert.assertTrue( !stats.is_dir() );
650 Assert.assertTrue( stats.is_file() );
651 Assert.assertTrue( stats.is_link() );
652 Assert.assertTrue( 15 == stats.size() );
653 Assert.assertTrue(
null != stats.link_target_path() );
654 Assert.assertTrue(
"file_01_slink09R1.txt".equals( stats.link_target_path() ) );
656 final long link_count[] = { 0 };
657 final FileStats final_target = stats.final_target(link_count);
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() ) );
663 Assert.assertTrue(
null != stats.link_target() );
664 final FileStats link_target1 = stats.link_target();
665 PrintUtil.fprintf_td(System.err,
"- link_target1 %s\n", link_target1);
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() );
672 Assert.assertTrue(
null != link_target1.link_target_path() );
673 Assert.assertTrue(
"file_01_slink01.txt".equals( link_target1.link_target_path() ) );
675 final FileStats link_target2 = link_target1.link_target();
676 Assert.assertTrue(
null != link_target2 );
677 PrintUtil.fprintf_td(System.err,
" - link_target2 %s\n", 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() );
685 Assert.assertTrue(
null != link_target2.link_target_path() );
686 Assert.assertTrue(
"file_01.txt".equals( link_target2.link_target_path() ) );
688 final FileStats link_target3 = link_target2.link_target();
689 Assert.assertTrue(
null != link_target3 );
690 PrintUtil.fprintf_td(System.err,
" - link_target3 %s\n", 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() );
698 Assert.assertTrue(
null == link_target3.link_target_path() );
699 Assert.assertTrue(
null == link_target3.link_target() );
703 final FileStats stats =
new FileStats(proot_stats.path()+
"/dead_link23");
704 PrintUtil.fprintf_td(System.err,
"test06_file_stat_symlinks: 30: %s\n", stats);
705 PrintUtil.fprintf_td(System.err,
"test06_file_stat_symlinks: 30: fields %s\n", stats.fields());
706 Assert.assertTrue( !stats.exists() );
707 Assert.assertTrue( stats.has_access() );
708 Assert.assertTrue( !stats.is_dir() );
709 Assert.assertTrue( !stats.is_file() );
710 Assert.assertTrue( stats.is_link() );
711 Assert.assertTrue( 0 == stats.size() );
712 Assert.assertTrue(
null != stats.link_target_path() );
713 Assert.assertTrue(
"not_existing_file".equals( stats.link_target_path() ) );
714 Assert.assertTrue(
null == stats.link_target() );
716 final long link_count[] = { 0 };
717 final FileStats final_target = stats.final_target(link_count);
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 ) );
723 final FileStats stats =
new FileStats(proot_stats.path()+
"/dead_link22");
724 PrintUtil.fprintf_td(System.err,
"test06_file_stat_symlinks: 31: %s\n", stats);
725 PrintUtil.fprintf_td(System.err,
"test06_file_stat_symlinks: 31: fields %s\n", stats.fields());
726 Assert.assertTrue( !stats.exists() );
727 Assert.assertTrue( stats.has_access() );
728 Assert.assertTrue( !stats.is_dir() );
729 Assert.assertTrue( !stats.is_file() );
730 Assert.assertTrue( stats.is_link() );
731 Assert.assertTrue( 0 == stats.size() );
732 Assert.assertTrue(
null != stats.link_target_path() );
733 Assert.assertTrue(
"dead_link21".equals( stats.link_target_path() ) );
734 Assert.assertTrue(
null == stats.link_target() );
736 final long link_count[] = { 0 };
737 final FileStats final_target = stats.final_target(link_count);
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);
747 final FileStats stats =
new FileStats(fd);
748 PrintUtil.fprintf_td(System.err,
"fd: %s\n", stats);
749 Assert.assertTrue( stats.exists() );
750 Assert.assertTrue( stats.has_access() );
751 Assert.assertTrue( !stats.is_socket() );
752 Assert.assertTrue( !stats.is_block() );
753 Assert.assertTrue( !stats.is_dir() );
754 if( !stats.type_mode().isSet(exp_type) ) {
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() );
759 if( !stats.is_file() ) {
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() {
808 PlatformRuntime.checkInitialized();
809 PrintUtil.println(System.err,
"test07_file_stat_fd\n");
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);
823 final ByteOutStream_File fos =
new ByteOutStream_File(
"test07_file_stat_fd_tmp", FMode.def_file);
824 final int fd = fos.fd();
825 final String named_fd = FileUtil.to_named_fd(fd);
826 PrintUtil.fprintf_td(System.err,
"XXXX.0: %s -> fd %d, named_fd '%s'\n", fos.toString(), fd, named_fd);
827 Assert.assertTrue( 0 <= fd );
828 test_file_stat_fd_item(FMode.Bit.file, fd, FileUtil.to_named_fd(fd),
"");
830 }
catch(
final Exception e ) {
835 @Test(timeout = 10000)
836 public final
void test10_mkdir() {
837 PlatformRuntime.checkInitialized();
838 PrintUtil.println(System.err,
"test10_mkdir\n");
840 FileUtil.remove(root, TraverseOptions.recursive);
842 final FileStats root_stats =
new FileStats(root);
843 PrintUtil.println(System.err,
"root_stats.pre: "+root_stats);
844 Assert.assertTrue( !root_stats.exists() );
845 Assert.assertTrue( root_stats.has_access() );
846 Assert.assertTrue( !root_stats.is_dir() );
847 Assert.assertTrue( !root_stats.is_file() );
848 Assert.assertTrue( !root_stats.is_link() );
850 final FMode mode_def_dir =
new FMode(FMode.Bit.def_dir_prot.value);
851 Assert.assertTrue(
true == FileUtil.mkdir(root, mode_def_dir) );
853 final FileStats root_stats =
new FileStats(root);
854 PrintUtil.println(System.err,
"root_stats.post: "+root_stats);
855 Assert.assertTrue( root_stats.exists() );
856 Assert.assertTrue( root_stats.has_access() );
857 Assert.assertTrue( root_stats.is_dir() );
858 Assert.assertTrue( !root_stats.is_file() );
859 Assert.assertTrue( !root_stats.is_link() );
861 Assert.assertTrue(
false == FileUtil.remove(root, TraverseOptions.none) );
862 Assert.assertTrue(
true == FileUtil.remove(root, TraverseOptions.recursive) );
865 @Test(timeout = 10000)
866 public
void test11_touch() {
867 PlatformRuntime.checkInitialized();
868 PrintUtil.println(System.err,
"test11_touch\n");
869 final String file_01 = root+
"/data01.txt";
870 final String file_02 = root+
"/data02.txt";
871 Assert.assertTrue(
true == FileUtil.mkdir(root, FMode.def_dir) );
873 final FileStats root_stats =
new FileStats(root);
874 PrintUtil.println(System.err,
"root_stats1.post: "+root_stats);
875 Assert.assertTrue( root_stats.exists() );
876 Assert.assertTrue( root_stats.has_access() );
877 Assert.assertTrue( root_stats.is_dir() );
878 Assert.assertTrue( !root_stats.is_file() );
879 Assert.assertTrue( !root_stats.is_link() );
882 Assert.assertTrue(
true == FileUtil.touch(file_01, FMode.def_dir) );
884 final Instant now = Instant.now();
885 final FileStats file_stats =
new FileStats(file_01);
886 PrintUtil.println(System.err,
"file_stats2.post: "+file_stats);
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);
892 PrintUtil.println(System.err,
"now: "+now.atZone(ZoneOffset.UTC));
893 PrintUtil.println(System.err,
"btime: "+btime.atZone(ZoneOffset.UTC));
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() );
897 Assert.assertTrue( file_stats.has_access() );
898 Assert.assertTrue( !file_stats.is_dir() );
899 Assert.assertTrue( file_stats.is_file() );
900 Assert.assertTrue( !file_stats.is_link() );
901 if( file_stats.has( FileStats.Field.Type.atime ) ) {
902 Assert.assertTrue( 1000 >= atime_td_ms );
904 if( file_stats.has( FileStats.Field.Type.mtime ) ) {
905 Assert.assertTrue( 1000 >= mtime_td_ms );
909 Assert.assertTrue(
true == FileUtil.touch(file_02, FMode.def_dir ) );
911 final Instant now = Instant.now();
912 final FileStats file_stats_pre =
new FileStats(file_02);
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);
918 PrintUtil.println(System.err,
"now : "+now.atZone(ZoneOffset.UTC));
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");
922 if( file_stats_pre.has( FileStats.Field.Type.atime ) ) {
923 Assert.assertTrue( 1000 >= atime_td_ms );
925 if( file_stats_pre.has( FileStats.Field.Type.mtime ) ) {
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));
935 Assert.assertTrue(
true == FileUtil.touch(file_02, atime_set, mtime_set, FMode.def_file) );
937 final FileStats file_stats_post =
new FileStats(file_02);
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));
942 PrintUtil.fprintf_td(System.err,
"test11_touch: 03: %s\n", file_stats_post);
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() );
949 if( file_stats_post.has( FileStats.Field.Type.atime ) ) {
950 Assert.assertTrue( atime_set.equals( file_stats_post.atime() ) );
952 if( file_stats_post.has( FileStats.Field.Type.mtime ) ) {
953 Assert.assertTrue( mtime_set.equals( file_stats_post.mtime() ) );
958 Assert.assertTrue(
true == FileUtil.remove(root, TraverseOptions.recursive) );
961 @Test(timeout = 10000)
962 public
void test20_visit() {
963 PlatformRuntime.checkInitialized();
964 PrintUtil.println(System.err,
"test20_visit\n");
966 final String sub_dir1 = root+
"/sub1";
967 final String sub_dir2 = root+
"/sub2";
968 final String sub_dir3 = root+
"/sub1/sub3";
970 Assert.assertTrue(
true == FileUtil.mkdir(root, FMode.def_dir) );
971 Assert.assertTrue(
true == FileUtil.touch(root+
"/data01.txt", FMode.def_file) );
972 Assert.assertTrue(
true == FileUtil.touch(root+
"/data02.txt", FMode.def_file) );
973 Assert.assertTrue(
true == FileUtil.mkdir(sub_dir1, FMode.def_dir) );
974 Assert.assertTrue(
true == FileUtil.mkdir(sub_dir2, FMode.def_dir) );
975 Assert.assertTrue(
true == FileUtil.mkdir(sub_dir3, FMode.def_dir) );
976 Assert.assertTrue(
true == FileUtil.touch(sub_dir1+
"/data03.txt", FMode.def_file) );
977 Assert.assertTrue(
true == FileUtil.touch(sub_dir1+
"/data04.txt", FMode.def_file) );
978 Assert.assertTrue(
true == FileUtil.touch(sub_dir2+
"/data05.txt", FMode.def_file) );
979 Assert.assertTrue(
true == FileUtil.touch(sub_dir2+
"/data06.txt", FMode.def_file) );
980 Assert.assertTrue(
true == FileUtil.touch(sub_dir3+
"/data07.txt", FMode.def_file) );
981 Assert.assertTrue(
true == FileUtil.touch(sub_dir3+
"/data08.txt", FMode.def_file) );
983 final TraverseOptions topts_R_FSL_PDL =
new TraverseOptions();
984 topts_R_FSL_PDL.set(TraverseOptions.Bit.recursive);
985 topts_R_FSL_PDL.set(TraverseOptions.Bit.follow_symlinks);
986 topts_R_FSL_PDL.set(TraverseOptions.Bit.dir_exit);
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 );
1003 final TraverseOptions topts_R_FSL =
new TraverseOptions();
1004 topts_R_FSL.set(TraverseOptions.Bit.recursive);
1005 topts_R_FSL.set(TraverseOptions.Bit.follow_symlinks);
1006 topts_R_FSL.set(TraverseOptions.Bit.dir_entry);
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 ) );
1014 Assert.assertTrue(
true == FileUtil.remove(root, TraverseOptions.recursive) );
1017 @Test(timeout = 10000)
1018 public
void test22_visit_symlinks() {
1019 PlatformRuntime.checkInitialized();
1020 PrintUtil.println(System.err,
"test22_visit_symlinks\n");
1022 final FileStats proot_stats = getTestDataDirStats();
1023 Assert.assertTrue(
true == proot_stats.exists() );
1024 Assert.assertTrue(
true == proot_stats.is_dir() );
1028 final TraverseOptions topts =
new TraverseOptions();
1029 topts.set(TraverseOptions.Bit.recursive);
1030 topts.set(TraverseOptions.Bit.dir_exit);
1034 Assert.assertTrue(
true == FileUtil.visit(proot_stats, topts, pv) );
1035 PrintUtil.fprintf_td(System.err,
"test22_visit[R]: %s\n%s\n", topts, stats);
1044 Assert.assertTrue( 3 == stats.
dirs_real );
1050 final TraverseOptions topts =
new TraverseOptions();
1051 topts.set(TraverseOptions.Bit.recursive);
1052 topts.set(TraverseOptions.Bit.dir_entry);
1053 topts.set(TraverseOptions.Bit.follow_symlinks);
1057 Assert.assertTrue(
true == FileUtil.visit(proot_stats, topts, pv) );
1058 PrintUtil.fprintf_td(System.err,
"test22_visit[R, FSL]: %s\n%s\n", topts, stats);
1067 Assert.assertTrue( 3 == stats.
dirs_real );
1072 final TraverseOptions topts =
new TraverseOptions();
1073 topts.set(TraverseOptions.Bit.recursive);
1074 topts.set(TraverseOptions.Bit.dir_check_entry);
1075 topts.set(TraverseOptions.Bit.dir_entry);
1076 topts.set(TraverseOptions.Bit.follow_symlinks);
1081 public boolean visit(
final TraverseEvent tevt,
final FileStats item_stats,
final long depth) {
1083 if( TraverseEvent.dir_check_entry == tevt && depth > 1 ) {
1086 stats.
add(item_stats);
1091 Assert.assertTrue(
true == FileUtil.visit(proot_stats, topts, pv_flat) );
1092 PrintUtil.fprintf_td(System.err,
"test22_visit[F, FSL]: %s\n%s\n", topts, stats);
1101 Assert.assertTrue( 2 == stats.
dirs_real );
1106 @Test(timeout = 10000)
1107 public
void test30_copy_file2dir() {
1108 PlatformRuntime.checkInitialized();
1109 PrintUtil.println(System.err,
"test30_copy_file2dir\n");
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";
1118 FileUtil.remove(root_copy, TraverseOptions.recursive);
1120 Assert.assertTrue(
true == FileUtil.mkdir(root_copy, FMode.def_dir) );
1122 final FileStats stats =
new FileStats(root_copy);
1123 Assert.assertTrue(
true == stats.exists() );
1124 Assert.assertTrue(
true == stats.ok() );
1125 Assert.assertTrue(
true == stats.is_dir() );
1128 final FileStats source1_stats =
new FileStats(root_orig_stats.path()+
"/file_01.txt");
1129 PrintUtil.fprintf_td(System.err,
"test30_copy_file2dir: source1: %s\n", source1_stats);
1131 Assert.assertTrue(
true == source1_stats.exists() );
1132 Assert.assertTrue(
true == source1_stats.ok() );
1133 Assert.assertTrue(
true == source1_stats.is_file() );
1137 final CopyOptions copts =
new CopyOptions();
1138 copts.set(CopyOptions.Bit.preserve_all);
1139 copts.set(CopyOptions.Bit.verbose);
1141 final FileStats dest_stats =
new FileStats(root_copy+
"/file_01.txt");
1142 PrintUtil.fprintf_td(System.err,
"test30_copy_file2dir: 01: dest.pre: %s\n", dest_stats);
1143 Assert.assertTrue(
false == dest_stats.exists() );
1145 Assert.assertTrue(
true == FileUtil.copy(source1_stats.path(), root_copy, copts) );
1147 final FileStats dest_stats =
new FileStats(root_copy+
"/file_01.txt");
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() ) );
1158 final CopyOptions copts =
new CopyOptions();
1159 copts.set(CopyOptions.Bit.preserve_all);
1160 copts.set(CopyOptions.Bit.verbose);
1162 final FileStats dest_stats =
new FileStats(root_copy+
"/file_01.txt");
1163 PrintUtil.fprintf_td(System.err,
"test30_copy_file2dir: 02: dest.pre: %s\n", dest_stats);
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) );
1172 final CopyOptions copts =
new CopyOptions();
1173 copts.set(CopyOptions.Bit.preserve_all);
1174 copts.set(CopyOptions.Bit.overwrite);
1175 copts.set(CopyOptions.Bit.verbose);
1177 PrintUtil.fprintf_td(System.err,
"test30_copy_file2dir: 03: source: %s\n", source1_stats);
1179 final FileStats dest_stats =
new FileStats(root_copy+
"/file_01.txt");
1180 PrintUtil.fprintf_td(System.err,
"test30_copy_file2dir: 03: dest.pre: %s\n", dest_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) );
1189 final FileStats dest_stats =
new FileStats(root_copy+
"/file_01.txt");
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() ) );
1198 Assert.assertTrue(
true == FileUtil.remove(root_copy, TraverseOptions.recursive) );
1201 @Test(timeout = 10000)
1202 public
void test31_copy_file2file() {
1203 PlatformRuntime.checkInitialized();
1204 PrintUtil.println(System.err,
"test31_copy_file2file\n");
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";
1213 FileUtil.remove(root_copy, TraverseOptions.recursive);
1215 Assert.assertTrue(
true == FileUtil.mkdir(root_copy, FMode.def_dir) );
1217 final FileStats stats =
new FileStats(root_copy);
1218 Assert.assertTrue(
true == stats.exists() );
1219 Assert.assertTrue(
true == stats.ok() );
1220 Assert.assertTrue(
true == stats.is_dir() );
1223 final FileStats source1_stats =
new FileStats(root_orig_stats.path()+
"/file_01.txt");
1224 PrintUtil.fprintf_td(System.err,
"test31_copy_file2file: source1: %s\n", source1_stats);
1226 Assert.assertTrue(
true == source1_stats.exists() );
1227 Assert.assertTrue(
true == source1_stats.ok() );
1228 Assert.assertTrue(
true == source1_stats.is_file() );
1230 final FileStats source2_stats =
new FileStats(root_orig_stats.path()+
"/README_slink08_relext.txt");
1231 PrintUtil.fprintf_td(System.err,
"test31_copy_file2file: source2: %s\n", source2_stats);
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() );
1240 final CopyOptions copts =
new CopyOptions();
1241 copts.set(CopyOptions.Bit.preserve_all)
1242 .set(CopyOptions.Bit.verbose);
1244 final FileStats dest_stats =
new FileStats(root_copy+
"/file_10.txt");
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) );
1251 final FileStats dest_stats =
new FileStats(root_copy+
"/file_10.txt");
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() ) );
1262 final CopyOptions copts =
new CopyOptions();
1263 copts.set(CopyOptions.Bit.preserve_all)
1264 .set(CopyOptions.Bit.verbose);
1266 final FileStats dest_stats =
new FileStats(root_copy+
"/file_10.txt");
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) );
1277 final CopyOptions copts =
new CopyOptions();
1278 copts.set(CopyOptions.Bit.preserve_all)
1279 .set(CopyOptions.Bit.overwrite)
1280 .set(CopyOptions.Bit.follow_symlinks)
1281 .set(CopyOptions.Bit.verbose);
1283 final FileStats dest_stats =
new FileStats(root_copy+
"/file_10.txt");
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) );
1294 final FileStats dest_stats =
new FileStats(root_copy+
"/file_10.txt");
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() );
1301 Assert.assertTrue( source2_stats.link_target().prot_mode().equals( dest_stats.prot_mode() ) );
1304 Assert.assertTrue(
true == FileUtil.remove(root_copy, TraverseOptions.recursive) );
1307 @Test(timeout = 10000)
1308 public
void test40_copy_ext_r_p() {
1309 PlatformRuntime.checkInitialized();
1310 PrintUtil.println(System.err,
"test40_copy_ext_r_p\n");
1312 final FileStats root_orig_stats = getTestDataDirStats();
1313 Assert.assertTrue(
true == root_orig_stats.exists() );
1314 Assert.assertTrue(
true == root_orig_stats.is_dir() );
1316 final CopyOptions copts =
new CopyOptions();
1317 copts.set(CopyOptions.Bit.recursive)
1318 .set(CopyOptions.Bit.preserve_all)
1319 .set(CopyOptions.Bit.sync)
1320 .set(CopyOptions.Bit.verbose);
1322 final String root_copy = root+
"_copy_test40";
1323 FileUtil.remove(root_copy, TraverseOptions.recursive);
1324 testxx_copy_r_p(
"test40_copy_ext_r_p", root_orig_stats, 0 , root_copy, copts,
false );
1325 Assert.assertTrue(
true == FileUtil.remove(root_copy, TraverseOptions.recursive) );
1328 @Test(timeout = 10000)
1329 public
void test41_copy_ext_r_p_below() {
1330 PlatformRuntime.checkInitialized();
1331 PrintUtil.println(System.err,
"test41_copy_ext_r_p_below\n");
1333 final FileStats root_orig_stats = getTestDataDirStats();
1334 Assert.assertTrue(
true == root_orig_stats.exists() );
1335 Assert.assertTrue(
true == root_orig_stats.is_dir() );
1337 final CopyOptions copts =
new CopyOptions();
1338 copts.set(CopyOptions.Bit.recursive)
1339 .set(CopyOptions.Bit.preserve_all)
1340 .set(CopyOptions.Bit.sync)
1341 .set(CopyOptions.Bit.verbose);
1343 final String root_copy_parent = root+
"_copy_test41_parent";
1344 FileUtil.remove(root_copy_parent, TraverseOptions.recursive);
1345 Assert.assertTrue( FileUtil.mkdir(root_copy_parent) );
1346 testxx_copy_r_p(
"test41_copy_ext_r_p_below", root_orig_stats, 0 , root_copy_parent, copts,
false );
1347 Assert.assertTrue(
true == FileUtil.remove(root_copy_parent, TraverseOptions.recursive) );
1350 @Test(timeout = 10000)
1351 public
void test42_copy_ext_r_p_into() {
1352 PlatformRuntime.checkInitialized();
1353 PrintUtil.println(System.err,
"test42_copy_ext_r_p_into\n");
1355 final FileStats root_orig_stats = getTestDataDirStats();
1356 Assert.assertTrue(
true == root_orig_stats.exists() );
1357 Assert.assertTrue(
true == root_orig_stats.is_dir() );
1359 final CopyOptions copts =
new CopyOptions();
1360 copts.set(CopyOptions.Bit.recursive)
1361 .set(CopyOptions.Bit.into_existing_dir)
1362 .set(CopyOptions.Bit.preserve_all)
1363 .set(CopyOptions.Bit.sync)
1364 .set(CopyOptions.Bit.verbose);
1366 final String root_copy = root+
"_copy_test42_into";
1367 FileUtil.remove(root_copy, TraverseOptions.recursive);
1368 Assert.assertTrue( FileUtil.mkdir(root_copy) );
1369 testxx_copy_r_p(
"test42_copy_ext_r_p_into", root_orig_stats, 0 , root_copy, copts,
false );
1370 Assert.assertTrue(
true == FileUtil.remove(root_copy, TraverseOptions.recursive) );
1373 @Test(timeout = 10000)
1374 public
void test43_copy_ext_r_p_over() {
1375 PlatformRuntime.checkInitialized();
1376 PrintUtil.println(System.err,
"test43_copy_ext_r_p_over\n");
1378 final FileStats root_orig_stats = getTestDataDirStats();
1379 Assert.assertTrue(
true == root_orig_stats.exists() );
1380 Assert.assertTrue(
true == root_orig_stats.is_dir() );
1382 final CopyOptions copts =
new CopyOptions();
1383 copts.set(CopyOptions.Bit.recursive)
1384 .set(CopyOptions.Bit.preserve_all)
1385 .set(CopyOptions.Bit.sync)
1386 .set(CopyOptions.Bit.verbose);
1388 final String root_copy = root+
"_copy_test43_over";
1389 FileUtil.remove(root_copy, TraverseOptions.recursive);
1390 Assert.assertTrue( FileUtil.mkdir(root_copy) );
1391 final String root_copy_sub = root_copy+
"/"+root_orig_stats.item().basename();
1392 Assert.assertTrue( FileUtil.mkdir(root_copy_sub) );
1393 testxx_copy_r_p(
"test43_copy_ext_r_p_over", root_orig_stats, 0 , root_copy, copts,
false );
1394 Assert.assertTrue(
true == FileUtil.remove(root_copy, TraverseOptions.recursive) );
1397 @Test(timeout = 10000)
1398 public
void test49_copy_ext_r_p_vfat() {
1399 PlatformRuntime.checkInitialized();
1400 PrintUtil.println(System.err,
"test49_copy_ext_r_p_vfat\n");
1403 final FileStats dest_fs_vfat_stats =
new FileStats(dest_fs_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";
1409 FileUtil.remove(dest_vfat_parent, TraverseOptions.recursive);
1410 if( !FileUtil.mkdir(dest_vfat_parent) ) {
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() );
1420 final CopyOptions copts =
new CopyOptions();
1421 copts.set(CopyOptions.Bit.recursive)
1422 .set(CopyOptions.Bit.preserve_all)
1423 .set(CopyOptions.Bit.ignore_symlink_errors)
1424 .set(CopyOptions.Bit.sync)
1425 .set(CopyOptions.Bit.verbose);
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 );
1429 Assert.assertTrue(
true == FileUtil.remove(dest_vfat_parent, TraverseOptions.recursive) );
1432 @Test(timeout = 10000)
1433 public
void test50_copy_ext_r_p_fsl() {
1434 PlatformRuntime.checkInitialized();
1435 PrintUtil.println(System.err,
"test50_copy_ext_r_p_fsl\n");
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";
1442 final CopyOptions copts =
new CopyOptions();
1443 copts.set(CopyOptions.Bit.recursive);
1444 copts.set(CopyOptions.Bit.preserve_all);
1445 copts.set(CopyOptions.Bit.follow_symlinks);
1446 copts.set(CopyOptions.Bit.ignore_symlink_errors);
1447 copts.set(CopyOptions.Bit.verbose);
1449 FileUtil.remove(root_copy, TraverseOptions.recursive);
1451 Assert.assertTrue(
true == FileUtil.copy(root_orig_stats.path(), root_copy, copts) );
1453 final FileStats root_copy_stats =
new FileStats(root_copy);
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() );
1459 final TraverseOptions topts_orig =
new TraverseOptions();
1460 topts_orig.set(TraverseOptions.Bit.recursive);
1461 topts_orig.set(TraverseOptions.Bit.dir_entry);
1462 topts_orig.set(TraverseOptions.Bit.follow_symlinks);
1464 final TraverseOptions topts_copy =
new TraverseOptions();
1465 topts_copy.set(TraverseOptions.Bit.recursive);
1466 topts_copy.set(TraverseOptions.Bit.dir_entry);
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) );
1509 final FileStats root_copy_stats2 =
new FileStats(root_copy);
1510 Assert.assertTrue(
false == root_copy_stats2.exists() );
1512 final FileStats root_copy_renamed_stats =
new FileStats(root_copy_renamed);
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() );
1517 final TraverseOptions topts_copy =
new TraverseOptions();
1518 topts_copy.set(TraverseOptions.Bit.recursive);
1519 topts_copy.set(TraverseOptions.Bit.dir_entry);
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 );
1543 Assert.assertTrue(
true == FileUtil.remove(root_copy_renamed, TraverseOptions.recursive) );
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[])