Handle permissions when reading and writing files

This commit is contained in:
Juno Takano 2024-09-03 09:23:37 -03:00
parent 59e040d597
commit de634f3749

View file

@ -54,15 +54,27 @@ file_merge_tree() {
return 0 return 0
elif [ "$strategy" -eq 1 ]; then elif [ "$strategy" -eq 1 ]; then
backup_paths "$absolute_path" backup_paths "$absolute_path"
if [ -r "$config_path" ] && [ -w "$absolute_path" ]; then
cp -vi "$config_path" "$absolute_path" cp -vi "$config_path" "$absolute_path"
else
$AUTHORIZE_COMMAND cp -vi "$config_path" "$absolute_path"
fi
return 1 return 1
elif [ "$strategy" -eq 2 ]; then elif [ "$strategy" -eq 2 ]; then
backup_paths "$config_path" backup_paths "$config_path"
if [ -r "$absolute_path" ] && [ -w "$config_path" ]; then
cp -vi "$absolute_path" "$config_path" cp -vi "$absolute_path" "$config_path"
else
$AUTHORIZE_COMMAND cp -vi "$absolute_path" "$config_path"
fi
return 1 return 1
elif [ "$strategy" -eq 3 ]; then elif [ "$strategy" -eq 3 ]; then
echo "< $(tildify "$absolute_path") | $(echo "$config_path" | sed "s*$CONFIG_ROOT/**") >" echo "< $(tildify "$absolute_path") | $(echo "$config_path" | sed "s*$CONFIG_ROOT/**") >"
if [ -r "$absolute_path" ] && [ -r "$config_path" ]; then
diff "$absolute_path" "$config_path" diff "$absolute_path" "$config_path"
else
$AUTHORIZE_COMMAND diff "$absolute_path" "$config_path"
fi
return 1 return 1
else else
log user 'Invalid choice' log user 'Invalid choice'