Compare commits

..

No commits in common. "741f3490288ceeee1b379bd34c8f369de339167a" and "1580865b56265d5768fe9fda3799cda2609cdcfa" have entirely different histories.

2 changed files with 8 additions and 24 deletions

25
tag.sh
View File

@ -150,7 +150,6 @@ add_path() {
COLUMN="filename,path"
FILES=()
for FILE in "$@"; do
[ ! -f "$FILE" ] && fail "File '$FILE' does not exist in the specified path."
local FILENAME=$(basename "$FILE")
local FILEPATH=$(realpath $(dirname "$FILE"))
file_exists_in_db "$FILE" && fail "File '$FILE' already exists in database."
@ -162,13 +161,12 @@ add_path() {
add_hash() {
# $FILE $HASH
local TABLE="hashes"
local COLUMN="fid,md5"
TABLE="hashes"
COLUMN="fid,md5"
local FILENAME="${1:-}"
[ -z "$FILENAME" ] && fail "No file specified."
local FID=$(file_by_filename "$FILENAME")
[[ "$FID" -eq 0 ]] && fail "File \"$FILENAME\" does not exist in database."
sqlite_insert_multi "$TABLE" "$COLUMN" $FID "'$2'"
! file_exists_in_db "$FILENAME" && fail "File \"$FILENAME\" does not exist in database."
sqlite_insert_multi "$TABLE" "$COLUMN" $RESULT "'$2'"
}
add_path_auto() {
@ -189,23 +187,16 @@ tag_exists_in_db() {
file_exists_in_db() {
# $FILENAME
local RESULT=$(file_by_filename "$1")
if [[ "$RESULT" -eq 0 ]]; then
local FILENAME=$(basename "${1:-}")
local FILEPATH=$(dirname "${1:-}")
local RESULT=$(sqlite_query "SELECT id FROM files WHERE filename = '$FILENAME' AND path = '$FILEPATH'")
if [[ -z "$RESULT" ]]; then
return 1
else
return 0
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() {
if [[ ! -f "$DB_FILE" ]]; then
return 1

View File

@ -15,7 +15,6 @@ oneTimeTearDown() {
# runs one-time teardown two times
# see https://github.com/kward/shunit2/issues/112
[ -f "$DB_FILE" ] && rm "$DB_FILE"
rm "$FILENAME"
}
testDbCreated() {
@ -28,13 +27,7 @@ testTagAdded() {
assertEquals $RESULT "hello"
}
testFailAddingNonexistentFile() {
tag --db "$DB_FILE" import "$FILENAME" 2>/dev/null
assertEquals "$?" 1
}
testFilenameAdded() {
touch "$FILENAME"
tag --db "$DB_FILE" add path "$FILENAME" >/dev/null
RESULT=$(sqlite3 "$DB_FILE" "SELECT filename from files WHERE filename = '$FILENAME'")
assertEquals "$RESULT" "$FILENAME"