Store destination filenames relatively to the dest root

This commit is contained in:
Vincent Riquer 2025-11-08 18:09:08 +01:00
parent ce1ff7aff5
commit c114645781
9 changed files with 46 additions and 19 deletions

35
atom
View File

@ -214,9 +214,13 @@ read -u4 removecount
until (( ${#removefile[@]} == removecount ))
do
echo '
SELECT id,
filename
SELECT destination_files.id,
destinations.name,
destination_files.filename
FROM destination_files
INNER JOIN destinations
ON destination_files.destination_id
= destinations.id
WHERE source_file_id is NULL
LIMIT 500 OFFSET '${#removefile[@]}';
@ -226,7 +230,11 @@ do
read -u4 line
until [[ $line == AtOM:NoMoreFiles ]]
do
removefile[${line%::AtOM:SQL:Sep::*}]="${line#*::AtOM:SQL:Sep::}"
removeFileId=${line%%::AtOM:SQL:Sep::*}
rest=${line#*::AtOM:SQL:Sep::}
removeFileDestName=${line%%::AtOM:SQL:Sep::*}
rest=${line#*::AtOM:SQL:Sep::}
removefile[$removeFileId]="${destinationpath["$removeFileDestName"]}/${rest%%::AtOM:SQL:Sep::*}"
read -u4 line
done
done
@ -288,6 +296,7 @@ echo '
ascii INTEGER,
source_file INTEGER,
fileid INTEGER,
destdir TEXT,
filename TEXT,
cmd_arg0 TEXT,
cmd_arg1 TEXT,
@ -894,7 +903,9 @@ do
progressSpin
if [[ "$oldfilename" != "$destfilename" ]]
then
mv "$oldfilename" "$destfilename"
mv \
"${destinationpath[$destination]}/$oldfilename" \
"${destinationpath[$destination]}/$destfilename"
(( changedcount++ ))
commit=1
fi
@ -929,10 +940,14 @@ done
copyFiles_action
echo '
SELECT id,
filename,
old_filename
SELECT destination_files.id,
destination_files.filename,
destination_files.old_filename,
destinations.name
FROM destination_files
INNER JOIN destinations
ON destination_files.destination_id
= destinations.id
WHERE old_filename IS NOT NULL;
SELECT "AtOM:NoMoreFiles";
@ -952,10 +967,12 @@ do
id=${line%%::AtOM:SQL:Sep::*}
rest=${line#*::AtOM:SQL:Sep::}
filename=${rest%%::AtOM:SQL:Sep::*}
oldfilename=${rest#*::AtOM:SQL:Sep::}
rest=${line#*::AtOM:SQL:Sep::}
oldfilename=${rest%%::AtOM:SQL:Sep::*}
destination=${rest#*::AtOM:SQL:Sep::}
if [[ $oldfilename != "$filename" ]] && [ -f "$oldfilename" ]
then
rm -f "$oldfilename"
rm -f "${destinationpath[$destination]}/$oldfilename"
fi
Update destination_files old_filename NULL <<<"id = $id"
(( count++ ))

View File

@ -5,7 +5,7 @@ getConfigDestination() {
destinationenabled["$destination"]="$value"
;;
'path')
destinationpath["$destination"]="$value"
destinationpath["$destination"]="${value%/}"
;;
'format')
case "$value" in

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
currentdbversion=6
currentdbversion=7
checkDatabaseVersion() {
local dbversion
if dbversion=$(Select atom version <<<"\"1\" = 1")

View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
upgradedatabase_6_7() {
echo "Upgrading database to version 7... (backup is $database.bak_v6)"
cp "$database" "$database.bak_v6"
for destination in "${destinations[@]}"
do
echo "UPDATE destination_files SET filename = REPLACE(filename,'${destinationpath[$destination]}/','') WHERE filename LIKE '${destinationpath[$destination]}/%';" >&3
done
Update atom version 7 <<<"1 = 1"
}

View File

@ -53,7 +53,7 @@ encodeFile::mp3() {
esac
fi
fi
lameopts+=("$tempdir/$tmpfile.wav" "$destdir/$destfile.mp3")
lameopts+=("$tempdir/$tmpfile.wav" "${destinationpath[$destination]}/$destdir/$destfile.mp3")
encodetaskid=$(
Insert tasks <<-EOInsert
key ${fileid}lame$destination

View File

@ -23,7 +23,7 @@ encodeFile::opus() {
[ -n "$track" ] && opusencopts+=(--comment "TRACKNUMBER=${track%/*}")
[ -n "${track#*/}" ] && opusencopts+=(--comment "TRACKTOTAL=${track#*/}")
[ -n "$year" ] && opusencopts+=(--comment "DATE=$year")
opusencopts+=("$tempdir/$tmpfile".wav "$destdir/$destfile.opus")
opusencopts+=("$tempdir/$tmpfile".wav "${destinationpath[$destination]}/$destdir/$destfile.opus")
encodetaskid=$(
Insert tasks <<-EOInsert
key ${fileid}opusenc$destination

View File

@ -17,7 +17,7 @@ encodeFile::vorbis() {
[ -n "$title" ] && oggencopts+=(-t "$title")
[ -n "$track" ] && oggencopts+=(-N "$track")
[ -n "$year" ] && oggencopts+=(-d "$year")
oggencopts+=(-o "$destdir/$destfile.ogg" "$tempdir/$tmpfile.wav")
oggencopts+=(-o "${destinationpath[$destination]}/$destdir/$destfile.ogg" "$tempdir/$tmpfile.wav")
encodetaskid=$(
Insert tasks <<-EOInsert
key ${fileid}oggenc$destination

View File

@ -41,7 +41,7 @@ getDestDir() {
)
)
then
destdir="${destinationpath[$destination]}/"
destdir=""
if (( ${destinationascii["$destination"]} ))
then
echo "$album" >&${toascii[1]}
@ -83,8 +83,7 @@ getDestDir() {
replace=$(sanitizeFile "$disc" dir)
destdir="${destdir//?(\[)%\{disc\}?(\])/$replace}"
else
destdir="${destinationpath[$destination]}/"
destdir+=$(sanitizeFile "${filename%%/*}" dir)
destdir=$(sanitizeFile "${filename%%/*}" dir)
part=${filename#*/}
while [[ $part =~ / ]]
do
@ -101,7 +100,7 @@ getDestDir() {
fi
if ! [ -d "$destdir" ]
then
mkdir -p "$destdir"
mkdir -p "${destinationpath[$destination]}/$destdir"
fi
destdir="${destdir//+(\/)//}"
}

View File

@ -1,7 +1,7 @@
#!/bin/bash
getTags_version='unknown-4'
getTags() {
unset type
local type
case "$mimetype" in
audio/mpeg)
type=ffmpeg