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