Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [ulnfs] migrate filename from dlnfs to ulnfs #2317

Merged
merged 1 commit into from
Sep 26, 2024
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
5 changes: 5 additions & 0 deletions assets/scripts/99dfm-ulnfs-automount
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
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")

echo "\ndfm_INFO: start migrate filename from dlnfs to ulnfs at" $(date "+%Y-%m-%d %H:%M:%S.%3N")
[ -f /etc/deepin/dde-file-manager/dfm_migrate_filename_from_dlnfs_to_ulnfs ] && \
bash /etc/deepin/dde-file-manager/dfm_migrate_filename_from_dlnfs_to_ulnfs &
echo "dfm_INFO: end migrate at" $(date "+%Y-%m-%d %H:%M:%S.%3N")
159 changes: 159 additions & 0 deletions assets/scripts/dfm_migrate_filename_from_dlnfs_to_ulnfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#!/bin/bash

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


if [ -z $dry_run ]; then dry_run=0; fi

# migrate for a dir entry
migrate_for_dentry()
{
dir_path="$1"
short_name="$2"
long_name="$3"

if [ "$short_name" == "$long_name" ]; then return 0; fi

short_path="$dir_path/$short_name"
long_path="$dir_path/$long_name"

if [ -L "$short_path" ]
then
target=`readlink "$short_path"`
if [ $dry_run -eq 0 ]
then
ln -s "$target" "$long_path" >/dev/null 2>&1
else
echo symlink "$long_path" to "$target"
fi
# no rm $short_path
else
if [ $dry_run -eq 0 ]
then
mv -n "$short_path" "$long_path" >/dev/null 2>&1
else
echo move "$short_path" to "$long_path"
fi
fi
}

# migrate for a dir
migrate_for_dir()
{
dir_path="$1"
data_file_path="$dir_path/.longname"

first_line=1
short_name=""
while IFS= read -r line; do
# check data file version
if [ $first_line -eq 1 ]
then
if [ "$line" != "version=1.0" ]
then
echo "dfm_WARNING: .longname version not support, $data_file_path"
break
fi
first_line=0
continue
fi

# rename short name to long name
if [ -z "$short_name" ]
then
short_name="$line"
else
long_name="$line"
migrate_for_dentry "$dir_path" "$short_name" "$long_name"
short_name=""
fi
done < "$data_file_path"

if [ $dry_run -eq 0 ]
then
mv "$data_file_path" "${data_file_path}~" >/dev/null 2>&1
fi
}

# migrate for a mount point
migrate_for_mount_point()
{
mount_point="$1"

if [ $dry_run -eq 1 ]
then
echo "================ $mount_point ================"
fi

# process the directories under the mount point in a bottom-up order
# the fs type where the directory is located is ulnfs, and there is a .longname file in the dir
find "$mount_point" -depth -type d -fstype ulnfs -exec test -f '{}'/.longname \; -print0 |
while IFS= read -r -d '' data_file_dir; do
migrate_for_dir "$data_file_dir"
done
}

# migrate for all mount point
migrate_for_mount_points()
{
default_paths=`dde-dconfig --get -a org.deepin.dde.file-manager -r org.deepin.dde.file-manager -k dfm.mount.dlnfs.defaults`

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

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

migrate_for_mount_point $abs_path
done
}

migrate_filename()
{
# check if we finished the migrate
if [ -f $HOME/.config/deepin/migrate_filename_from_dlnfs_to_ulnfs_finished ]
then
echo "file name migration has been done"
return 0
fi

# check if we should do a migration
ulnfs_enable=`dde-dconfig --get -a org.deepin.dde.file-manager -r org.deepin.dde.file-manager -k dfm.mount.ulnfs`
if [[ "$ulnfs_enable" != "true" ]]; then return 0; fi

migrate_for_mount_points

touch $HOME/.config/deepin/migrate_filename_from_dlnfs_to_ulnfs_finished
echo "complete file name migration"
}

if [ "$test_dir" ]
then
migrate_for_mount_point "$test_dir"
else
migrate_filename
fi

exit 0
1 change: 1 addition & 0 deletions debian/dde-file-manager.install
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ 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
etc/deepin/dde-file-manager/dfm_migrate_filename_from_dlnfs_to_ulnfs
3 changes: 3 additions & 0 deletions src/dfm-base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ install(FILES ${ULNFS_SCRIPT} DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/deepin/dde
set(ULNFS_SCRIPT_LAUNCHER ${AssetsPath}/scripts/99dfm-ulnfs-automount)
install(FILES ${ULNFS_SCRIPT_LAUNCHER} DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/X11/Xsession.d)

set(MIGRATE_FILENAME_SCRIPT ${AssetsPath}/scripts/dfm_migrate_filename_from_dlnfs_to_ulnfs)
install(FILES ${MIGRATE_FILENAME_SCRIPT} DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/deepin/dde-file-manager)

set(Mimetypes "${ShareDir}/mimetypes")
FILE(GLOB MIMETYPE_FILES ${AssetsPath}/mimetypes/*)
install(FILES ${MIMETYPE_FILES} DESTINATION ${Mimetypes})
Expand Down
Loading