From 1332c386564f02380a6c4cc79c6cadf4ce59f448 Mon Sep 17 00:00:00 2001 From: Gofannon Date: Tue, 25 Aug 2020 23:36:47 +0200 Subject: [PATCH] [enh] Simplify by removing subprocess + add comment --- scripts/upgrade | 76 +++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 41 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 88f5813..cf19ba1 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -230,49 +230,43 @@ then # See https://www.dokuwiki.org/install:unused_files if [ -f "$final_path/data/deleted.files" ]; then - # Use a "sub process" to start a new shell to run these commands - # Allow to use only one "cd" and to be more efficent - ( - # Move to the dokuwiki installation folder so the "official" commands can be used without adaptation - cd $final_path + # Feed output of grep[...] line by line to 'ynh_secure_remove' + # 'ynh_secure_remove' can only work file by file. Cannot work with a list + # This is a (complicated) workaround this limitation + while IFS= read -r line; do - while IFS= read -r line; do + # Added this test to reduce the spam printed by helper to the user in the webadmin. + # Should be less 'scary' to them I think + # + # number of messages = number of lines *2 (673 lines while writing this) + ### grep --extended-regexp --invert-match '^($|#)' data/deleted.files | wc -l + ### 673 + # + # Spam sample: + #Attention : /!\ Packager ! You provided more than one argument to ynh_secure_remove but it will be ignored... Use this helper with one argument at time. + #Info : 'inc/parser/spamcheck.php' wasn't deleted because it doesn't exist. + #Attention : /!\ Packager ! You provided more than one argument to ynh_secure_remove but it will be ignored... Use this helper with one argument at time. + #Attention : /!\ Packager ! You provided more than one argument to ynh_secure_remove but it will be ignored... Use this helper with one argument at time. + #Info : 'lib/images/favicon.ico' wasn't deleted because it doesn't exist. + #Info : 'lib/images/thumbup.gif' wasn't deleted because it doesn't exist. + #Attention : /!\ Packager ! You provided more than one argument to ynh_secure_remove but it will be ignored... Use this helper with one argument at time. + #Info : 'lib/images/toolbar/code.png' wasn't deleted because it doesn't exist. + #Attention : /!\ Packager ! You provided more than one argument to ynh_secure_remove but it will be ignored... Use this helper with one argument at time. + #Info : 'lib/images/toolbar/empty.png' wasn't deleted because it doesn't exist. + if [ -f "$line" ]; then + ynh_secure_remove --file "$line" + fi + done < <(grep --null --extended-regexp --invert-match '^($|#)' "$final_path/data/deleted.files" | xargs --null --max-args=1 || true) + # ^ ^ First < is redirection, second is process substitution. + # Source: https://tldp.org/LDP/abs/html/process-sub.html - # Added this test to reduce the spam printed by helper to the user in the webadmin. - # Should be less 'scary' to them I think - # - # number of messages = number of lines *2 (673 lines while writing this) - ### grep --extended-regexp --invert-match '^($|#)' data/deleted.files | wc -l - ### 673 - # - # Spam sample: - #Attention : /!\ Packager ! You provided more than one argument to ynh_secure_remove but it will be ignored... Use this helper with one argument at time. - #Info : 'inc/parser/spamcheck.php' wasn't deleted because it doesn't exist. - #Attention : /!\ Packager ! You provided more than one argument to ynh_secure_remove but it will be ignored... Use this helper with one argument at time. - #Attention : /!\ Packager ! You provided more than one argument to ynh_secure_remove but it will be ignored... Use this helper with one argument at time. - #Info : 'lib/images/favicon.ico' wasn't deleted because it doesn't exist. - #Info : 'lib/images/thumbup.gif' wasn't deleted because it doesn't exist. - #Attention : /!\ Packager ! You provided more than one argument to ynh_secure_remove but it will be ignored... Use this helper with one argument at time. - #Info : 'lib/images/toolbar/code.png' wasn't deleted because it doesn't exist. - #Attention : /!\ Packager ! You provided more than one argument to ynh_secure_remove but it will be ignored... Use this helper with one argument at time. - #Info : 'lib/images/toolbar/empty.png' wasn't deleted because it doesn't exist. - if [ -f "$line" ]; then - ynh_secure_remove --file "$line" - fi - done < <(grep --null --extended-regexp --invert-match '^($|#)' "$final_path/data/deleted.files" | xargs --null --max-args=1 || true) - # ^ ^ First < is redirection, second is process substitution. - # Source: https://tldp.org/LDP/abs/html/process-sub.html - - # Previous attemps if someone reads this one day - ###grep --extended-regexp --invert-match '^($|#)' data/deleted.files | xargs --max-args=1 rm --verbose --force --dir 2>&1 || true - ###grep --extended-regexp --invert-match '^($|#)' data/deleted.files | xargs --max-args=1 ynh_secure_remove --file 2>&1 - - ###grep --null --extended-regexp --invert-match '^($|#)' data/deleted.files > toto.list - ###xargs --null --verbose --max-args=1 --arg-file=toto.list ynh_secure_remove 2>&1 - - - ) - fi + # Previous attemps if someone reads this one day + ###grep --extended-regexp --invert-match '^($|#)' data/deleted.files | xargs --max-args=1 rm --verbose --force --dir 2>&1 || true + ###grep --extended-regexp --invert-match '^($|#)' data/deleted.files | xargs --max-args=1 ynh_secure_remove --file 2>&1 + + ###grep --null --extended-regexp --invert-match '^($|#)' data/deleted.files > toto.list + ###xargs --null --verbose --max-args=1 --arg-file=toto.list ynh_secure_remove 2>&1 +fi # TODO Taken from old "upgrade" script. Should check if it is needed and what it does # Update all plugins