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 backups cleanup #297

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
41 changes: 20 additions & 21 deletions common/profile-sync-daemon.in
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ ungraceful_state_check() {
}

cleanup() {
local keep_count=$1
if [ -z "$keep_count" ]
then
keep_count=0
fi

local browser
for browser in "${BROWSERS[@]}"; do
load_env_for "$browser"
Expand All @@ -340,15 +346,20 @@ cleanup() {
CRASHArr=("${CRASHArr[@]}" "$backup")
done < <(find "${DIR%/*}" -type d -name '*crashrecovery*' -print0 | sort -r -z)

if [[ ${#CRASHArr[@]} -gt 0 ]]; then
echo -e "${BLD}Deleting ${#CRASHArr[@]} crashrecovery dir(s) for profile ${BLU}$DIR${NRM}"
for backup in "${CRASHArr[@]}"; do
echo -e "${BLD}${RED} $backup${NRM}"
rm -rf "$backup"
done
else
echo -e "${BLD}Found no crashrecovery dirs for: ${BLU}$DIR${NRM}${BLD}${NRM}"
let "remove_count=${#CRASHArr[@]} - keep_count"
if [[ remove_count -le 0 ]]; then
if [[ keep_count -eq 0 ]]; then
echo -e "${BLD}Found no crashrecovery dirs for: ${BLU}$DIR${NRM}${BLD}${NRM}"
fi
continue
fi

echo -e "${BLD}Deleting ${remove_count} crashrecovery dir(s) for profile ${BLU}$DIR${NRM}"

for backup in "${CRASHArr[@]:$keep_count}"; do
echo -e "${BLD}${RED} $backup${NRM}"
rm -rf "$backup"
done
echo
done
done
Expand Down Expand Up @@ -554,19 +565,7 @@ do_sync() {
}

enforce() {
local browser
for browser in "${BROWSERS[@]}"; do
local CRASHArr=()
while IFS= read -d '' -r backup; do
CRASHArr=("${CRASHArr[@]}" "$backup")
done < <(find "${DIR%/*}" -type d -name '*crashrecovery*' -print0 | sort -r -z)

if [[ ${#CRASHArr[@]} -gt $BACKUP_LIMIT ]]; then
for remove in "${CRASHArr[@]:$BACKUP_LIMIT}"; do
rm -rf "$remove"
done
fi
done
cleanup $BACKUP_LIMIT
}

do_unsync() {
Expand Down