MCPcopy Create free account
hub / github.com/ElyPrismLauncher/Launcher / test_hard_link

Method test_hard_link

tests/FileSystem_test.cpp:354–401  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 12

PathCombineFunction · 0.85
toStdStringFunction · 0.85
debugMethod · 0.80
valueMethod · 0.80
getOSErrorMethod · 0.80
filePathMethod · 0.80
appendMethod · 0.80
QDirClass · 0.50
pathMethod · 0.45
isSymLinkMethod · 0.45
existsMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected