Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ On Windows, a flag marked "Unix" prints a warning. The run goes on without it, e
| `-ni`, `--no-info` | Hide the system line | all |
| `-w`, `--weather` | Show a weather line from wttr.in | all |
| `--ascii` | ASCII glyphs only | all |
| `-nc`, `--keep-cache` | Skip user cache cleaning (Windows: `%TEMP%`) | all |
| `-nc`, `--keep-cache` | Skip user cache cleaning (Windows: `%TEMP%`) and, on Linux, the warning about space still held by deleted files that a program keeps open | all |
| `-nt`, `--keep-trash` | Skip trash cleaning (Windows: Recycle Bin) | all |
| `--deep-clean` | Also clean the journal, old kernels, leftover configs, snap revisions, container images, crash dumps, npm and Go caches, asking for each | Unix |
| `--deep-clean` | Also clean the journal, old kernels, leftover configs, snap revisions, crash dumps, npm and Go caches and unused docker and podman data, asking for each | Unix |
| `--changed` | Show the last run's package changes | Unix |
| `--changelog PKG` | Show the upstream changelog of `PKG` | Unix |
| `--history` | Show the last runs | all |
Expand Down
6 changes: 3 additions & 3 deletions completions/_up
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ _up() {
'--no-logo[no logo]'
'-ni[no system info]'
'--no-info[no system info]'
'-nc[no cache clean]'
'--keep-cache[no cache clean]'
'-nc[skip cache cleaning and the deleted-but-open files warning]'
'--keep-cache[skip cache cleaning and the deleted-but-open files warning]'
'-nt[no trash clean]'
'--keep-trash[no trash clean]'
'--deep-clean[clean journal, old kernels, containers, crash dumps]'
'--deep-clean[clean journal, old kernels, containers]'
'-w[weather]'
'--weather[weather]'
'--changed[show package diff]'
Expand Down
4 changes: 2 additions & 2 deletions completions/up.fish
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ complete -c up -l parallel -d 'parallel user-space'
complete -c up -l ascii -d 'ASCII glyphs only'
complete -c up -o nl -l no-logo -d 'hide logo'
complete -c up -o ni -l no-info -d 'hide system info'
complete -c up -o nc -l keep-cache -d 'skip cache cleaning'
complete -c up -o nc -l keep-cache -d 'skip cache cleaning and the deleted-but-open files warning'
complete -c up -o nt -l keep-trash -d 'skip trash cleaning'
complete -c up -l json -d 'JSON summary on stdout'
complete -c up -l only -d 'only these managers' -xa 'pacman yay paru apt dnf yum zypper xbps apk eopkg emerge nix softwareupdate brew mas fwupd rpi-eeprom flatpak snap rustup cargo npm pnpm pip gem'
Expand All @@ -42,7 +42,7 @@ complete -c up -l rollback -d 'revert last snapshot'
complete -c up -l reboot-exit -d 'exit 4 if reboot required'
complete -c up -l download-only -d 'download, do not install'
complete -c up -l metrics -d 'export Prometheus textfile' -r
complete -c up -l deep-clean -d 'journal, old kernels, containers, crash dumps'
complete -c up -l deep-clean -d 'journal, old kernels, containers'
complete -c up -l profile -d 'load profile' -xa '(__up_profiles)'
complete -c up -l list-profiles -d 'list profiles'
complete -c up -l snapshot -d 'pre-update snapshot'
Expand Down
Binary file modified doc/documentation.pdf
Binary file not shown.
40 changes: 34 additions & 6 deletions doc/documentation.tex
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@ \section{Execution flow}\label{sec:flow}
user-space ones when \texttt{-{}-parallel} is active.
\item Optionally clear user cache and trash (skippable with
\texttt{-nc} and \texttt{-nt}), then, with
\texttt{-{}-deep-clean}, the system leftovers (Unix).
\texttt{-{}-deep-clean}, the system leftovers and the container
data (Unix).
\item Execute \texttt{post.d} hooks.
\item Snapshot the installed-packages list into \texttt{pkgs.after} and
compute \texttt{pkgs.diff}.
Expand Down Expand Up @@ -519,7 +520,7 @@ \subsection{All flags}
\texttt{-{}-deep-clean} & System leftovers (see \S\ref{sec:deepclean}) & Linux/macOS \\
\texttt{-nl}, \texttt{-{}-no-logo} & Hide logo & all \\
\texttt{-ni}, \texttt{-{}-no-info} & Hide system info line & all \\
\texttt{-nc}, \texttt{-{}-keep-cache} & Skip user cache cleaning & all \\
\texttt{-nc}, \texttt{-{}-keep-cache} & Skip user cache cleaning and the warning about space held by deleted files still open & all \\
\texttt{-nt}, \texttt{-{}-keep-trash} & Skip trash cleaning & all \\
\texttt{-{}-security} & Security-only updates & supported managers \\
\texttt{-{}-firmware} & Include \texttt{fwupdmgr} & Linux \\
Expand Down Expand Up @@ -725,6 +726,12 @@ \subsection{Cache cleaning}
own cache is always kept; \verb|CACHE_EXCLUDE="mozilla,pip*"| keeps more.
With \texttt{-y} everything not excluded is cleaned.

On Linux the step then reports the deleted files a running process
still keeps open on the filesystems of \texttt{/} and
\verb|$HOME|, when they hold 1M or more: the five biggest holders, by
command. That space comes back only when the holder closes the files or
exits, so nothing is deleted; restart the program named.

\subsection{Deep clean}\label{sec:deepclean}
\texttt{up -{}-deep-clean} goes after system-level leftovers a normal run
doesn't touch, asking about each one and showing how much it would free.
Expand All @@ -738,13 +745,31 @@ \subsection{Deep clean}\label{sec:deepclean}
\texttt{kernels} & dnf: keep the 2 newest kernels; zypper: \texttt{purge-kernels} \\
\texttt{residual} & \texttt{dpkg -{}-purge} config files of removed packages \\
\texttt{snap} & remove disabled snap revisions \\
\texttt{docker}, \texttt{podman} & \texttt{image prune -f} + \texttt{builder prune -f}
(dangling images and build cache only) \\
\texttt{coredumps} & delete \verb|/var/lib/systemd/coredump| files \\
\texttt{npm}, \texttt{go} & \texttt{npm cache clean -{}-force}, \texttt{go clean -cache} \\
\bottomrule
\end{longtable}

Two more sections follow, with the same prompts and skip keys.

\begin{longtable}{@{}p{0.22\linewidth} p{0.70\linewidth}@{}}
\toprule
\textbf{Key} & \textbf{Task} \\
\midrule \endhead
\texttt{docker}, \texttt{podman} & Containers section, per local docker
context (\texttt{unix://}; remote ones are skipped): \texttt{container prune -f}, \texttt{image prune -af},
\texttt{builder prune -af} (docker only) and \texttt{volume prune}
(\texttt{-af} on docker), each with its reclaimable size, a kind at
0B not offered, sizes read again after the container prune. Stopped
containers (toolbox, distrobox) and volumes hold data: never pruned
under \texttt{-y}. Only the Linux system docker daemon is tried
through \texttt{sudo}. Docker Desktop's data
(\verb|~/.docker/desktop|, on macOS
\verb|~/Library/Containers/com.docker.docker|) is shown from 1M,
since its disk image shrinks only from Docker Desktop \\
\bottomrule
\end{longtable}

Respects \texttt{-n}; space freed on \texttt{/} goes into the summary.

\subsection{Parallel mode}
Expand Down Expand Up @@ -1483,8 +1508,9 @@ \section{Security model}\label{sec:security}
the \texttt{-{}-metrics} file, and deletions inside
\verb|~/.cache| and the Trash when cleaning.
\texttt{-{}-deep-clean} also deletes journal entries, old kernels,
leftover configs, snap revisions, container images and crash dumps
(\verb|/var/lib/systemd/coredump|), after asking for each.
leftover configs, snap revisions, crash dumps
(\verb|/var/lib/systemd/coredump|), unused containers, images,
build cache and volumes, after asking for each.
\item On Windows, UAC elevation happens only for the managers that need
admin. They run in an elevated child that loads no config, profile
or hook. That child runs the code of the checkout: clone it into a
Expand Down Expand Up @@ -1812,8 +1838,10 @@ \subsection{Bash library modules (\texttt{src/lib/})}
\texttt{state/lock.sh} & Global \texttt{flock}, \texttt{mkdir} fallback \\
\texttt{clean/size.sh} & Size of a path, short size format \\
\texttt{clean/cache.sh} & Selective \texttt{\textasciitilde{}/.cache} menu \\
\texttt{clean/open.sh} & Report of deleted files still open \\
\texttt{clean/trash.sh} & Trash \\
\texttt{clean/deep.sh} & \texttt{-{}-deep-clean} tasks \\
\texttt{clean/containers.sh} & \texttt{-{}-deep-clean} Containers section \\
\bottomrule
\end{longtable}
\end{center}
Expand Down
11 changes: 7 additions & 4 deletions man/up.1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ the Windows build are in the eMerger manual, \fIdoc/documentation.pdf\fR.
eMerger detects the package managers installed on the host and runs each of
them in turn to refresh, upgrade and clean the system, then prints a summary.
It can also clean the user cache, the trash and, with \fB\-\-deep\-clean\fR,
system leftovers. Every cleaning step asks first unless \fB\-y\fR is given.
system leftovers and unused container data. Every cleaning step asks first unless \fB\-y\fR is given.
.PP
Short flags from the set \fBh V n v q y w\fR can be bundled: \fB\-nv\fR is
\fB\-n \-v\fR. Other short flags (\fB\-nl\fR, \fB\-qq\fR, \fB\-up\fR and so on)
Expand Down Expand Up @@ -132,16 +132,19 @@ ASCII glyphs only. The spinner becomes the ".:" pulse.
.SH CLEANING
.TP
.B \-nc, \-\-keep\-cache
Skip user cache cleaning.
Skip user cache cleaning and the warning about space held by deleted files still open.
.TP
.B \-nt, \-\-keep\-trash
Skip trash cleaning.
.TP
.B \-\-deep\-clean
Also clean system leftovers, asking for each: journal above
\fBJOURNAL_MAX_SIZE\fR, old kernels (dnf, zypper), config files of removed
packages, disabled snap revisions, dangling docker/podman images and build
cache, crash dumps, npm and Go caches.
packages, disabled snap revisions, crash dumps, npm and Go caches. Then the
Containers section: stopped containers, unused images, build cache and
unused volumes of every local docker context (remote ones skipped) and of
podman (stopped containers and volumes never under \fB\-y\fR), and the size
of Docker Desktop's data.
.SH INSPECTION
.TP
.B \-\-changed
Expand Down
4 changes: 2 additions & 2 deletions src/emerger.sh
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ main() {
run_parallel "$((step+1))" "$total" "${parallel[@]}"
fi

(( ARG_KEEP_CACHE )) || clean_cache
if (( ! ARG_KEEP_CACHE )); then clean_cache; clean_open_deleted; fi
(( ARG_KEEP_TRASH )) || clean_trash
if (( ARG_DEEP_CLEAN )); then clean_deep; fi
if (( ARG_DEEP_CLEAN )); then clean_deep; clean_containers; fi

hooks_run post

Expand Down
164 changes: 164 additions & 0 deletions src/lib/clean/containers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#!/usr/bin/env bash
# --deep-clean, Containers section: what docker (every local context) and
# podman keep without using it. Every task asks first unless -y. Stopped
# containers (toolbox, distrobox) and unused volumes hold data: never offered
# under -y. Remote contexts (ssh://, tcp://) are left alone.

# Offer to prune stopped containers, unused images, build cache and unused
# volumes of every local docker context and of podman, then add the
# growth of free space on / to SUMMARY_FREED_KB. Silent when neither tool is
# installed or DEEP_CLEAN_SKIP lists both.
clean_containers() {
local -a engines=()
local bin context endpoint free_before
for bin in docker podman; do
if sys_has "$bin" && ! _deep_is_skipped "$bin"; then engines+=("$bin"); fi
done
(( ${#engines[@]} > 0 )) || return 0
ui_title "Containers"
_DEEP_TASK_COUNT=0
free_before=$(sys_free_space k /)

for bin in "${engines[@]}"; do
if [[ $bin == docker ]]; then
# On fd 3: a probe or prune reading stdin cannot eat the list.
while IFS='|' read -r context endpoint <&3; do
if [[ -n $endpoint && $endpoint != unix://* && $endpoint != npipe://* ]]; then
ui_muted "docker ($context): remote engine at $endpoint, skipped"
else
_containers_target docker "$context"
fi
done 3< <(_containers_docker_contexts)
_containers_desktop_note
else
_containers_target "$bin" ""
fi
done

if (( _DEEP_TASK_COUNT == 0 )); then
ui_ok "nothing to clean"
return 0
fi
_deep_report_freed "$free_before"
return 0
}

# Print the docker contexts as name|endpoint, one per line, or one empty line
# when docker lists none (an engine older than contexts, or a failing call).
_containers_docker_contexts() {
local list
list=$(docker context ls --format '{{.Name}}|{{.DockerEndpoint}}' 2>/dev/null || true)
if [[ -z $list ]]; then
printf '\n'
else
printf '%s\n' "$list"
fi
}

# Print the command line reaching engine $1 through docker context $2 (none
# when empty), one word per line: plain if the daemon answers, else sudo
# (probed with sudo -n, never under --dry-run, where sudo is assumed). Only
# the Linux system docker daemon (no context or "default") is tried through
# sudo: other contexts are user sockets, and root's podman has its own
# storage. Empty when the daemon is not reachable.
_containers_cmd() {
local -a base=("$1")
[[ -n $2 ]] && base+=(--context "$2")
if "${base[@]}" info >/dev/null 2>&1; then
printf '%s\n' "${base[@]}"
elif sys_is_root || [[ $1 != docker || ( -n $2 && $2 != default ) ]] || sys_is_macos; then
return 0
elif (( DRY_RUN )) || sudo -n "${base[@]}" info >/dev/null 2>&1; then
printf '%s\n' sudo "${base[@]}"
fi
return 0
}

# Set _containers_target's free_images, free_containers, free_volumes and
# free_build to the reclaimable sizes `system df` reports through command
# $@ ("4.978GB"), empty for a kind it does not list.
_containers_reclaimable() {
local type value
free_images="" free_containers="" free_volumes="" free_build=""
while IFS='|' read -r type value; do
value=${value%% (*}
case "$type" in
Images) free_images=$value ;;
Containers) free_containers=$value ;;
'Local Volumes') free_volumes=$value ;;
'Build Cache') free_build=$value ;;
esac
done < <("$@" system df --format '{{.Type}}|{{.Reclaimable}}' 2>/dev/null || true)
return 0
}

# Offer the prune tasks of engine $1 through docker context $2 (empty for
# podman or an engine without contexts), each with its reclaimable size.
# A kind reclaiming 0B is not offered.
_containers_target() {
local bin="$1" context="$2" name="$1"
[[ -n $context && $context != default ]] && name="$bin ($context)"
local -a command=()
mapfile -t command < <(_containers_cmd "$bin" "$context")
if (( ${#command[@]} == 0 )); then
if [[ -n $context && $context != default ]]; then
ui_muted "$name: daemon not running, skipped"
elif [[ $bin == docker ]]; then
ui_muted "$name: daemon not reachable (not in the docker group?), skipped"
else
ui_muted "$name: not reachable, skipped"
fi
return 0
fi

local free_images="" free_containers="" free_volumes="" free_build="" read_sizes=1
# Under --dry-run a sudo command line is not run, not even to read.
[[ ${command[0]} == sudo ]] && (( DRY_RUN )) && read_sizes=0
(( read_sizes )) && _containers_reclaimable "${command[@]}"
_containers_offer "$bin" "Remove stopped $name containers (their files are lost)" "$free_containers" \
"$name stopped containers kept under -y: they hold files" "${command[@]}" container prune -f
# Pruned containers free their images and volumes: read the sizes again.
if (( read_sizes && ! ARG_YES )) && [[ $free_containers != 0B ]]; then
_containers_reclaimable "${command[@]}"
fi
_containers_offer "$bin" "Remove unused $name images" "$free_images" "" \
"${command[@]}" image prune -af
if [[ $bin == docker ]]; then
_containers_offer "$bin" "Clear $name build cache" "$free_build" "" \
"${command[@]}" builder prune -af
fi
# podman volume prune has no -a: it always removes every unused volume.
local -a volume_args=(volume prune -f)
[[ $bin == docker ]] && volume_args=(volume prune -af)
_containers_offer "$bin" "Remove unused $name volumes (their data is lost)" "$free_volumes" \
"$name unused volumes kept under -y: they hold data" "${command[@]}" "${volume_args[@]}"
return 0
}

# Offer task $2 of DEEP_CLEAN_SKIP key $1 running command $5... with
# reclaimable size $3 in its detail ("?" when unknown). Nothing when $3 is
# 0B. A non-empty $4 makes the task ask even under -y: there it prints $4.
_containers_offer() {
local key="$1" label="$2" free="$3" kept="$4"; shift 4
[[ $free == 0B ]] && return 0
if [[ -n $kept ]]; then
_deep_task_asked "$key" "$label" "(reclaimable: ${free:-?})" "$kept" "$@"
else
_deep_task "$key" "$label" "(reclaimable: ${free:-?})" "$@"
fi
}

# Report the size of Docker Desktop's data (~/.docker/desktop on Linux,
# ~/Library/Containers/com.docker.docker on macOS) when it holds 1M or more:
# its disk image does not shrink when the engine prunes, only from Docker
# Desktop.
_containers_desktop_note() {
local dir kb
for dir in "$HOME/.docker/desktop" "$HOME/Library/Containers/com.docker.docker"; do
[[ -d $dir ]] || continue
kb=$(_clean_size_kb "$dir")
(( kb >= 1024 )) || continue
ui_muted "Docker Desktop keeps $(_clean_format_kb "$kb") in $dir: shrink it from Docker Desktop (Troubleshoot, Clean / Purge data)"
done
return 0
}
Loading
Loading