Fix adding hashes, add file_by_filename
This commit is contained in:
parent
1580865b56
commit
c3acf30c66
24
tag.sh
24
tag.sh
|
@ -161,12 +161,13 @@ add_path() {
|
||||||
|
|
||||||
add_hash() {
|
add_hash() {
|
||||||
# $FILE $HASH
|
# $FILE $HASH
|
||||||
TABLE="hashes"
|
local TABLE="hashes"
|
||||||
COLUMN="fid,md5"
|
local COLUMN="fid,md5"
|
||||||
local FILENAME="${1:-}"
|
local FILENAME="${1:-}"
|
||||||
[ -z "$FILENAME" ] && fail "No file specified."
|
[ -z "$FILENAME" ] && fail "No file specified."
|
||||||
! file_exists_in_db "$FILENAME" && fail "File \"$FILENAME\" does not exist in database."
|
local FID=$(file_by_filename "$FILENAME")
|
||||||
sqlite_insert_multi "$TABLE" "$COLUMN" $RESULT "'$2'"
|
[[ "$FID" -eq 0 ]] && fail "File \"$FILENAME\" does not exist in database."
|
||||||
|
sqlite_insert_multi "$TABLE" "$COLUMN" $FID "'$2'"
|
||||||
}
|
}
|
||||||
|
|
||||||
add_path_auto() {
|
add_path_auto() {
|
||||||
|
@ -187,16 +188,23 @@ tag_exists_in_db() {
|
||||||
|
|
||||||
file_exists_in_db() {
|
file_exists_in_db() {
|
||||||
# $FILENAME
|
# $FILENAME
|
||||||
local FILENAME=$(basename "${1:-}")
|
local RESULT=$(file_by_filename "$1")
|
||||||
local FILEPATH=$(dirname "${1:-}")
|
if [[ "$RESULT" -eq 0 ]]; then
|
||||||
local RESULT=$(sqlite_query "SELECT id FROM files WHERE filename = '$FILENAME' AND path = '$FILEPATH'")
|
|
||||||
if [[ -z "$RESULT" ]]; then
|
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file_by_filename() {
|
||||||
|
# FILENAME
|
||||||
|
local FILENAME=$(basename "${1:-}")
|
||||||
|
local FILEPATH=$(realpath $(dirname "${1:-}"))
|
||||||
|
local RESULT=0
|
||||||
|
RESULT=$(sqlite_query "SELECT id FROM files WHERE filename = '$FILENAME' AND path = '$FILEPATH'")
|
||||||
|
echo $RESULT
|
||||||
|
}
|
||||||
|
|
||||||
dbfile_exists() {
|
dbfile_exists() {
|
||||||
if [[ ! -f "$DB_FILE" ]]; then
|
if [[ ! -f "$DB_FILE" ]]; then
|
||||||
return 1
|
return 1
|
||||||
|
|
Loading…
Reference in New Issue