From de634f3749c834b16ede0478eaa98af3dc0fdc5f Mon Sep 17 00:00:00 2001 From: jutty Date: Tue, 3 Sep 2024 09:23:37 -0300 Subject: [PATCH] Handle permissions when reading and writing files --- src/file/file_merge.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/file/file_merge.sh b/src/file/file_merge.sh index 46e75be..c938431 100644 --- a/src/file/file_merge.sh +++ b/src/file/file_merge.sh @@ -54,15 +54,27 @@ file_merge_tree() { return 0 elif [ "$strategy" -eq 1 ]; then backup_paths "$absolute_path" - cp -vi "$config_path" "$absolute_path" + if [ -r "$config_path" ] && [ -w "$absolute_path" ]; then + cp -vi "$config_path" "$absolute_path" + else + $AUTHORIZE_COMMAND cp -vi "$config_path" "$absolute_path" + fi return 1 elif [ "$strategy" -eq 2 ]; then backup_paths "$config_path" - cp -vi "$absolute_path" "$config_path" + if [ -r "$absolute_path" ] && [ -w "$config_path" ]; then + cp -vi "$absolute_path" "$config_path" + else + $AUTHORIZE_COMMAND cp -vi "$absolute_path" "$config_path" + fi return 1 elif [ "$strategy" -eq 3 ]; then echo "< $(tildify "$absolute_path") | $(echo "$config_path" | sed "s*$CONFIG_ROOT/**") >" - diff "$absolute_path" "$config_path" + if [ -r "$absolute_path" ] && [ -r "$config_path" ]; then + diff "$absolute_path" "$config_path" + else + $AUTHORIZE_COMMAND diff "$absolute_path" "$config_path" + fi return 1 else log user 'Invalid choice'