| 1561 | #elif defined(Q_OS_LINUX) |
| 1562 | |
| 1563 | bool linux_ficlone(const std::string& src_path, const std::string& dst_path, std::error_code& ec) |
| 1564 | { |
| 1565 | // https://man7.org/linux/man-pages/man2/ioctl_ficlone.2.html |
| 1566 | |
| 1567 | int src_fd = open(src_path.c_str(), O_RDONLY); |
| 1568 | if (src_fd == -1) { |
| 1569 | qDebug() << "Failed to open file:" << src_path.c_str(); |
| 1570 | qDebug() << "Error:" << strerror(errno); |
| 1571 | ec = std::make_error_code(static_cast<std::errc>(errno)); |
| 1572 | return false; |
| 1573 | } |
| 1574 | int dst_fd = open(dst_path.c_str(), O_CREAT | O_WRONLY | O_TRUNC, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); |
| 1575 | if (dst_fd == -1) { |
| 1576 | qDebug() << "Failed to open file:" << dst_path.c_str(); |
| 1577 | qDebug() << "Error:" << strerror(errno); |
| 1578 | ec = std::make_error_code(static_cast<std::errc>(errno)); |
| 1579 | close(src_fd); |
| 1580 | return false; |
| 1581 | } |
| 1582 | // attempt to clone |
| 1583 | if (ioctl(dst_fd, FICLONE, src_fd) == -1) { |
| 1584 | qDebug() << "Failed to clone file:" << src_path.c_str() << "to" << dst_path.c_str(); |
| 1585 | qDebug() << "Error:" << strerror(errno); |
| 1586 | ec = std::make_error_code(static_cast<std::errc>(errno)); |
| 1587 | close(src_fd); |
| 1588 | close(dst_fd); |
| 1589 | return false; |
| 1590 | } |
| 1591 | if (close(src_fd)) { |
| 1592 | qDebug() << "Failed to close file:" << src_path.c_str(); |
| 1593 | qDebug() << "Error:" << strerror(errno); |
| 1594 | } |
| 1595 | if (close(dst_fd)) { |
| 1596 | qDebug() << "Failed to close file:" << dst_path.c_str(); |
| 1597 | qDebug() << "Error:" << strerror(errno); |
| 1598 | } |
| 1599 | return true; |
| 1600 | } |
| 1601 | |
| 1602 | #elif defined(Q_OS_MACOS) |
| 1603 | |