From 3bc8f5b3b3d34bbab35e0f2b875d09f866bc2ec2 Mon Sep 17 00:00:00 2001 From: home Date: Wed, 22 Nov 2023 12:36:14 +0300 Subject: [PATCH] archive : add prune to delete old versions. --- .README.md | 1 + .config/bash/module/archive.sh | 29 ++++++++++++++++++++++++++++- .config/bash/module/checksum.sh | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/.README.md b/.README.md index 9f0bf92..30514b6 100644 --- a/.README.md +++ b/.README.md @@ -316,6 +316,7 @@ Command|Description `archive_fast [FILES]`|Like normal `archive` but with minimal compression. `archive_check [ARCHIVES]`|Check specified archives or all archives in current directory. `archive_name [ARCHIVES] [NAME]`|Rename specified archive ro specified name or simplify name for specified archive or simplify names for all archives. +`archive_prune [NAME]`|Delete old versions of an archive, or all archives by default. `unarchive [ARCHIVES]`|Check specified or all archives and extract if they are correct. ## Autocomplete. diff --git a/.config/bash/module/archive.sh b/.config/bash/module/archive.sh index 8087dca..5a5cc34 100644 --- a/.config/bash/module/archive.sh +++ b/.config/bash/module/archive.sh @@ -124,6 +124,33 @@ archive_check() fi } +# Delete old versions of an archives. +# Usage: archive_prune [NAME] +archive_prune() +{ + local targets=("${@}") + local count=0 + local total=${#} + + # All archives by default. + if [[ "${target}" = "" ]]; then + targets=($(ls | grep -E ${_ARCHIVE_PATTERN})) + total=${#targets[@]} + fi + + # Iterate each target. + for target in "${targets[@]}"; do + # Only work with files. + [[ -f "${target}" ]] || continue + + # Iterate counter. + ((count++)) + + local name="${target%_*}" + # local copies=("$()") + done +} + # extract previously created archive with checksum validation. # usage: unarchive [FILES] unarchive() @@ -198,7 +225,7 @@ archive_name() # iterate each target. for target in "${targets[@]}"; do - # only work with targets. + # only work with files. [[ -f "${target}" ]] || continue # iterate counter. diff --git a/.config/bash/module/checksum.sh b/.config/bash/module/checksum.sh index fc9444f..c039ce3 100644 --- a/.config/bash/module/checksum.sh +++ b/.config/bash/module/checksum.sh @@ -8,7 +8,7 @@ checksum() if [[ "$action" =~ ^(n|new)$ ]]; then # create checksums for all files. - find -type f | parallel sha1sum {} > "$file" + find -type f | parallel sha1sum {} >> "$file" # remove checksum file from resulting hashes. sed -i "/$file/d" "$file"