From 40213dd64c3307836e3c78a23dafa1f9211f771c Mon Sep 17 00:00:00 2001 From: t0b10 Date: Wed, 11 Dec 2024 21:55:19 -0700 Subject: [PATCH] Implement bind_files function and add some handling to bind_directories to prevent errors in unpatched ports. --- PortMaster/funcs.txt | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/PortMaster/funcs.txt b/PortMaster/funcs.txt index 9bdccb2..8b8df1e 100644 --- a/PortMaster/funcs.txt +++ b/PortMaster/funcs.txt @@ -41,15 +41,20 @@ fi bind_directories() { # Usage: bind_directories ~/.config/StardewValley $GAMEDIR/savedata - # + # # Reason: some platforms (batocera) use exfat for the home directory, so we can't use symbolic links # We then instead use bind mount, however retrodeck cannot bind mount because it does not run in root. # if [ "$PM_CAN_MOUNT" = "Y" ]; then - [[ -L "$1" ]] && rm -f "$1" - mkdir -p "$1" - $ESUDO umount "$1" - $ESUDO mount --bind "$2" "$1" + [[ -L "$1" ]] && rm -f "$1" && echo "removed previous symlink $1" + # Ensure the directory exists before attempting the bind mount + if [ -d "$2" ]; then + mkdir -p "$1" + $ESUDO umount "$1" + $ESUDO mount --bind "$2" "$1" && echo "successful bind mount from $2 to $1" + else + echo "no directory found at $2" + fi else # RetroDECK cant use bind mount without root. rm -f "$1" @@ -57,6 +62,28 @@ bind_directories() { fi } +bind_files() { + # Usage: bind_files ~/.config_file $GAMEDIR/conf/.config_file + # + # Reason: some platforms (batocera) use exfat for the home directory, so we can't use symbolic links + # We then instead use bind mount, however retrodeck cannot bind mount because it does not run in root. + # + if [ "$PM_CAN_MOUNT" = "Y" ]; then + [[ -L "$1" ]] && rm -f "$1" && echo "removed previous symlink $1" + # Ensure the file exists before attempting the bind mount + if [ -f "$2" ]; then + touch "$1" + $ESUDO umount "$1" + $ESUDO mount --bind "$2" "$1" && echo "successful bind mount from $2 to $1" + else + echo "no file found at $2" + fi + else + # RetroDECK cant use bind mount without root. + rm -f "$1" + ln -sfv "$2" "$1" + fi +} pm_begin_splash() { # Usage: pm_begin_splash