Fix handling of yaml files when deleting entries

master
Jonathan Hodgson 4 years ago
parent a3bbe9b4a2
commit 6206986546
  1. 3
      inc/file-management
  2. 6
      kb

@ -155,6 +155,7 @@ $filename title changed
Please resolve manually" Please resolve manually"
else else
mv "$filename" "$newFilename" mv "$filename" "$newFilename"
[ -e "$filename.yaml" ] && mv "$filename.yaml" "$newFilename.yaml"
if fileInDB "$filename"; then if fileInDB "$filename"; then
echo "UPDATE items echo "UPDATE items
SET (filename,title) = SET (filename,title) =
@ -169,6 +170,7 @@ Please resolve manually"
sqlite3 "${sqliteFile}" sqlite3 "${sqliteFile}"
fi fi
getYamlTags "$filename" | assignTags "$filename"
gitChange "$filename" "$newFilename" gitChange "$filename" "$newFilename"
fi fi
fi fi
@ -187,6 +189,7 @@ deleteFile(){
read -r rsp read -r rsp
if [[ "$(echo "$rsp" | tr '[:upper:]' '[:lower:]')" = "y"* ]]; then if [[ "$(echo "$rsp" | tr '[:upper:]' '[:lower:]')" = "y"* ]]; then
rm "$filename" rm "$filename"
[ -e "$filename.yaml" ] && rm "$filename.yaml"
# This deletes the file from the sql database and any tag links # This deletes the file from the sql database and any tag links
echo "DELETE FROM items echo "DELETE FROM items
WHERE id = '$(safeSQL "$fileID")'; WHERE id = '$(safeSQL "$fileID")';

6
kb

@ -221,10 +221,15 @@ gitChange(){
if ! git diff --exit-code "$filename" > /dev/null 2>&1; then if ! git diff --exit-code "$filename" > /dev/null 2>&1; then
# Changes # Changes
git add "$filename" git add "$filename"
[ -e "$filename.yaml" ] && git add "$filename.yaml"
git commit -m "KB auto-commit: Updated: $filename" git commit -m "KB auto-commit: Updated: $filename"
elif [ -e "$filename.yaml" ] && ! git diff --exit-code "$filename.yaml" > /dev/null 2>&1; then
git add "$filename.yaml"
git commit -m "KB auto-commit: Updated: $filename.yaml"
elif ! git ls-files --error-unmatch "$filename" > /dev/null 2>&1; then elif ! git ls-files --error-unmatch "$filename" > /dev/null 2>&1; then
# New file # New file
git add "$filename" git add "$filename"
[ -e "$filename.yaml" ] && git add "$filename.yaml"
git commit -m "KB auto-commit: New: $filename" git commit -m "KB auto-commit: New: $filename"
fi fi
else else
@ -235,6 +240,7 @@ gitChange(){
else else
# if we get here, the file has been deleted # if we get here, the file has been deleted
git add "$filename" git add "$filename"
git add "$filename.yaml"
git commit -m "KB auto-commit: delete: $filename" git commit -m "KB auto-commit: delete: $filename"
fi fi
fi fi

Loading…
Cancel
Save