refact: remove unnecessary open operation
fix AM can't access some dirs due to systemd 254's sandboxing option: PrivateUser is true by default. Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
parent
df9bb10cee
commit
4c9d4491df
@ -11,3 +11,5 @@ BusName=org.deepin.dde.ApplicationManager1
|
||||
ExecStart=@CMAKE_INSTALL_FULL_BINDIR@/dde-application-manager-reborn
|
||||
Restart=always
|
||||
Environment=QT_LOGGING_RULES="*.debug=false"
|
||||
PrivateUsers=false
|
||||
# turn off PrivateUser to prevent AM can't access some directory. eg. "/persistent/linglong"
|
||||
|
@ -270,7 +270,7 @@ void ApplicationManager1Service::updateApplication(const QSharedPointer<Applicat
|
||||
return;
|
||||
}
|
||||
|
||||
auto mtime = getFileTimeInfo(desktopFile.sourceFileRef());
|
||||
auto mtime = getFileTimeInfo(QFileInfo{desktopFile.sourceFileRef()});
|
||||
|
||||
if (destApp->desktopFileSource().modified(std::get<1>(mtime))) {
|
||||
auto *newEntry = new (std::nothrow) DesktopEntry{};
|
||||
|
@ -259,7 +259,7 @@ bool DesktopEntry::checkMainEntryValidation() const noexcept
|
||||
|
||||
std::optional<DesktopFile> DesktopFile::createTemporaryDesktopFile(std::unique_ptr<QFile> temporaryFile) noexcept
|
||||
{
|
||||
auto [ctime, mtime, _] = getFileTimeInfo(*temporaryFile);
|
||||
auto [ctime, mtime, _] = getFileTimeInfo(QFileInfo{*temporaryFile});
|
||||
if (mtime == 0) {
|
||||
qWarning() << "create temporary file failed.";
|
||||
return std::nullopt;
|
||||
@ -330,12 +330,7 @@ std::optional<DesktopFile> DesktopFile::searchDesktopFileByPath(const QString &d
|
||||
|
||||
auto filePtr = std::make_unique<QFile>(std::move(path));
|
||||
|
||||
auto [ctime, mtime, _] = getFileTimeInfo(*filePtr);
|
||||
|
||||
if (mtime == 0) {
|
||||
err = DesktopErrorCode::OpenFailed;
|
||||
return std::nullopt;
|
||||
}
|
||||
auto [ctime, mtime, _] = getFileTimeInfo(QFileInfo{*filePtr});
|
||||
|
||||
err = DesktopErrorCode::NoError;
|
||||
return DesktopFile{std::move(filePtr), std::move(id), mtime, ctime};
|
||||
|
16
src/global.h
16
src/global.h
@ -88,7 +88,7 @@ void applyIteratively(QList<QDir> dirs, T &&func)
|
||||
QList<QDir> dirList{std::move(dirs)};
|
||||
|
||||
while (!dirList.isEmpty()) {
|
||||
const auto dir = dirList.takeFirst();
|
||||
const auto &dir = dirList.takeFirst();
|
||||
|
||||
if (!dir.exists()) {
|
||||
qWarning() << "apply function to an non-existent directory:" << dir.absolutePath() << ", skip.";
|
||||
@ -467,20 +467,12 @@ ObjectMap dumpDBusObject(const QMap<QDBusObjectPath, QSharedPointer<T>> &map)
|
||||
return objs;
|
||||
}
|
||||
|
||||
inline std::tuple<std::size_t, std::size_t, std::size_t> getFileTimeInfo(QFile &file)
|
||||
inline std::tuple<std::size_t, std::size_t, std::size_t> getFileTimeInfo(const QFileInfo &file)
|
||||
{
|
||||
struct stat buf;
|
||||
QFileInfo info{file};
|
||||
|
||||
if (!file.isOpen()) {
|
||||
if (auto ret = file.open(QFile::ExistingOnly | QFile::ReadOnly | QFile::Text); !ret) {
|
||||
qWarning() << "open file" << info.absoluteFilePath() << "failed.";
|
||||
return std::make_tuple(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (auto ret = stat(info.absoluteFilePath().toLocal8Bit().data(), &buf); ret == -1) {
|
||||
qWarning() << "get file" << info.absoluteFilePath() << "state failed:" << std::strerror(errno);
|
||||
if (auto ret = stat(file.absoluteFilePath().toLocal8Bit().constData(), &buf); ret == -1) {
|
||||
qWarning() << "get file" << file.absoluteFilePath() << "state failed:" << std::strerror(errno);
|
||||
return std::make_tuple(0, 0, 0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user