Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
dde-application-manager (1.2.28) unstable; urgency=medium

* revert the change that validate and remove broken desktop file symlinks

-- Wang Zichong <wangzichong@deepin.org> Thu, 17 Apr 2025 17:27:00 +0800

dde-application-manager (1.2.27) unstable; urgency=medium

* fix: convert file:// to local path
Expand Down
87 changes: 0 additions & 87 deletions src/dbus/applicationmanager1service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
#include <QStringBuilder>
#include <chrono>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <string.h>

ApplicationManager1Service::~ApplicationManager1Service() = default;

Expand Down Expand Up @@ -142,8 +138,6 @@ void ApplicationManager1Service::initService(QDBusConnection &connection) noexce

auto needLaunch = scanAutoStart();

autoRemoveFromDesktop();

scanInstances();

auto storagePtr = m_storage.lock();
Expand Down Expand Up @@ -652,87 +646,6 @@ void ApplicationManager1Service::updateApplication(const QSharedPointer<Applicat
}
}

// 删除桌面无效的快捷方式
void ApplicationManager1Service::autoRemoveFromDesktop() noexcept
{
auto dirPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
if (dirPath.isEmpty()) {
return;
}

DIR *dir = opendir(dirPath.toLocal8Bit().constData());
if (dir == nullptr) {
qWarning() << "open dir :" << dirPath << "failed";
return;
}

struct dirent *entry;
while ((entry = readdir(dir)) != nullptr) {
// 跳过 . 和 .. 目录
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
continue;
}

const char *suffix = ".desktop";
const char *entryName = entry->d_name;
int indexSuffix = strlen(suffix)-1;
int index = strlen(entryName)-1;
bool isDesktopFile = true;

if (index < indexSuffix) {
continue;
}

while (indexSuffix >= 0) {
if(suffix[indexSuffix--] != entryName[index--]){
isDesktopFile = false;
break;
}
}

if (!isDesktopFile) {
qWarning() << "entry->d_name not DesktopFile:" << entry->d_name;
continue;
}

qWarning() << "entry->d_name DesktopFile:" << entry->d_name;

std::string entryPath = dirPath.toStdString() + "/" + entry->d_name;

struct stat statbuf;
if (lstat(entryPath.c_str(), &statbuf) == -1) {
qWarning() << "lstat failed:" << entryPath.c_str();
continue;
}

// 检查是否是符号链接
if (S_ISLNK(statbuf.st_mode)) {
char target[4096];
ssize_t len = readlink(entryPath.c_str(), target, sizeof(target) - 1);
if (len == -1) {
qWarning() << "readlink failed:" << entryPath.c_str();
continue;
}
target[len] = '\0';

QFileInfo fileInfo{entryPath.c_str()};
// 检查符号链接的目标是否存在
struct stat targetStat;
if (lstat(target, &targetStat) == -1) {
QFile file{fileInfo.filePath()};
auto success = file.remove();
if (!success) {
qWarning() << "remove desktop file failed:" << file.errorString();
}else {
qWarning() << "remove desktop file success:" << fileInfo.filePath();
}
}
}
}

closedir(dir);
}

void ApplicationManager1Service::ReloadApplications()
{
if (calledFromDBus() && !m_reloadTimer.isActive()) {
Expand Down
1 change: 0 additions & 1 deletion src/dbus/applicationmanager1service.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class ApplicationManager1Service final : public QObject, protected QDBusContext
[[nodiscard]] QHash<QDBusObjectPath, QSharedPointer<ApplicationService>>
findApplicationsByIds(const QStringList &appIds) const noexcept;
void updateApplication(const QSharedPointer<ApplicationService> &destApp, DesktopFile desktopFile) noexcept;
void autoRemoveFromDesktop() noexcept;

[[nodiscard]] const auto &Applications() const noexcept { return m_applicationList; }
[[nodiscard]] JobManager1Service &jobManager() noexcept { return *m_jobManager; }
Expand Down
Loading