Skip to content

Commit

Permalink
Merge branch 'release/eagle' into fix-3
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnson-zs authored Sep 26, 2024
2 parents eb85a73 + ac93023 commit d50fbd5
Show file tree
Hide file tree
Showing 12 changed files with 284 additions and 6 deletions.
22 changes: 22 additions & 0 deletions assets/configs/org.deepin.dde.file-manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,28 @@
"permissions":"readwrite",
"visibility":"private"
},
"dfm.mount.ulnfs": {
"value":false,
"serial":0,
"flags":[],
"name":"Extend characters of file names by ulnfs",
"name[zh_CN]":"扩展文件名字符数",
"description[zh_CN]":"扩展文件名字符数需重启后才能生效",
"description":"To extend characters of file names, you should restart to make the configuration effective.",
"permissions":"readwrite",
"visibility":"private"
},
"dfm.mount.ulnfs.defaults": {
"value":["$HOME"],
"serial":0,
"flags":[],
"name":"Dirs that support long file names by ulnfs",
"name[zh_CN]":"启用长文件名扩展的目录",
"description[zh_CN]":"默认启用长文件名扩展的目录",
"description":"Dirs that support long file names by default.",
"permissions":"readwrite",
"visibility":"private"
},
"dfm.mount.dlnfs": {
"value":false,
"serial":0,
Expand Down
7 changes: 7 additions & 0 deletions assets/scripts/99dfm-ulnfs-automount
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

echo "\ndfm_INFO: start main script to mount ulnfs at" $(date "+%Y-%m-%d %H:%M:%S.%3N")
[ -f /etc/deepin/dde-file-manager/dfm-ulnfs-automount ] && bash /etc/deepin/dde-file-manager/dfm-ulnfs-automount &
echo "dfm_INFO: end main script at" $(date "+%Y-%m-%d %H:%M:%S.%3N")
5 changes: 4 additions & 1 deletion assets/scripts/dfm-dlnfs-automount
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ query_dconfig="dde-dconfig --get -a org.deepin.dde.file-manager -r org.deepin.dd
dlnfs_enable=`$query_dconfig dfm.mount.dlnfs`
echo "dfm_INFO: dlnfs mount status: $dlnfs_enable"

if [ "$dlnfs_enable" == "true" ]; then
ulnfs_enable=`$query_dconfig dfm.mount.ulnfs`
echo "dfm_INFO: ulnfs mount status: $ulnfs_enable"

if [ "$dlnfs_enable" == "true" ] && [ "$ulnfs_enable" != "true" ]; then
default_paths=`$query_dconfig dfm.mount.dlnfs.defaults`
echo "dfm_INFO: default mount paths: $default_paths"

Expand Down
63 changes: 63 additions & 0 deletions assets/scripts/dfm-ulnfs-automount
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

start_time=$(date "+%Y-%m-%d %H:%M:%S.%3N")
echo -e "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> started mounting ulnfs at [${start_time}]"
echo "dfm_INFO: user: $USER, uid: `id -u`, home: $HOME"

query_dconfig="dde-dconfig --get -a org.deepin.dde.file-manager -r org.deepin.dde.file-manager -k "
# obtain the config of ulnfs mount enable
ulnfs_enable=`$query_dconfig dfm.mount.ulnfs`
echo "dfm_INFO: ulnfs mount status: $ulnfs_enable"

if [ "$ulnfs_enable" == "true" ]; then

default_paths=`$query_dconfig dfm.mount.ulnfs.defaults`
echo "dfm_INFO: default mount paths: $default_paths"

formats='"[ " ]'
for path in $default_paths
do
contains=$(echo $formats | grep -F "${path}")
if [ "$contains" != "" ]; then
continue
fi

# remove quotes and commas
path=${path//'"'/}
path=${path//','/}
abs_path=$path

env_path=`echo $path | grep -o '\$[^/]*'` # env_path = $HOME

if [ "$env_path" != "" ]; then
env_var=${env_path//'$'/} # env_var = HOME
abs_env_path=`echo ${!env_var}` # abs_env_path = /home/$USER
abs_path=${path/$env_path/$abs_env_path} #path = /home/xxxx/xxxx
fi

echo "dfm_INFO: ========================= $path [$abs_path]"
if [ ! -d $abs_path ]; then
echo "dfm_WARNING: $abs_path do not exist"
continue
fi

gdbus call -y \
-d com.deepin.filemanager.daemon \
-o /com/deepin/filemanager/daemon/MountControl \
-m com.deepin.filemanager.daemon.MountControl.Mount \
"${abs_path}" \
"{'fsType': <'ulnfs'>}" \
-t 1

step_time=$(date "+%Y-%m-%d %H:%M:%S.%3N")
echo -e "dfm_INFO: finished mount ${abs_path} at [${step_time}]\n"
done

fi

end_time=$(date "+%Y-%m-%d %H:%M:%S.%3N")
echo -e "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< finished mounting ulnfs at [${end_time}]\n"
2 changes: 2 additions & 0 deletions debian/dde-file-manager.install
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ usr/lib/systemd/user/
etc/dbus-1/system.d/com.deepin.filemanager.daemon.conf
etc/X11/Xsession.d/99dfm-dlnfs-automount
etc/deepin/dde-file-manager/dfm-dlnfs-automount
etc/X11/Xsession.d/99dfm-ulnfs-automount
etc/deepin/dde-file-manager/dfm-ulnfs-automount
6 changes: 6 additions & 0 deletions src/dfm-base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ install(FILES ${DLNFS_SCRIPT} DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/deepin/dde
set(DLNFS_SCRIPT_LAUNCHER ${AssetsPath}/scripts/99dfm-dlnfs-automount)
install(FILES ${DLNFS_SCRIPT_LAUNCHER} DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/X11/Xsession.d)

set(ULNFS_SCRIPT ${AssetsPath}/scripts/dfm-ulnfs-automount)
install(FILES ${ULNFS_SCRIPT} DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/deepin/dde-file-manager)

set(ULNFS_SCRIPT_LAUNCHER ${AssetsPath}/scripts/99dfm-ulnfs-automount)
install(FILES ${ULNFS_SCRIPT_LAUNCHER} DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/X11/Xsession.d)

set(Mimetypes "${ShareDir}/mimetypes")
FILE(GLOB MIMETYPE_FILES ${AssetsPath}/mimetypes/*)
install(FILES ${MIMETYPE_FILES} DESTINATION ${Mimetypes})
Expand Down
2 changes: 1 addition & 1 deletion src/dfm-base/utils/fileutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ QString FileUtils::normalPathToTrash(const QString &normal)
bool FileUtils::supportLongName(const QUrl &url)
{
const static QList<QString> datas {
"vfat", "exfat", "ntfs", "fuseblk", "fuse.dlnfs"
"vfat", "exfat", "ntfs", "fuseblk", "fuse.dlnfs", "ulnfs"
};

const QString &fileSystem = dfmio::DFMUtils::fsTypeFromUrl(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ inline constexpr char kErrorMessage[] { "errMsg" };

namespace MountFstypeSupportedField {
inline constexpr char kDlnFs[] { "dlnfs" };
inline constexpr char kUlnFs[] { "ulnfs" };
inline constexpr char kCifs[] { "cifs" };
inline constexpr char kCommon[] { "common" };
}
Expand All @@ -51,8 +52,8 @@ enum MountErrorCode { // NOTE(xust): use NAGATIVE value when return, avoid con
kMountNotExist,
kNotOwnerOfMount,

kDlnFsProcessNotExists,
kDlnMountMounted,
kLnFsProcessNotExists,
kLnMountMounted,
kFusermountProcessNotExists,

kUnhandledError = 1000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "mounthelpers/cifsmounthelper.h"
#include "mounthelpers/dlnfsmounthelper.h"
#include "mounthelpers/commonmounthelper.h"
#include "mounthelpers/ulnfsmounthelper.h"

#include <QFile>
#include <DConfig>
Expand Down Expand Up @@ -79,9 +80,12 @@ MountControlDBusPrivate::MountControlDBusPrivate(MountControlDBus *qq)
{
CifsMountHelper *cifsHelper = new CifsMountHelper(qq);
DlnfsMountHelper *dlnfsHelper = new DlnfsMountHelper(qq);
UlnfsMountHelper *ulnfsHelper = new UlnfsMountHelper(qq);
CommonMountHelper *commonHelper = new CommonMountHelper(qq);

cifsHelper->cleanMountPoint();
mountHelpers.insert(MountFstypeSupportedField::kCifs, cifsHelper);
mountHelpers.insert(MountFstypeSupportedField::kUlnFs, ulnfsHelper);
mountHelpers.insert(MountFstypeSupportedField::kDlnFs, dlnfsHelper);
supportedFS.append(MountFstypeSupportedField::kDlnFs);
mountHelpers.insert(MountFstypeSupportedField::kCommon, commonHelper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ QVariantMap DlnfsMountHelper::mount(const QString &path, const QVariantMap &opts
// 1. check if dlnfs at `path` is already exist.
if (checkDlnfsExist(path))
return { { kResult, true },
{ kErrorCode, -kDlnMountMounted },
{ kErrorCode, -kLnMountMounted },
{ kErrorMessage, QString("dlnfs is already mounted at %1").arg(path) } };

// 2. check `dlnfs` process exist.
if (QStandardPaths::findExecutable(kDlnfs).isEmpty())
return { { kResult, false },
{ kErrorCode, -kDlnFsProcessNotExists },
{ kErrorCode, -kLnFsProcessNotExists },
{ kErrorMessage, "dlnfs do not exist" } };

// 3. mount dlnfs on `path`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "ulnfsmounthelper.h"

#include <QDataStream>
#include <QDebug>
#include <QFile>
#include <QProcess>
#include <QStandardPaths>

#include <libmount/libmount.h>

DAEMONPMOUNTCONTROL_USE_NAMESPACE

QVariantMap UlnfsMountHelper::mount(const QString &path, const QVariantMap &opts)
{
Q_UNUSED(opts) // not used yet and might be used in the future.
using namespace MountReturnField;

static constexpr char kUlnfs[] { "ulnfs" };

// 1. check if ulnfs/dlnfs at `path` is already exist.
if (checkLnfsExist(path))
return { { kResult, true },
{ kErrorCode, -kLnMountMounted },
{ kErrorMessage, QString("lnfs is already mounted at %1").arg(path) } };

// 2. check `ulnfs` is loaded.
if (!isModuleLoaded(kUlnfs) && !loadKernelModule(kUlnfs))
return { { kResult, false },
{ kErrorCode, -kLnFsProcessNotExists },
{ kErrorMessage, QString("ulnfs is not loaded.") } };

// 3. mount ulnfs on `path`
auto aPath = path.toLocal8Bit().constData();
int ret = ::mount(aPath, aPath, kUlnfs, 0, "");

fmInfo() << "ulnfs: mount result: " << ret << aPath;
if (ret == 0) {
return { { kMountPoint, aPath }, { kResult, true }, { kErrorCode, 0 } };
} else {
int errNum = errno;
QString errMsg = strerror(errNum);
return { { kResult, false },
{ kErrorMessage, errMsg },
{ kErrorCode, parseErrorCodeByMsg(ret) } };
}
}

QVariantMap UlnfsMountHelper::unmount(const QString &path, const QVariantMap &opts)
{
Q_UNUSED(opts)
using namespace MountReturnField;

// 1. check if ulnfs is already mounted at `path`
if (!checkLnfsExist(path)) {
fmDebug() << "dlnfs: is not mounted at" << path;
return { { kResult, true },
{ kErrorCode, -kMountNotExist },
{ kErrorMessage, QString("dlnfs is not mounted at %1").arg(path) } };
}

// 2. do unmount ulnfs

int ret = ::umount(path.toStdString().c_str());
int err = errno;
QString errMsg = strerror(errno);
if (ret != 0)
fmWarning() << "unmount failed: " << path << err << errMsg;

return { { kResult, ret == 0 }, { kErrorCode, err }, { kErrorMessage, errMsg } };
}

bool UlnfsMountHelper::isModuleLoaded(const QString &moduleName)
{
QProcess process;
process.start("lsmod");
process.waitForFinished();

QString output = process.readAllStandardOutput();
QStringList lines = output.split('\n');

foreach (const QString &line, lines) {
if (line.startsWith(moduleName)) {
return true;
}
}
return false;
}

bool UlnfsMountHelper::loadKernelModule(const QString &moduleName)
{
QProcess modprobeProcess;

modprobeProcess.start("modprobe", QStringList() << moduleName);

if (!modprobeProcess.waitForFinished()) {
qCritical("Failed to load module: %s", qPrintable(modprobeProcess.errorString()));
return false;
}

QByteArray output = modprobeProcess.readAllStandardOutput();
qDebug() << moduleName << "Module loaded successfully.";
return true;
}

bool UlnfsMountHelper::checkLnfsExist(const QString &path)
{
QFile mountsFile("/proc/mounts");
if (!mountsFile.open(QIODevice::ReadOnly)) {
qWarning() << "Failed to open /proc/mounts.";
return false;
}

QByteArray content = mountsFile.readAll();
QString fileContent(content);

QStringList lines = fileContent.split('\n');
for (const QString &line : lines) {
QStringList parts = line.split(' ');

if (parts.size() >= 3) {
QString mountPoint = parts[1];
QString fsType = parts[2];

if (mountPoint == path && fsType == "ulnfs") {
return true;
}
}
}

return false;
}

int UlnfsMountHelper::parseErrorCodeByMsg(int res)
{
if (res == 0)
return 0;
return -kUnhandledError;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef UlnfsMountHelper_H
#define UlnfsMountHelper_H

#include "abstractmounthelper.h"

DAEMONPMOUNTCONTROL_BEGIN_NAMESPACE
class UlnfsMountHelper : public AbstractMountHelper
{
public:
explicit UlnfsMountHelper(QDBusContext *context)
: AbstractMountHelper(context) {}

virtual QVariantMap mount(const QString &path, const QVariantMap &opts) override;
virtual QVariantMap unmount(const QString &path, const QVariantMap &opts) override;

private:
bool loadKernelModule(const QString &moduleName);
bool checkLnfsExist(const QString &path);
bool isModuleLoaded(const QString &path);
int parseErrorCodeByMsg(int res);
};
DAEMONPMOUNTCONTROL_END_NAMESPACE

#endif // UlnfsMountHelper_H

0 comments on commit d50fbd5

Please sign in to comment.