[arch-projects] [mkinitcpio][PATCH 07/26] functions: refactor get_{base, dir}name
Dan McGee
dpmcgee at gmail.com
Mon Sep 26 23:40:39 EDT 2011
On Mon, Sep 26, 2011 at 8:22 PM, Dave Reisner <d at falconindy.com> wrote:
> From: Dave Reisner <d at falconindy.com>
>
> Make sure these are completely safe for user input. Use the same three
> step process in both cases:
>
> 1) Strip any trailing slash
> 2) Trim the string according to base/dir request
> 3) Print the result, defaulting to / if step 2 yielded an empty string
>
> Signed-off-by: Dave Reisner <d at falconindy.com>
> ---
> functions | 15 ++++++++-------
> 1 files changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/functions b/functions
> index c7e167e..2f5797a 100644
> --- a/functions
> +++ b/functions
> @@ -30,15 +30,16 @@ die() {
> cleanup 1
> }
>
> -get_dirname() {
> - # strip any trailing slash first...
> - local dir="${1%/}"
> - # then get the directory portion
> - echo "${dir%/*}"
> +get_basename() {
> + local base=${1%/}
> + base=${base##*/}
> + printf '%s' "${base:-/}"
> }
>
> -get_basename() {
> - echo "${1##*/}"
> +get_dirname() {
> + local dir=${1%/}
> + dir=${dir%/*}
> + printf '%s' "${dir:-/}"
> }
Did you flip the order of the functions just to make the diff
trickier? Otherwise this looks OK.
>
> in_array() {
> --
> 1.7.6.4
More information about the arch-projects
mailing list