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

Function clone_file

launcher/FileSystem.cpp:1334–1380  ·  view source on GitHub ↗

* @brief clone/reflink file from src to dst * */

Source from the content-addressed store, hash-verified

1332 *
1333 */
1334bool clone_file(const QString& src, const QString& dst, std::error_code& ec)
1335{
1336 auto src_path = StringUtils::toStdString(QDir::toNativeSeparators(QFileInfo(src).absoluteFilePath()));
1337 auto dst_path = StringUtils::toStdString(QDir::toNativeSeparators(QFileInfo(dst).absoluteFilePath()));
1338
1339 FilesystemInfo srcinfo = statFS(src);
1340 FilesystemInfo dstinfo = statFS(dst);
1341
1342 if ((srcinfo.rootPath != dstinfo.rootPath) || (srcinfo.fsType != dstinfo.fsType)) {
1343 ec = std::make_error_code(std::errc::not_supported);
1344 qWarning() << "reflink/clone must be to the same device and filesystem! src and dst root filesystems do not match.";
1345 return false;
1346 }
1347
1348#if defined(Q_OS_WIN)
1349
1350 if (!win_ioctl_clone(src_path, dst_path, ec)) {
1351 qDebug() << "failed win_ioctl_clone";
1352 qWarning() << "clone/reflink not supported on windows outside of btrfs or ReFS!";
1353 qWarning() << "check out https://github.com/maharmstone/btrfs for btrfs support!";
1354 return false;
1355 }
1356
1357#elif defined(Q_OS_LINUX)
1358
1359 if (!linux_ficlone(src_path, dst_path, ec)) {
1360 qDebug() << "failed linux_ficlone:";
1361 return false;
1362 }
1363
1364#elif defined(Q_OS_MACOS)
1365
1366 if (!macos_bsd_clonefile(src_path, dst_path, ec)) {
1367 qDebug() << "failed macos_bsd_clonefile:";
1368 return false;
1369 }
1370
1371#else
1372
1373 qWarning() << "clone/reflink not supported! unknown OS";
1374 ec = std::make_error_code(std::errc::not_supported);
1375 return false;
1376
1377#endif
1378
1379 return true;
1380}
1381
1382#if defined(Q_OS_WIN)
1383

Callers 1

operator()Method · 0.85

Calls 6

toStdStringFunction · 0.85
QFileInfoClass · 0.85
statFSFunction · 0.85
win_ioctl_cloneFunction · 0.85
linux_ficloneFunction · 0.85
macos_bsd_clonefileFunction · 0.85

Tested by

no test coverage detected