mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2025-12-07 16:00:41 +01:00
fix(perms)!: change function name from fixperms to resetperms and document caution (#10686)
BREAKING CHANGE: function `fixperms` has been renamed to the more accurate `resetperms`. Please read the README carefully before using it as it may badly reset the permissions. Fixes #10648 Closes #10686
This commit is contained in:
committed by
Marc Cornellà
parent
a04cf07880
commit
62929263fa
@@ -6,25 +6,25 @@
|
||||
### Aliases
|
||||
|
||||
# Set all files' permissions to 644 recursively in a directory
|
||||
set644() {
|
||||
function set644 {
|
||||
find "${@:-.}" -type f ! -perm 644 -print0 | xargs -0 chmod 644
|
||||
}
|
||||
|
||||
# Set all directories' permissions to 755 recursively in a directory
|
||||
set755() {
|
||||
function set755 {
|
||||
find "${@:-.}" -type d ! -perm 755 -print0 | xargs -0 chmod 755
|
||||
}
|
||||
|
||||
### Functions
|
||||
|
||||
# fixperms - fix permissions on files and directories, with confirmation
|
||||
# resetperms - fix permissions on files and directories, with confirmation
|
||||
# Returns 0 on success, nonzero if any errors occurred
|
||||
fixperms () {
|
||||
function resetperms {
|
||||
local opts confirm target exit_status chmod_opts use_slow_mode
|
||||
zparseopts -E -D -a opts -help -slow v+=chmod_opts
|
||||
if [[ $# > 1 || -n "${opts[(r)--help]}" ]]; then
|
||||
cat <<EOF
|
||||
Usage: fixperms [-v] [--help] [--slow] [target]
|
||||
Usage: resetperms [-v] [--help] [--slow] [target]
|
||||
|
||||
target is the file or directory to change permissions on. If omitted,
|
||||
the current directory is taken to be the target.
|
||||
@@ -40,7 +40,7 @@ EOF
|
||||
return $exit_status
|
||||
fi
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
if [[ $# -eq 0 ]]; then
|
||||
target="."
|
||||
else
|
||||
target="$1"
|
||||
@@ -49,7 +49,7 @@ EOF
|
||||
|
||||
# Because this requires confirmation, bail in noninteractive shells
|
||||
if [[ ! -o interactive ]]; then
|
||||
echo "fixperms: cannot run in noninteractive shell"
|
||||
echo "resetperms: cannot run in noninteractive shell"
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -68,15 +68,20 @@ EOF
|
||||
if [[ $use_slow == true ]]; then
|
||||
# Process directories first so non-traversable ones are fixed as we go
|
||||
find "$target" -type d ! -perm 755 -exec chmod $chmod_opts 755 {} \;
|
||||
if [[ $? != 0 ]]; then exit_status=$?; fi
|
||||
if [[ $? -ne 0 ]]; then exit_status=$?; fi
|
||||
find "$target" -type f ! -perm 644 -exec chmod $chmod_opts 644 {} \;
|
||||
if [[ $? != 0 ]]; then exit_status=$?; fi
|
||||
if [[ $? -ne 0 ]]; then exit_status=$?; fi
|
||||
else
|
||||
find "$target" -type d ! -perm 755 -print0 | xargs -0 chmod $chmod_opts 755
|
||||
if [[ $? != 0 ]]; then exit_status=$?; fi
|
||||
if [[ $? -ne 0 ]]; then exit_status=$?; fi
|
||||
find "$target" -type f ! -perm 644 -print0 | xargs -0 chmod $chmod_opts 644
|
||||
if [[ $? != 0 ]]; then exit_status=$?; fi
|
||||
if [[ $? -ne 0 ]]; then exit_status=$?; fi
|
||||
fi
|
||||
echo "Complete"
|
||||
return $exit_status
|
||||
}
|
||||
|
||||
function fixperms {
|
||||
print -ru2 "fixperms has been deprecated. Use resetperms instead"
|
||||
return 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user