Skip to content

Commit

Permalink
fs: remove redudant $? usage in exit and return statements
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Jan 17, 2025
1 parent cf7eceb commit d259793
Show file tree
Hide file tree
Showing 17 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion commands/fs-absolute.bash
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ while [[ $# -ne 0 ]]; do
# Affirm accessibility
if [[ ! -e $path ]]; then
# discern if inaccessible
is-accessible.bash -- "$path" || exit $?
is-accessible.bash -- "$path" || exit
# if missing, then it only matters if the parent is missing, which the following will deal with
fi

Expand Down
4 changes: 2 additions & 2 deletions commands/fs-dequarantine.bash
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ while [[ $# -ne 0 ]]; do
# note that the -r option doesn't exist, will return [option -r not recognized] on Ventura and Sonoma
# cannot just -d directly, as will get a [No such xattr: com.apple.quarantine] error, so check for it first, this induces no errors
if /usr/bin/xattr -l "$path" | grep --quiet --fixed-strings --regexp='com.apple.quarantine'; then
/usr/bin/xattr -d com.apple.quarantine "$path" >/dev/stderr || exit $?
/usr/bin/xattr -d com.apple.quarantine "$path" >/dev/stderr || exit
fi
continue
elif [[ -e $path ]]; then
# does exist: is not readable
exit 13 # EACCES 13 Permission denied
else
# discern if inaccessible, broken, missing
is-accessible.bash -- "$path" || exit $?
is-accessible.bash -- "$path" || exit
if [[ -L $path ]]; then
# broken symlink
exit 9 # EBADF 9 Bad file descriptor
Expand Down
4 changes: 2 additions & 2 deletions commands/is-broken-symlink.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ while [[ $# -ne 0 ]]; do
exit 79 # EFTYPE 79 Inappropriate file type or format
else
# Discern accessibility of symlink target
is-accessible.bash -- "$path" || exit $?
is-accessible.bash -- "$path" || exit
# Target was accessible but did not exist, thus it is a broken symlink, which is what we want
continue
fi
Expand All @@ -30,7 +30,7 @@ while [[ $# -ne 0 ]]; do
exit 17 # EEXIST 17 File exists
else
# Discern accessibility or non-existence
is-accessible.bash -- "$path" || exit $?
is-accessible.bash -- "$path" || exit
exit 2 # ENOENT 2 No such file or directory
fi
done
Expand Down
2 changes: 1 addition & 1 deletion commands/is-directory.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ while [[ $# -ne 0 ]]; do
exit 20 # NOTDIR 20 Not a directory
else
# discern if inaccessible, broken, missing
is-accessible.bash -- "$path" || exit $?
is-accessible.bash -- "$path" || exit
if [[ -L $path ]]; then
# broken symlink
exit 9 # EBADF 9 Bad file descriptor
Expand Down
2 changes: 1 addition & 1 deletion commands/is-empty-directory.bash
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ while [[ $# -ne 0 ]]; do
exit 20 # ENOTDIR 20 Not a directory
else
# discern if inaccessible, broken, missing
is-accessible.bash -- "$path" || exit $?
is-accessible.bash -- "$path" || exit
if [[ -L $path ]]; then
# broken symlink
exit 9 # EBADF 9 Bad file descriptor
Expand Down
2 changes: 1 addition & 1 deletion commands/is-empty-file.bash
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ while [[ $# -ne 0 ]]; do
exit 79 # EFTYPE 79 Inappropriate file type or format
else
# discern if inaccessible, broken, missing
is-accessible.bash -- "$path" || exit $?
is-accessible.bash -- "$path" || exit
if [[ -L $path ]]; then
# broken symlink
exit 9 # EBADF 9 Bad file descriptor
Expand Down
4 changes: 2 additions & 2 deletions commands/is-executable.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ while [[ $# -ne 0 ]]; do
elif [[ -e $path ]]; then
# does exist: is not executable
# discern if unable to detect executable status because it was inaccessible
is-accessible.bash -- "$path" || exit $?
is-accessible.bash -- "$path" || exit
exit 93 # ENOATTR 93 Attribute not found
else
# discern if inaccessible, broken, missing
is-accessible.bash -- "$path" || exit $?
is-accessible.bash -- "$path" || exit
if [[ -L $path ]]; then
# broken symlink
exit 9 # EBADF 9 Bad file descriptor
Expand Down
2 changes: 1 addition & 1 deletion commands/is-file.bash
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ while [[ $# -ne 0 ]]; do
exit 79 # EFTYPE 79 Inappropriate file type or format
else
# discern if inaccessible, broken, missing
is-accessible.bash -- "$path" || exit $?
is-accessible.bash -- "$path" || exit
if [[ -L $path ]]; then
# broken symlink
exit 9 # EBADF 9 Bad file descriptor
Expand Down
2 changes: 1 addition & 1 deletion commands/is-missing.bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ while [[ $# -ne 0 ]]; do
exit 17 # EEXIST 17 File exists
else
# discern if inaccessible, missing
is-accessible.bash -- "$path" || exit $?
is-accessible.bash -- "$path" || exit
continue # missing, which is what we want
fi
done
Expand Down
2 changes: 1 addition & 1 deletion commands/is-nonempty-file.bash
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ while [[ $# -ne 0 ]]; do
exit 79 # EFTYPE 79 Inappropriate file type or format
else
# discern if inaccessible, broken, missing
is-accessible.bash -- "$path" || exit $?
is-accessible.bash -- "$path" || exit
if [[ -L $path ]]; then
# broken symlink
exit 9 # EBADF 9 Bad file descriptor
Expand Down
2 changes: 1 addition & 1 deletion commands/is-not-directory.bash
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ while [[ $# -ne 0 ]]; do
continue
else
# discern if inaccessible, broken, missing
is-accessible.bash -- "$path" || exit $?
is-accessible.bash -- "$path" || exit
if [[ -L $path ]]; then
# broken symlink
exit 9 # EBADF 9 Bad file descriptor
Expand Down
2 changes: 1 addition & 1 deletion commands/is-not-symlink.bash
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ while [[ $# -ne 0 ]]; do
continue
else
# discern if inaccessible, missing
is-accessible.bash -- "$path" || exit $?
is-accessible.bash -- "$path" || exit
exit 2 # ENOENT 2 No such file or directory
fi
done
Expand Down
2 changes: 1 addition & 1 deletion commands/is-owner
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function is_owner() (
shift
fi
for input in "$@"; do
is-present.bash -- "$input" || return $?
is-present.bash -- "$input" || return
__get_owner "$input"
if [[ ${#option_user_ids[@]} -ne 0 ]]; then
for item in "${option_user_ids[@]}"; do
Expand Down
2 changes: 1 addition & 1 deletion commands/is-present.bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ while [[ $# -ne 0 ]]; do
continue
else
# discern if inaccessible, missing
is-accessible.bash -- "$path" || exit $?
is-accessible.bash -- "$path" || exit
exit 2 # ENOENT 2 No such file or directory
fi
done
Expand Down
2 changes: 1 addition & 1 deletion commands/is-readable.bash
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ while [[ $# -ne 0 ]]; do
exit 93 # ENOATTR 93 Attribute not found
else
# discern if inaccessible, broken, missing
is-accessible.bash -- "$path" || exit $?
is-accessible.bash -- "$path" || exit
if [[ -L $path ]]; then
# broken symlink
exit 9 # EBADF 9 Bad file descriptor
Expand Down
2 changes: 1 addition & 1 deletion commands/is-writable.bash
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ while [[ $# -ne 0 ]]; do
exit 93 # ENOATTR 93 Attribute not found
else
# discern if inaccessible, broken, missing
is-accessible.bash -- "$path" || exit $?
is-accessible.bash -- "$path" || exit
if [[ -L $path ]]; then
# broken symlink
exit 9 # EBADF 9 Bad file descriptor
Expand Down
10 changes: 5 additions & 5 deletions sources/bash.bash
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ if [[ -z ${BASH_VERSION_CURRENT-} ]]; then
function __require_upgraded_bash {
echo-style \
--code="$0" ' ' --error='is incompatible with' ' ' --code="bash $BASH_VERSION" $'\n' \
'Run ' --code='setup-util-bash' ' to upgrade capabilities, then run the prior command again.' >/dev/stderr || return $?
'Run ' --code='setup-util-bash' ' to upgrade capabilities, then run the prior command again.' >/dev/stderr || return
return 45 # ENOTSUP 45 Operation not supported
}
fi
Expand Down Expand Up @@ -401,7 +401,7 @@ if shopt -s lastpipe 2>/dev/null; then
}
else
function __require_lastpipe {
echo-style --error='Missing lastpipe support:' >/dev/stderr || return $?
echo-style --error='Missing lastpipe support:' >/dev/stderr || return
__require_upgraded_bash
}
fi
Expand Down Expand Up @@ -668,7 +668,7 @@ if shopt -s globstar 2>/dev/null; then
}
else
function __require_globstar {
echo-style --error='Missing globstar support:' >/dev/stderr || return $?
echo-style --error='Missing globstar support:' >/dev/stderr || return
__require_upgraded_bash
}
fi
Expand All @@ -680,7 +680,7 @@ if shopt -s extglob 2>/dev/null; then
}
else
function __require_extglob {
echo-style --error='Missing extglob support:' >/dev/stderr || return $?
echo-style --error='Missing extglob support:' >/dev/stderr || return
__require_upgraded_bash
}
fi
Expand Down Expand Up @@ -833,7 +833,7 @@ function __has_array_capability {

function __require_array {
if ! __has_array_capability "$@"; then
echo-style --error='Array support insufficient, required:' ' ' --code="$*" >/dev/stderr || return $?
echo-style --error='Array support insufficient, required:' ' ' --code="$*" >/dev/stderr || return
__require_upgraded_bash
fi
}
Expand Down

0 comments on commit d259793

Please sign in to comment.