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

🧹 fix+refact(system-cleanup) #856

Merged
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
23 changes: 16 additions & 7 deletions core/tabs/system-setup/system-cleanup.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,21 @@ cleanup_system() {
"$ESCALATION_TOOL" "$PACKAGER" -Rns $(pacman -Qtdq) --noconfirm > /dev/null 2>&1
;;
*)
printf "%b\n" "${RED}Unsupported package manager: ""$PACKAGER""${RC}"
return 1
printf "%b\n" "${RED}Unsupported package manager: ${PACKAGER}. Skipping.${RC}"
;;
esac
}

common_cleanup() {
"$ESCALATION_TOOL" find /var/tmp -type f -atime +5 -delete
"$ESCALATION_TOOL" find /tmp -type f -atime +5 -delete
"$ESCALATION_TOOL" find /var/log -type f -name "*.log" -exec truncate -s 0 {} \;
if [ -d /var/tmp ]; then
"$ESCALATION_TOOL" find /var/tmp -type f -atime +5 -delete
fi
if [ -d /tmp ]; then
"$ESCALATION_TOOL" find /tmp -type f -atime +5 -delete
fi
if [ -d /var/log ]; then
"$ESCALATION_TOOL" find /var/log -type f -name "*.log" -exec truncate -s 0 {} \;
fi
Comment on lines +35 to +43
Copy link
Contributor

@jeevithakannan2 jeevithakannan2 Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do something like this ? This will not return non zero if the dir is not found

Suggested change
if [ -d /var/tmp ]; then
"$ESCALATION_TOOL" find /var/tmp -type f -atime +5 -delete
fi
if [ -d /tmp ]; then
"$ESCALATION_TOOL" find /tmp -type f -atime +5 -delete
fi
if [ -d /var/log ]; then
"$ESCALATION_TOOL" find /var/log -type f -name "*.log" -exec truncate -s 0 {} \;
fi
"$ESCALATION_TOOL" find /var/tmp -type f -atime +5 -delete &> /dev/null || true
"$ESCALATION_TOOL" find /tmp -type f -atime +5 -delete &> /dev/null || true
"$ESCALATION_TOOL" find /var/log -type f -name "*.log" -exec truncate -s 0 {} \; &> /dev/null || true

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could but if user doesnt have perms for a file (could happen and will happen with /tmp) it'll fail too

Copy link
Contributor

@jeevithakannan2 jeevithakannan2 Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cmd is escalated so is less likely to fail due to perm err

"$ESCALATION_TOOL" journalctl --vacuum-time=3d
}

Expand All @@ -45,8 +50,12 @@ clean_data() {
case $clean_response in
y|Y)
printf "%b\n" "${YELLOW}Cleaning up old cache files and emptying trash...${RC}"
find "$HOME/.cache/" -type f -atime +5 -delete
find "$HOME/.local/share/Trash" -mindepth 1 -delete
if [ -d "$HOME/.cache" ]; then
find "$HOME/.cache/" -type f -atime +5 -delete
fi
if [ -d "$HOME/.local/share/Trash" ]; then
find "$HOME/.local/share/Trash" -mindepth 1 -delete
fi
printf "%b\n" "${GREEN}Cache and trash cleanup completed.${RC}"
;;
*)
Expand Down