From ed0191e4500eda42810fdfe2c40b70fcf98ded7d Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Thu, 13 Feb 2020 00:32:48 +0100 Subject: [PATCH] Allow disabling destinations --- atom | 17 +++++++++++++++-- lib/config/getDestination | 3 +++ lib/config/print | 1 + lib/config/write | 3 +++ lib/database/checkVersion | 2 +- lib/database/upgradedatabase_2_3 | 14 ++++++++++++++ lib/destinations/create | 2 +- lib/tools/progressSpin | 8 ++++---- 8 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 lib/database/upgradedatabase_2_3 diff --git a/atom b/atom index 9e2531a..05f719e 100755 --- a/atom +++ b/atom @@ -13,6 +13,7 @@ EFMTINVPARM=49 # config structures declare -A \ + destinationenabled \ destinationascii \ destinationchannels \ destinationfat32compat \ @@ -330,6 +331,16 @@ fi openDatabase +for destination in "${!destinationpath[@]}" +do + if (( ${destinationenabled["$destination"]} )) + then + Update destinations enabled 1 <<<"name = $destination" + else + Update destinations enabled 0 <<<"name = $destination" + fi +done + createDestinations getFiles @@ -513,7 +524,8 @@ echo ' ON mime_type_actions.id = source_files.mime_type INNER JOIN tags ON source_files.id = tags.source_file - WHERE CAST(destination_files.last_change AS TEXT) + WHERE destinations.enabled = 1 + AND CAST(destination_files.last_change AS TEXT) <> CAST(source_files.last_change AS TEXT) AND mime_type_actions.destination_id = destinations.id AND mime_type_actions.action = 1;' >&3 @@ -554,7 +566,8 @@ echo ' ON mime_type_actions.id = source_files.mime_type INNER JOIN tags ON source_files.id = tags.source_file - WHERE CAST(destination_files.last_change AS TEXT) + WHERE destinations.enabled = 1 + AND CAST(destination_files.last_change AS TEXT) <> CAST(source_files.last_change AS TEXT) AND mime_type_actions.destination_id = destinations.id AND mime_type_actions.action = 1 diff --git a/lib/config/getDestination b/lib/config/getDestination index 2926648..20773db 100644 --- a/lib/config/getDestination +++ b/lib/config/getDestination @@ -1,6 +1,9 @@ #!/bin/bash getConfigDestination() { case "$key" in + 'enabled') + destinationenabled["$destination"]="$value" + ;; 'path') destinationpath["$destination"]="$value" ;; diff --git a/lib/config/print b/lib/config/print index 567c547..ddbc65e 100644 --- a/lib/config/print +++ b/lib/config/print @@ -26,6 +26,7 @@ printConfig() { cat <<-EOF $destination|Path|${destinationpath["$destination"]} + |Enabled|${destinationenabled["$destination"]} |Format|${destinationformat["$destination"]} |Quality|${destinationquality["$destination"]} EOF diff --git a/lib/config/write b/lib/config/write index d8b6b36..40da076 100644 --- a/lib/config/write +++ b/lib/config/write @@ -60,6 +60,9 @@ path $sourcepath # Common parameters: # Mandatory parameters: +# * enabled: Whether or not to treat this destination (1=tue/0=false) +enabled 1 + # * path: Where files will be written path ${destinationpath["$destination"]} diff --git a/lib/database/checkVersion b/lib/database/checkVersion index 3491709..dcef357 100644 --- a/lib/database/checkVersion +++ b/lib/database/checkVersion @@ -1,5 +1,5 @@ #!/bin/bash -currentdbversion=2 +currentdbversion=3 checkDatabaseVersion() { local dbversion if dbversion=$(Select atom version <<<"\"1\" = 1") diff --git a/lib/database/upgradedatabase_2_3 b/lib/database/upgradedatabase_2_3 new file mode 100644 index 0000000..998556f --- /dev/null +++ b/lib/database/upgradedatabase_2_3 @@ -0,0 +1,14 @@ +#!/bin/bash + +upgradedatabase_2_3() { + local data \ + datas \ + id \ + destination + echo "Upgrading database to version 3... (backup is $database.bak_v2)" + cp "$database" "$database.bak_v2" + echo 'ALTER TABLE destinations ADD COLUMN enabled INTEGER DEFAULT 1;' >&3 + Update destinations enabled 1 <<< "1 = 1" + + Update atom version 3 <<<"1 = 1" +} \ No newline at end of file diff --git a/lib/destinations/create b/lib/destinations/create index fc6e3bc..e30b835 100644 --- a/lib/destinations/create +++ b/lib/destinations/create @@ -11,7 +11,7 @@ createDestinations() { fi fi destinationid["$destination"]=$( - InsertIfUnset destinations <<<"name $destination" + InsertIfUnset destinations <<<"name $destination ${destinationenabled[\"$destination\"]}" ) done } diff --git a/lib/tools/progressSpin b/lib/tools/progressSpin index b30a18c..40dbb52 100644 --- a/lib/tools/progressSpin +++ b/lib/tools/progressSpin @@ -5,10 +5,10 @@ progressSpin() { (( ++count )) else case $(( ++count % 40 )) in - 0) echo -ne $count '\b|' ;; - 10) echo -ne $count '\b/' ;; - 20) echo -en $count '\b-' ;; - 30) echo -ne $count '\b\\' ;; + 0) echo -n $'\b|' ;; + 10) echo -n $'\b/' ;; + 20) echo -n $'\b-' ;; + 30) echo -n $'\b\\' ;; *) ;; esac fi