这是indexloc提供的服务,不要输入任何密码
Skip to content

Optimize xpns_normalize_directory and xpns_is_valid_directory #184

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

Merged
merged 3 commits into from
Apr 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions bin/xpanes
Original file line number Diff line number Diff line change
Expand Up @@ -511,34 +511,31 @@ xpns_log_filenames() {
# Return:
# Normalized <dirname>
## --------------------------------

xpns_normalize_directory() {
local _dir="$1"
# Remove end of slash '/'
_dir="${_dir%/}"
# Remove end of slash '/' for the first arguement
local _dir="${1%/}"
# tilde expansion
_dir="${_dir/#~/${HOME}}"
printf "%s\\n" "${_dir}"
printf "%s\\n" "${_dir/#~/$HOME}"
}

## --------------------------------
# Ensure existence of given directory
# Usage:
# xpns_is_valid_directory <direname>
# xpns_is_valid_directory <dirname>
# Return:
# Absolute path of the <dirname>
## --------------------------------
xpns_is_valid_directory() {
local _dir="$1"
local _checkfile="${XP_THIS_FILE_NAME}.$$"
# Check directory.
if [[ ! -d "${_dir}" ]]; then
if ! [[ -d "${_dir}" ]]; then
# Create directory
if mkdir "${_dir}"; then
xpns_msg_info "${_dir} is created."
else
if ! mkdir "${_dir}"; then
xpns_msg_error "Failed to create ${_dir}"
exit ${XP_ELOGDIR}
fi
xpns_msg_info "${_dir} is created."
fi
# Try to create file.
# Not only checking directory permission,
Expand Down