When I'm cleaning up tmsu stuff(missing files, mass tagging, etc) I often have a few different operations that need to be queued up, in separate terminals. This script monitors whether any tmsu operations are running that lock the db, and returns when there are none.
So running it before tmsu commands (as in 'waitfortmsu; tmsu repair --remove some/file') will mostly (99% -- there is still a small possibility of race conditions occurring) prevent 'database is locked' errors.
Maybe instead there should be a global TMSU option to wait for the database to be unlocked before trying to run whatever operation is selected?
Anyhow, here's the 'waitfortmsu' script:
#!/bin/sh
# wait for TMSU operations that lock the db to complete
#
# These operations are: copy delete imply merge rename tag untag repair
#
# Newer versions may contain other operation modes which write to the db; these should be added to the list below.
#
INSTANCES=10
while [ "$INSTANCES" -gt 0 ]; do
INSTANCES=$(ps aux | fgrep 'tmsu copy
tmsu delete
tmsu imply
tmsu merge
tmsu rename
tmsu tag
tmsu untag
tmsu repair' | fgrep -v "grep" | wc -l)
if [ "$INSTANCES" -gt 0 ]; then sleep 2; fi
done