diff options
author | Dave Reisner <d@falconindy.com> | 2011-07-15 04:59:36 +0200 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2011-09-27 12:18:04 +0200 |
commit | 06331559487ccc6cca1b770b2e21c5e3f7bec5c3 (patch) | |
tree | 9abc0272bfbf52c09f18dab18790f29aaf491002 /functions | |
parent | 5a0f7ebc8d2cede7532539268e0ffc0bd6816572 (diff) | |
download | mkinitcpio-06331559487ccc6cca1b770b2e21c5e3f7bec5c3.tar.gz mkinitcpio-06331559487ccc6cca1b770b2e21c5e3f7bec5c3.tar.xz |
functions: refactor get_{base,dir}name
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@falconindy.com>
Diffstat (limited to 'functions')
-rw-r--r-- | functions | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -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:-/}" } in_array() { |