MCPcopy Create free account
hub / github.com/ElyPrismLauncher/Launcher / operator()

Method operator()

launcher/FileSystem.cpp:308–376  ·  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

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

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected