#1354 Issue closed: Possibly false IsInArray usage in 610_exclude_from_restore.sh

Labels: fixed / solved / done, minor bug

jsmeix opened issue at 2017-05-10 11:19:

In current GitHub master code I found via

# find usr/sbin/rear usr/share/rear/ | xargs grep -o 'IsInArray .*' | grep -v '\[@\]'

in usr/share/rear/layout/prepare/default/610_exclude_from_restore.sh

    if ! IsInArray "$component" "${EXCLUDE_RESTORE}" ; then

I wonder if "${EXCLUDE_RESTORE}" is a typo
and actually "${EXCLUDE_RESTORE[@]}" is meant?

Currently I do not sufficiently understand the code
to "just change" it.

It was introduced via
https://github.com/rear/rear/commit/78bfff162557f28c20c1e5a38cb509d0b4afcd77

Because it seems to work since then (on 8 Jun 2011)
it may be intentional?

jsmeix commented at 2017-05-22 07:30:

I postpone it for a later release (after 2.1 - for now for 2.2)
because no real bad consequence is currently known.

gdha commented at 2017-07-19 15:07:

post-pone to release 2.3

jsmeix commented at 2017-12-01 13:37:

nothing known to go wrong here
so nothing needs to be done right now
so that I postpone it to ReaR 2.4

jsmeix commented at 2018-05-03 13:31:

The current code in
https://github.com/rear/rear/blob/master/usr/share/rear/layout/prepare/default/610_exclude_from_restore.sh

    if ! IsInArray "$component" "${EXCLUDE_RESTORE}" ; then
        EXCLUDE_RESTORE=( "${EXCLUDE_RESTORE[@]}" "$component" )
    fi

looks clearly "just wrong" from my point of view and should be fixed as

    if ! IsInArray "$component" "${EXCLUDE_RESTORE[@]}" ; then
        EXCLUDE_RESTORE=( "${EXCLUDE_RESTORE[@]}" "$component" )
    fi

or is there a special reason why in this particular case the IsInArray function
must search "$component" only in the first EXCLUDE_RESTORE array member?
If that was really intended the code should have been simply something like

    if ! test "$component" = "$EXCLUDE_RESTORE" ; then
        EXCLUDE_RESTORE=( "${EXCLUDE_RESTORE[@]}" "$component" )
    fi

but because the IsInArray function is called I really assume it should inspect
if "$component" is any of the EXCLUDE_RESTORE array members.

@gdha @gozora @schabrolles
if you do not object I will change it tomorrow from

    if ! IsInArray "$component" "${EXCLUDE_RESTORE}" ; then

to

    if ! IsInArray "$component" "${EXCLUDE_RESTORE[@]}" ; then

jsmeix commented at 2018-05-08 09:59:

Fixed via
https://github.com/rear/rear/commit/a5486cd72d19e06c7f53ee3aa608ceab3b2101ad


[Export of Github issue for rear/rear.]