From 78cbbfd228957f28c2d6fdc2c7daf10a111329e8 Mon Sep 17 00:00:00 2001 From: Jiri Date: Aug 31 2022 16:43:19 +0000 Subject: [PATCH 1/2] Prevent deleting dirs/files out of the java folders https://bugzilla.redhat.com/show_bug.cgi?id=2100617 --- diff --git a/copy_jdk_configs_fixFiles.sh b/copy_jdk_configs_fixFiles.sh index 7e87be8..ec2d0ec 100755 --- a/copy_jdk_configs_fixFiles.sh +++ b/copy_jdk_configs_fixFiles.sh @@ -10,6 +10,18 @@ debug(){ debug "cjc: bash debug is on" +isJavaConfig() { + local arg="${1}" + if [[ `realpath -s $arg` = /usr/lib/jvm/java* || `realpath -s $arg` = /etc/java/java* ]] ; then + if [[ `readlink -f $arg` = /usr/lib/jvm/java* || `readlink -f $arg` = /etc/java/java* ]] ; then + debug "$arg / `realpath -s $arg` / `readlink -f $arg` is correct jdk folder" + return 0 + fi + fi + debug "$arg / `realpath -s $arg` / `readlink -f $arg` is not jdk folder, file/dir should be skipped" + return 1 +} + cmdvDebug() { if [ "x$debug" == "xtrue" ] ; then "$@" -v @@ -23,11 +35,19 @@ mvDebug() { } rmDebug() { - cmdvDebug rm "$@" + for x in "$@" ; do + if isJavaConfig "$x" ; then + cmdvDebug rm "$@" + fi + done } rmdirDebug() { - cmdvDebug rmdir "$@" + for x in "$@" ; do + if isJavaConfig "$x" ; then + cmdvDebug rmdir "$@" + fi + done } #we should be pretty strict about removing once used (even "used" [with fail]) config file, as it may corrupt another installation @@ -225,9 +245,12 @@ done debug "cleaning legacy leftowers" if [ "x$debug" == "xtrue" ] ; then - find $sourceSearchPath -empty -type d -delete + emptyCandidates=`find $sourceSearchPath -empty -type d` else - find $sourceSearchPath -empty -type d -delete 2>/dev/null >/dev/null + emptyCandidates=`find $sourceSearchPath -empty -type d 2>/dev/null` +fi +if [ ! "x$emptyCandidates" == "x" ] ; then + rmdirDebug $emptyCandidates fi rmdirDebug $sourceSearchPath From a793903bbe7c6aba36b9bee49a35a15157d6db0d Mon Sep 17 00:00:00 2001 From: Jiri Vanek Date: Sep 26 2022 14:28:24 +0000 Subject: [PATCH 2/2] Extracted realpath and readlin to variables --- diff --git a/copy_jdk_configs_fixFiles.sh b/copy_jdk_configs_fixFiles.sh index ec2d0ec..0e4ce9f 100755 --- a/copy_jdk_configs_fixFiles.sh +++ b/copy_jdk_configs_fixFiles.sh @@ -12,13 +12,15 @@ debug "cjc: bash debug is on" isJavaConfig() { local arg="${1}" - if [[ `realpath -s $arg` = /usr/lib/jvm/java* || `realpath -s $arg` = /etc/java/java* ]] ; then - if [[ `readlink -f $arg` = /usr/lib/jvm/java* || `readlink -f $arg` = /etc/java/java* ]] ; then - debug "$arg / `realpath -s $arg` / `readlink -f $arg` is correct jdk folder" + local relpath=`realpath -s $arg` + local realink=`readlink -f $arg` + if [[ ${relpath} = /usr/lib/jvm/java* || ${relpath} = /etc/java/java* ]] ; then + if [[ ${realink} = /usr/lib/jvm/java* || ${realink} = /etc/java/java* ]] ; then + debug "$arg / ${relpath} / ${realink} is correct jdk folder" return 0 fi fi - debug "$arg / `realpath -s $arg` / `readlink -f $arg` is not jdk folder, file/dir should be skipped" + debug "$arg / ${relpath} / ${realink} is not jdk folder, file/dir should be skipped" return 1 }