Skip to content

Commit c4038b6

Browse files
mymldengbo11
authored andcommitted
fix: handle renaming and copying of non-original linyaps files in exportDir
Updated the exportDir function to rename source files to include a ".linyaps.original" suffix if they are not already named as such, ensuring proper handling during the export process. This change prevents overwriting original files and maintains compatibility with existing export logic.
1 parent 98165a3 commit c4038b6

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

libs/linglong/src/linglong/repo/ostree_repo.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,7 +1972,8 @@ utils::error::Result<void> OSTreeRepo::exportDir(const std::string &appID,
19721972
}
19731973
}
19741974

1975-
{
1975+
// 如果source_path不是linyaps.original文件,则进行重写
1976+
if (source_path.string().rfind(".linyaps.original") == std::string::npos) {
19761977
auto info = QFileInfo(target_path.c_str());
19771978
if ((info.path().contains("share/applications") && info.suffix() == "desktop")
19781979
|| (info.path().contains("share/dbus-1") && info.suffix() == "service")
@@ -1987,7 +1988,16 @@ utils::error::Result<void> OSTreeRepo::exportDir(const std::string &appID,
19871988
QString::number(timestamp),
19881989
info.suffix())
19891990
.toStdString();
1990-
std::filesystem::copy(source_path, sourceNewPath, ec);
1991+
1992+
auto originPath = source_path.string() + ".linyaps.original";
1993+
if (!std::filesystem::exists(originPath, ec)) {
1994+
std::filesystem::rename(source_path, originPath, ec);
1995+
if (ec) {
1996+
return LINGLONG_ERR("rename orig path", ec);
1997+
}
1998+
}
1999+
2000+
std::filesystem::copy(originPath, sourceNewPath, ec);
19912001
if (ec) {
19922002
return LINGLONG_ERR("copy file failed: " + sourceNewPath, ec);
19932003
}

0 commit comments

Comments
 (0)