MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / operator()

Method operator()

launcher/FileSystem.cpp:318–386  ·  view source on GitHub ↗

* @brief Copies a directory and it's contents from src to dest * @param offset subdirectory form src to copy to dest * @return if there was an error during the filecopy */

Source from the content-addressed store, hash-verified

316 * @return if there was an error during the filecopy
317 */
318bool copy::operator()(const QString& offset, bool dryRun)
319{
320 using copy_opts = fs::copy_options;
321 m_copied = 0; // reset counter
322 m_failedPaths.clear();
323
324// NOTE always deep copy on windows. the alternatives are too messy.
325#if defined Q_OS_WIN32
326 m_followSymlinks = true;
327#endif
328
329 auto src = PathCombine(m_src.absolutePath(), offset);
330 auto dst = PathCombine(m_dst.absolutePath(), offset);
331
332 std::error_code err;
333
334 fs::copy_options opt = copy_opts::none;
335
336 // The default behavior is to follow symlinks
337 if (!m_followSymlinks)
338 opt |= copy_opts::copy_symlinks;
339
340 if (m_overwrite)
341 opt |= copy_opts::overwrite_existing;
342
343 // Function that'll do the actual copying
344 auto copy_file = [&](QString src_path, QString relative_dst_path) {
345 if (m_matcher && (m_matcher->matches(relative_dst_path) != m_whitelist))
346 return;
347
348 auto dst_path = PathCombine(dst, relative_dst_path);
349 if (!dryRun) {
350 ensureFilePathExists(dst_path);
351#ifdef Q_OS_WIN32
352 copyFolderAttributes(src, dst, relative_dst_path);
353#endif
354 fs::copy(StringUtils::toStdString(src_path), StringUtils::toStdString(dst_path), opt, err);
355 }
356 if (err) {
357 qWarning() << "Failed to copy files:" << QString::fromStdString(err.message());
358 qDebug() << "Source file:" << src_path;
359 qDebug() << "Destination file:" << dst_path;
360 m_failedPaths.append(dst_path);
361 emit copyFailed(relative_dst_path);
362 return;
363 }
364 m_copied++;
365 emit fileCopied(relative_dst_path);
366 };
367
368 // We can't use copy_opts::recursive because we need to take into account the
369 // blacklisted paths, so we iterate over the source directory, and if there's no blacklist
370 // match, we copy the file.
371 QDir src_dir(src);
372 QDirIterator source_it(src, QDir::Filter::Files | QDir::Filter::Hidden, QDirIterator::Subdirectories);
373
374 while (source_it.hasNext()) {
375 auto src_path = source_it.next();

Callers

nothing calls this directly

Calls 12

PathCombineFunction · 0.85
ensureFilePathExistsFunction · 0.85
copyFolderAttributesFunction · 0.85
copyClass · 0.85
toStdStringFunction · 0.85
fromStdStringFunction · 0.85
canCloneFunction · 0.85
clone_fileFunction · 0.85
appendMethod · 0.80
valueMethod · 0.80
clearMethod · 0.45
matchesMethod · 0.45

Tested by

no test coverage detected