Compare commits

..

No commits in common. "f43c1d433ad730d493076ea60f94a4e865cc2717" and "473d88b3c9fb30a140b9d41f85d37877e93e9812" have entirely different histories.

1 changed files with 6 additions and 33 deletions

39
tag.sh
View File

@ -13,6 +13,7 @@ set -ueo pipefail
# - tag $FILENAME $TAG - tag $FILENAME with $TAG, $TAG can be repeated
# - listtags $FILENAME - list all tags for $FILENAME
# TODO: when tagging, check if tags exist
# TODO: when tagging, allow more than one tag
# FIXME: adding tags doesn't work
@ -59,10 +60,8 @@ listtags() {
[ -z "$1" ] && fail "No filename supplied."
FILENAME="$1"
shift
! file_exists_in_db "$FILENAME" && fail "File '$FILENAME' does not exist in database."
LIMIT="${1:-0}"
ADDITIONAL_QUERY=""
[ $LIMIT -gt 0 ] && ADDITIONAL_QUERY="LIMIT $LIMIT"
@ -147,9 +146,6 @@ add_path() {
# $PATH1..$PATHN
TABLE="files"
COLUMN="filename"
for FILE in "$@"; do
file_exists_in_db "$FILE" && fail "File '$FILENAME' already exists in database."
done
sqlite_insert_single "$TABLE" "$COLUMN" "$@"
}
@ -159,7 +155,8 @@ add_hash() {
COLUMN="fid,md5"
local FILENAME="${1:-}"
[ -z "$FILENAME" ] && fail "No file specified."
! file_exists_in_db "$FILENAME" && fail "File \"$FILENAME\" does not exist in database."
RESULT=$(sqlite_query "SELECT id FROM files WHERE filename = '$FILENAME'")
[ -z "$RESULT" ] && fail "File \"$FILENAME\" does not exist in database."
sqlite_insert_multi "$TABLE" "$COLUMN" $RESULT "'$2'"
}
@ -168,28 +165,6 @@ add_path_auto() {
find "${2}" -type f -regextype posix-extended -iregex "$1" -exec "$0" import "{}" +
}
tag_exists_in_db() {
# $TAGLABEL
TAG=${1:-}
RESULT=$(sqlite_query "SELECT id FROM tags WHERE label = '$TAG'")
if [[ -z "$RESULT" ]]; then
return 1
else
return 0
fi
}
file_exists_in_db() {
# $FILENAME
FILENAME=${1:-}
RESULT=$(sqlite_query "SELECT id FROM files WHERE filename = '$FILENAME'")
if [[ -z "$RESULT" ]]; then
return 1
else
return 0
fi
}
main() {
[ -z "${1:-}" ] && fail "Usage: tag init/add/import/autoimport/list/listtags"
@ -234,15 +209,13 @@ main() {
if [[ "$1" = "tag" ]]; then
shift
[ -z "${1:-}" ] && fail "No filename supplied."
[ -z "$1" ] && fail "No filename supplied."
FILENAME="$1"
! file_exists_in_db "$FILENAME" && fail "File '$FILENAME' does not exist in database."
shift
[ -z "${1:-}" ] && fail "No tag supplied."
[ -z "$1" ] && fail "No tag supplied."
COUNTER=0
while true; do
LABEL="$1"
! tag_exists_in_db "$LABEL" && fail "Tag '$TAG' does not exist in database."
shift
sqlite3 -table "$DB_FILE" "INSERT INTO tags_ties (id, id) VALUES ((SELECT id FROM files WHERE filename = \"$FILENAME\"),(SELECT id FROM tags WHERE label = \"$LABEL\"))"
COUNTER=$((COUNTER++))