| 352 | } |
| 353 | |
| 354 | void test_hard_link() |
| 355 | { |
| 356 | QString folder = QFINDTESTDATA("testdata/FileSystem/test_folder"); |
| 357 | auto f = [&folder]() { |
| 358 | // use working dir to prevent makeing a hard link to a tmpfs or across devices |
| 359 | QTemporaryDir tempDir("./tmp"); |
| 360 | tempDir.setAutoRemove(true); |
| 361 | qDebug() << "From:" << folder << "To:" << tempDir.path(); |
| 362 | |
| 363 | QDir target_dir(FS::PathCombine(tempDir.path(), "test_folder")); |
| 364 | qDebug() << tempDir.path(); |
| 365 | qDebug() << target_dir.path(); |
| 366 | FS::create_link lnk(folder, target_dir.path()); |
| 367 | lnk.useHardLinks(true); |
| 368 | lnk.debug(true); |
| 369 | if (!lnk()) { |
| 370 | qDebug() << "Link Failed!" << lnk.getOSError().value() << lnk.getOSError().message().c_str(); |
| 371 | } |
| 372 | |
| 373 | for (auto entry : target_dir.entryList()) { |
| 374 | qDebug() << entry; |
| 375 | QFileInfo entry_lnk_info(target_dir.filePath(entry)); |
| 376 | QVERIFY(!entry_lnk_info.isSymLink()); |
| 377 | QFileInfo entry_orig_info(QDir(folder).filePath(entry)); |
| 378 | if (!entry_lnk_info.isDir()) { |
| 379 | qDebug() << "hard link equivalency?" << entry_lnk_info.absoluteFilePath() << "vs" << entry_orig_info.absoluteFilePath(); |
| 380 | QVERIFY(fs::equivalent(fs::path(StringUtils::toStdString(entry_lnk_info.absoluteFilePath())), |
| 381 | fs::path(StringUtils::toStdString(entry_orig_info.absoluteFilePath())))); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | QFileInfo lnk_info(target_dir.path()); |
| 386 | QVERIFY(lnk_info.exists()); |
| 387 | QVERIFY(!lnk_info.isSymLink()); |
| 388 | |
| 389 | QVERIFY(target_dir.entryList().contains("pack.mcmeta")); |
| 390 | QVERIFY(target_dir.entryList().contains("assets")); |
| 391 | }; |
| 392 | |
| 393 | // first try variant without trailing / |
| 394 | QVERIFY(!folder.endsWith('/')); |
| 395 | f(); |
| 396 | |
| 397 | // then variant with trailing / |
| 398 | folder.append('/'); |
| 399 | QVERIFY(folder.endsWith('/')); |
| 400 | f(); |
| 401 | } |
| 402 | |
| 403 | void test_link_with_blacklist() |
| 404 | { |
nothing calls this directly
no test coverage detected