Skip to content
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

Use $XDG_CACHE_HOME, keep cache files in $HOME/.cache/distrobox by default #1082

Merged
merged 2 commits into from
Feb 1, 2024
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
12 changes: 7 additions & 5 deletions distrobox-create
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ distrobox_hostexec_path="$(cd "$(dirname "${0}")" && pwd)/distrobox-host-exec"
verbose=0
version="1.6.0.1"

app_cache_dir=${XDG_CACHE_HOME:-"${HOME}/.cache"}/distrobox

# Source configuration files, this is done in an hierarchy so local files have
# priority over system defaults
# leave priority to environment variables.
Expand Down Expand Up @@ -209,9 +211,9 @@ EOF
# Outputs:
# print usage with examples.
show_compatibility() {
if [ ! -e "${HOME}/.cache/distrobox-compatibility-${version}" ] ||
[ ! -s "${HOME}/.cache/distrobox-compatibility-${version}" ]; then
mkdir -p "${HOME}/.cache"
if [ ! -e "${app_cache_dir}/distrobox-compatibility-${version}" ] ||
[ ! -s "${app_cache_dir}/distrobox-compatibility-${version}" ]; then
mkdir -p "${app_cache_dir}"

# If we don't have a cache file, we need connectivity. Ensure we have
# one and return error if not.
Expand All @@ -227,9 +229,9 @@ show_compatibility() {
cut -d '|' -f 4 |
sed 's|<br>|\n|g' |
tr -d ' ' |
sort -u > "${HOME}/.cache/distrobox-compatibility-${version}"
sort -u > "${app_cache_dir}/distrobox-compatibility-${version}"
fi
cat "${HOME}/.cache/distrobox-compatibility-${version}"
cat "${app_cache_dir}/distrobox-compatibility-${version}"
}

# Parse arguments
Expand Down
16 changes: 9 additions & 7 deletions distrobox-enter
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
# DBX_SKIP_WORKDIR
# DBX_SUDO_PROGRAM

app_cache_dir=${XDG_CACHE_HOME:-"${HOME}/.cache"}/distrobox

trap cleanup TERM INT HUP EXIT

cleanup() {
rm -f "${HOME}/.cache/.${container_name}.fifo"
rm -f "${app_cache_dir}/.${container_name}.fifo"
if [ -n "${logs_pid:-}" ]; then
kill "${logs_pid:-}" 2> /dev/null || :
fi
Expand Down Expand Up @@ -527,14 +529,14 @@ if [ "${container_status}" != "running" ]; then
fi

printf >&2 "%-40s\t" "Starting container..."
mkdir -p "${HOME}/.cache/"
rm -f "${HOME}/.cache/.${container_name}.fifo"
mkfifo "${HOME}/.cache/.${container_name}.fifo"
mkdir -p "${app_cache_dir}"
rm -f "${app_cache_dir}/.${container_name}.fifo"
mkfifo "${app_cache_dir}/.${container_name}.fifo"
while true; do
# save starting loop timestamp in temp variable, we'll use it
# after to let logs command minimize possible holes
${container_manager} logs -f "${container_name}" 2> /dev/null \
> "${HOME}/.cache/.${container_name}.fifo" &
> "${app_cache_dir}/.${container_name}.fifo" &
logs_pid="$!"

# read logs from log_timestamp to now, line by line
Expand All @@ -559,10 +561,10 @@ if [ "${container_status}" != "running" ]; then
;;
*) ;;
esac
done < "${HOME}/.cache/.${container_name}.fifo"
done < "${app_cache_dir}/.${container_name}.fifo"
done
# cleanup fifo
rm -f "${HOME}/.cache/.${container_name}.fifo"
rm -f "${app_cache_dir}/.${container_name}.fifo"
printf >&2 "\nContainer Setup Complete!\n"
fi

Expand Down