MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / make_link_list

Method make_link_list

launcher/FileSystem.cpp:417–472  ·  view source on GitHub ↗

* @brief Make a list of all the links to make * @param offset subdirectory of src to link to dest */

Source from the content-addressed store, hash-verified

415 * @param offset subdirectory of src to link to dest
416 */
417void create_link::make_link_list(const QString& offset)
418{
419 for (auto pair : m_path_pairs) {
420 const QString& srcPath = pair.src;
421 const QString& dstPath = pair.dst;
422
423 auto src = PathCombine(QDir(srcPath).absolutePath(), offset);
424 auto dst = PathCombine(QDir(dstPath).absolutePath(), offset);
425
426 // you can't hard link a directory so make sure if we deal with a directory we do so recursively
427 if (m_useHardLinks)
428 m_recursive = true;
429
430 // Function that'll do the actual linking
431 auto link_file = [&](QString src_path, QString relative_dst_path) {
432 if (m_matcher && (m_matcher->matches(relative_dst_path) != m_whitelist)) {
433 qDebug() << "path" << relative_dst_path << "in black list or not in whitelist";
434 return;
435 }
436
437 auto dst_path = PathCombine(dst, relative_dst_path);
438 LinkPair link = { src_path, dst_path };
439 m_links_to_make.append(link);
440 };
441
442 if ((!m_recursive) || !fs::is_directory(StringUtils::toStdString(src))) {
443 if (m_debug)
444 qDebug() << "linking single file or dir:" << src << "to" << dst;
445 link_file(src, "");
446 } else {
447 if (m_debug)
448 qDebug() << "linking recursively:" << src << "to" << dst << ", max_depth:" << m_max_depth;
449 QDir src_dir(src);
450 QDirIterator source_it(src, QDir::Filter::Files | QDir::Filter::Hidden, QDirIterator::Subdirectories);
451
452 QStringList linkedPaths;
453
454 while (source_it.hasNext()) {
455 auto src_path = source_it.next();
456 auto relative_path = src_dir.relativeFilePath(src_path);
457
458 if (m_max_depth >= 0 && pathDepth(relative_path) > m_max_depth) {
459 relative_path = pathTruncate(relative_path, m_max_depth);
460 src_path = src_dir.filePath(relative_path);
461 if (linkedPaths.contains(src_path)) {
462 continue;
463 }
464 }
465
466 linkedPaths.append(src_path);
467
468 link_file(src_path, relative_path);
469 }
470 }
471 }
472}
473
474bool create_link::make_links()

Callers

nothing calls this directly

Calls 9

PathCombineFunction · 0.85
toStdStringFunction · 0.85
pathDepthFunction · 0.85
pathTruncateFunction · 0.85
appendMethod · 0.80
filePathMethod · 0.80
QDirClass · 0.70
matchesMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected