@@ -281,12 +281,13 @@ class mkdwarfs_tester : public tester_common {
281
281
return filesystem_v2 (*lgr, *os, mm, opt);
282
282
}
283
283
284
- filesystem_v2 fs_from_file (std::string path) {
284
+ filesystem_v2
285
+ fs_from_file (std::string path, filesystem_options const & opt = {}) {
285
286
auto fsimage = fa->get_file (path);
286
287
if (!fsimage) {
287
288
throw std::runtime_error (" file not found: " + path);
288
289
}
289
- return fs_from_data (std::move (fsimage.value ()));
290
+ return fs_from_data (std::move (fsimage.value ()), opt );
290
291
}
291
292
292
293
filesystem_v2 fs_from_stdout (filesystem_options const & opt = {}) {
@@ -2404,8 +2405,6 @@ class map_file_error_test : public testing::TestWithParam<char const*> {};
2404
2405
TEST_P (map_file_error_test, delayed) {
2405
2406
std::string extra_args{GetParam ()};
2406
2407
2407
- // TODO: we must also simulate hardlinks here...
2408
-
2409
2408
auto t = mkdwarfs_tester::create_empty ();
2410
2409
t.add_root_dir ();
2411
2410
t.os ->add_local_files (audio_data_dir);
@@ -2414,6 +2413,25 @@ TEST_P(map_file_error_test, delayed) {
2414
2413
.max_name_len = 8 ,
2415
2414
.with_errors = true });
2416
2415
2416
+ static constexpr size_t const kSizeSmall {1 << 10 };
2417
+ static constexpr size_t const kSizeLarge {1 << 20 };
2418
+ auto gen_small = [] { return test::loremipsum (kSizeLarge ); };
2419
+ auto gen_large = [] { return test::loremipsum (kSizeLarge ); };
2420
+ t.os ->add (" large_link1" , {43 , 0100755 , 2 , 1000 , 100 , kSizeLarge , 42 , 0 , 0 , 0 },
2421
+ gen_large);
2422
+ t.os ->add (" large_link2" , {43 , 0100755 , 2 , 1000 , 100 , kSizeLarge , 42 , 0 , 0 , 0 },
2423
+ gen_large);
2424
+ t.os ->add (" small_link1" , {44 , 0100755 , 2 , 1000 , 100 , kSizeSmall , 42 , 0 , 0 , 0 },
2425
+ gen_small);
2426
+ t.os ->add (" small_link2" , {44 , 0100755 , 2 , 1000 , 100 , kSizeSmall , 42 , 0 , 0 , 0 },
2427
+ gen_small);
2428
+ for (auto const & link :
2429
+ {" large_link1" , " large_link2" , " small_link1" , " small_link2" }) {
2430
+ t.os ->set_map_file_error (
2431
+ fs::path{" /" } / link ,
2432
+ std::make_exception_ptr (std::runtime_error (" map_file_error" )), 0 );
2433
+ }
2434
+
2417
2435
{
2418
2436
std::mt19937_64 rng{42 };
2419
2437
@@ -2444,9 +2462,28 @@ TEST_P(map_file_error_test, delayed) {
2444
2462
2445
2463
EXPECT_EQ (2 , t.run (args)) << t.err ();
2446
2464
2447
- auto fs = t.fs_from_file (" test.dwarfs" );
2465
+ auto fs = t.fs_from_file (" test.dwarfs" , {. metadata = {. enable_nlink = true }} );
2448
2466
// fs.dump(std::cout, 2);
2449
2467
2468
+ {
2469
+ auto large_link1 = fs.find (" /large_link1" );
2470
+ auto large_link2 = fs.find (" /large_link2" );
2471
+ auto small_link1 = fs.find (" /small_link1" );
2472
+ auto small_link2 = fs.find (" /small_link2" );
2473
+
2474
+ ASSERT_TRUE (large_link1);
2475
+ ASSERT_TRUE (large_link2);
2476
+ ASSERT_TRUE (small_link1);
2477
+ ASSERT_TRUE (small_link2);
2478
+ EXPECT_EQ (large_link1->inode_num (), large_link2->inode_num ());
2479
+ EXPECT_EQ (small_link1->inode_num (), small_link2->inode_num ());
2480
+ file_stat st;
2481
+ ASSERT_EQ (0 , fs.getattr (*large_link1, &st));
2482
+ EXPECT_EQ (0 , st.size );
2483
+ ASSERT_EQ (0 , fs.getattr (*small_link1, &st));
2484
+ EXPECT_EQ (0 , st.size );
2485
+ }
2486
+
2450
2487
std::unordered_map<fs::path, std::string, fs_path_hash> actual_files;
2451
2488
fs.walk ([&](auto const & dev) {
2452
2489
auto iv = dev.inode ();
0 commit comments