Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get and apply bash flags and options settings #726

Merged

Conversation

jsmeix
Copy link
Member

@jsmeix jsmeix commented Dec 2, 2015

Implemented simple functions get_bash_flags_and_options_commands
and apply_bash_flags_and_options_commands that are used
in a fail-safe way via an explicit variable that
stores the current bash flags and options commands
and using that explicit variable to re-apply them, i.e. like

      saved_flags_options_cmds="$( get_bash_flags_and_options_commands )"
      ... [change bash flags and options] ...
      ... [do something] ...
      apply_bash_flags_and_options_commands "$saved_flags_options_cmds"

Currently those functions are used in framework-functions.sh
when "Entering debugscripts mode" and "Leaving debugscripts mode"
so that the workaround by using DEBUGSCRIPTS_OPPOSITE_ARGUMENT is obsoleted.

See #700

functionality for bash flags and options settings,
see rear#700
in usr/share/rear/lib/framework-functions.sh which should obsolete
the DEBUGSCRIPTS_OPPOSITE_ARGUMENT workaround,
see rear#700
and ApplyBashFlagsAndOptionsCommands that are used
in a fail-safe way via an explicit variable that
stores the current bash flags and options commands
and using that explicit variable to re-apply them, i.e. like
  saved_flags_options_cmds="$( GetBashFlagsAndOptionsCommands )"
  ... [change bash flags and options]
  ... [do something]
  ApplyBashFlagsAndOptionsCommands "$saved_flags_options_cmds"

In contrast using implicitly a stack of saved_flags_options_cmds
via SaveFlagsAndOptions and RestoreFlagsAndOptions functions
is not equally fail-safe because one must carefully ensure that
each element that is put onto the stack via SaveFlagsAndOptions
gets removed later via RestoreFlagsAndOptions, e.g.
  SaveFlagsAndOptions
  ... [change bash flags and options]
  ... [do something]
  if <condition> ; then
      SaveFlagsAndOptions
      ... [change bash flags and options]
      ... [do something]
  fi
  ... [do something]
  RestoreFlagsAndOptions
restores wrong flags and options in case of <condition>.

Furthermore using implicitly a stack of saved_flags_options_cmds
makes it complicated to restore an explicity named state
or to simply restore a specific state several times like:
  initial_flags_options_cmds="$( GetBashFlagsAndOptionsCommands )"
  ... [change bash flags and options]
  ... [do something]
  if <condition> ; then
      saved_flags_options_cmds="$( GetBashFlagsAndOptionsCommands )"
      ... [change bash flags and options]
      ... [do something]
      ApplyBashFlagsAndOptionsCommands "$saved_flags_options_cmds"
      ... [do something]
  fi
  ApplyBashFlagsAndOptionsCommands "$initial_flags_options_cmds"
  ... [do something]
  ... [change bash flags and options]
  ... [do something]
  ApplyBashFlagsAndOptionsCommands "$initial_flags_options_cmds"
and apply_bash_flags_and_options_commands that are used
in a fail-safe way via an explicit variable that
stores the current bash flags and options commands
and using that explicit variable to re-apply them, i.e. like
  saved_flags_options_cmds="$( get_bash_flags_and_options_commands )"
  ... [change bash flags and options] ...
  ... [do something] ...
  apply_bash_flags_and_options_commands "$saved_flags_options_cmds"

In contrast using implicitly a stack of saved_flags_options_cmds
via save_flags_and_options and restore_flags_and_options functions
is not equally fail-safe because one must carefully ensure that
each element that is put onto the stack via save_flags_and_options
gets removed later via restore_flags_and_options, i.e. the
save_flags_and_options and restore_flags_and_options function
calls must be carefully balanced in any case in all scripts,
e.g. the following loppy code restores wrong flags and options
in case of <condition>:
  save_flags_and_options
  ... [change bash flags and options] ...
  ... [do something] ...
  if <condition> ; then
      save_flags_and_options
      ... [change bash flags and options] ...
      ... [do something] ...
  fi
  ... [do something] ...
  restore_flags_and_options

Furthermore using implicitly a stack of saved_flags_options_cmds
makes it complicated to restore an explicity named state
or to simply restore a specific state several times like:
  initial_flags_options_cmds="$( get_bash_flags_and_options_commands )"
  ... [change bash flags and options] ...
  ... [do something] ...
  if <condition> ; then
      saved_flags_options_cmds="$( get_bash_flags_and_options_commands )"
      ... [change bash flags and options] ...
      ... [do something] ...
      apply_bash_flags_and_options_commands "$saved_flags_options_cmds"
      ... [do something] ...
  fi
  apply_bash_flags_and_options_commands "$initial_flags_options_cmds"
  ... [do something] ...
  ... [change bash flags and options] ...
  ... [do something] ...
  apply_bash_flags_and_options_commands "$initial_flags_options_cmds"

Finally, if using implicitly a stack of saved_flags_options_cmds
via save_flags_and_options and restore_flags_and_options functions
is really needed, it can be implemented later as an enhancement that
is based on the simple functions get_bash_flags_and_options_commands
and apply_bash_flags_and_options_commands.
@gdha
Copy link
Member

gdha commented Dec 2, 2015

@jsmeix I'm good with your enhancements - perhaps if I need to say something - add a remark in the main script that functions belong the the library scripts, but that these 2 are exceptions on the rule.
And, add yourself to the AUTHORS list, ok?
Gratien

belong to the library scripts, but that these 2 are exceptions,
and added myself (jsmeix) to the AUTHORS list in usr/sbin/rear
@gdha gdha added this to the Rear v1.18 milestone Dec 3, 2015
@gdha gdha self-assigned this Dec 3, 2015
gdha added a commit that referenced this pull request Dec 3, 2015
…ons_settings

Get and apply bash flags and options settings
@gdha gdha merged commit 9f1f375 into rear:master Dec 3, 2015
@jsmeix jsmeix deleted the get_and_apply_bash_flags_and_options_settings branch December 3, 2015 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants