Skip to content

Commit

Permalink
fs-trim: still failing, try alternative to eval-on-empty-stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Nov 29, 2024
1 parent 6ffa78c commit 3db5aba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
2 changes: 2 additions & 0 deletions commands/fs-structure
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ function fs_structure_test() (
source "$DOROTHY/sources/bash.bash"
echo-style --h1="TEST: $0"

set -x
fs-structure
fs-structure --no-eza

Expand All @@ -12,6 +13,7 @@ function fs_structure_test() (

fs-structure -- "$DOROTHY"
fs-structure --no-eza -- "$DOROTHY"
set +x

echo-style --g1="TEST: $0"
return 0
Expand Down
41 changes: 24 additions & 17 deletions commands/fs-trim
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ function fs_trim() (
done

# check
set -x
if [[ ${#option_inputs[@]} -eq 0 ]]; then
# help 'No <path>s provided.'
option_inputs+=('.')
Expand Down Expand Up @@ -259,31 +260,37 @@ function fs_trim() (
sudo-helper --inherit --sudo="$option_sudo" --user="$option_user" --group="$option_group" -- "$@"
return
}
function __fail_on_empty {
__wrap "$@" | eval-on-empty-stdin -- false
return
}
function do_find {
local path="$1" refresh='yes'
while [[ $refresh == 'yes' ]]; do
refresh='no'
local path="$1" modifications
modifications="$(fs-temp --directory='fs-trim' --file)"
while :; do
if is-not-directory --sudo="$option_sudo" --user="$option_user" --group="$option_group" -- "$path"; then
break
fi
if [[ $option_cache == 'yes' ]] && __fail_on_empty find "$path" \( "${cache_find[@]}" \) -delete -print; then
refresh='yes'
: >"$modifications" # clear
if [[ $option_cache == 'yes' ]]; then
__wrap find "$path" \( "${cache_find[@]}" \) -delete -print >>"$modifications"
fi
if [[ $option_module == 'yes' ]]; then
__wrap find "$path" \( "${module_find[@]}" \) -delete -print >>"$modifications"
fi
if [[ $option_module == 'yes' ]] && __fail_on_empty find "$path" \( "${module_find[@]}" \) -delete -print; then
refresh='yes'
if [[ $option_empty_files == 'yes' ]]; then
__wrap find "$path" -type f -empty -delete -print >>"$modifications"
fi
if [[ $option_empty_files == 'yes' ]] && __fail_on_empty find "$path" -type f -empty -delete -print; then
refresh='yes'
if [[ $option_broken_symlinks == 'yes' ]]; then
__wrap find "$path" -type l -exec fs-trim-symlinks.bash -- {} + >>"$modifications"
fi
if [[ $option_broken_symlinks == 'yes' ]] && __fail_on_empty find "$path" -type l -exec fs-trim-symlinks.bash -- {} +; then
refresh='yes'
if [[ $option_empty_directories == 'yes' ]]; then
__wrap find "$path" -type d -empty -delete -print >>"$modifications"
fi
if [[ $option_empty_directories == 'yes' ]] && __fail_on_empty find "$path" -type d -empty -delete -print; then
refresh='yes'
if [[ ! -s $modifications ]]; then
# nothing was trimmed, modifications is empty
break
else
{
echo-style --notice1='The following items were trimmed from ' --code-notice1="$path"
echo-file -- "$modifications"
} >/dev/stderr
fi
done
}
Expand Down

0 comments on commit 3db5aba

Please sign in to comment.