|
18 | 18 | #include "linglong/repo/config.h"
|
19 | 19 | #include "linglong/utils/command/env.h"
|
20 | 20 | #include "linglong/utils/error/error.h"
|
| 21 | +#include "linglong/utils/file.h" |
21 | 22 | #include "linglong/utils/finally/finally.h"
|
22 | 23 | #include "linglong/utils/gkeyfile_wrapper.h"
|
23 | 24 | #include "linglong/utils/packageinfo_handler.h"
|
@@ -1640,8 +1641,37 @@ utils::error::Result<void> OSTreeRepo::exportDir(const std::string &appID,
|
1640 | 1641 | return LINGLONG_ERR("remove file failed", ec);
|
1641 | 1642 | }
|
1642 | 1643 | }
|
1643 |
| - auto ret = IniLikeFileRewrite(QFileInfo(source_path.c_str()), appID.c_str()); |
1644 |
| - if (!ret) { } |
| 1644 | + |
| 1645 | + { |
| 1646 | + auto info = QFileInfo(target_path.c_str()); |
| 1647 | + if ((info.path().contains("share/applications") && info.suffix() == "desktop") |
| 1648 | + || (info.path().contains("share/dbus-1") && info.suffix() == "service") |
| 1649 | + || (info.path().contains("share/systemd/user") && info.suffix() == "service") |
| 1650 | + || (info.path().contains("share/applications/context-menus"))) { |
| 1651 | + // We should not modify the files of the checked application directly, but |
| 1652 | + // should copy them to root entries directory and then modify. |
| 1653 | + std::filesystem::copy(source_path, target_path, ec); |
| 1654 | + if (ec) { |
| 1655 | + return LINGLONG_ERR("copy file failed: " + target_path.string(), ec); |
| 1656 | + } |
| 1657 | + |
| 1658 | + exists = std::filesystem::exists(target_path, ec); |
| 1659 | + if (ec) { |
| 1660 | + return LINGLONG_ERR("check file exists", ec); |
| 1661 | + } |
| 1662 | + |
| 1663 | + if (!exists) { |
| 1664 | + qWarning() << "failed to copy file: " << source_path.c_str(); |
| 1665 | + continue; |
| 1666 | + } |
| 1667 | + |
| 1668 | + auto ret = IniLikeFileRewrite(QFileInfo(target_path.c_str()), appID.c_str()); |
| 1669 | + if (ret) { |
| 1670 | + continue; |
| 1671 | + } |
| 1672 | + } |
| 1673 | + } |
| 1674 | + |
1645 | 1675 | std::filesystem::create_symlink(source_path, target_path, ec);
|
1646 | 1676 | if (ec) {
|
1647 | 1677 | return LINGLONG_ERR("create symlink failed: " + target_path.string(), ec);
|
@@ -1735,6 +1765,30 @@ OSTreeRepo::exportEntries(const std::filesystem::path &rootEntriesDir,
|
1735 | 1765 | return LINGLONG_OK;
|
1736 | 1766 | }
|
1737 | 1767 |
|
| 1768 | +utils::error::Result<void> OSTreeRepo::fixExportAllEntries() noexcept |
| 1769 | +{ |
| 1770 | + auto exportVersion = repoDir.absoluteFilePath("entries/.version").toStdString(); |
| 1771 | + auto data = linglong::utils::readFile(exportVersion); |
| 1772 | + if (data && data == LINGLONG_EXPORT_VERSION) { |
| 1773 | + qDebug() << exportVersion.c_str() << data->c_str(); |
| 1774 | + qDebug() << "skip export entry, already exported"; |
| 1775 | + } else { |
| 1776 | + auto ret = exportAllEntries(); |
| 1777 | + if (!ret.has_value()) { |
| 1778 | + qCritical() << "failed to export entries:" << ret.error(); |
| 1779 | + return ret; |
| 1780 | + } else { |
| 1781 | + ret = linglong::utils::writeFile(exportVersion, LINGLONG_EXPORT_VERSION); |
| 1782 | + if (!ret.has_value()) { |
| 1783 | + qCritical() << "failed to write export version:" << ret.error(); |
| 1784 | + return ret; |
| 1785 | + } |
| 1786 | + } |
| 1787 | + } |
| 1788 | + |
| 1789 | + return LINGLONG_OK; |
| 1790 | +} |
| 1791 | + |
1738 | 1792 | utils::error::Result<void> OSTreeRepo::exportAllEntries() noexcept
|
1739 | 1793 | {
|
1740 | 1794 | LINGLONG_TRACE("export all entries");
|
|
0 commit comments