Skip to content

Commit

Permalink
v1.0.18 (#20)
Browse files Browse the repository at this point in the history
Minor updates
* Adding upload-cleanup to remove files after time expiry (download expiry is handled by send)
  • Loading branch information
bfren authored Jan 29, 2023
1 parent f03dafe commit 366cd81
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.17
1.0.18
61 changes: 61 additions & 0 deletions overlay/etc/periodic/hourly/upload-cleanup
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/command/with-contenv sh

set -euo pipefail
export BF_E=`basename ${0}`


#======================================================================================================================
# Remove files.
# Arguments:
# 1 The list of files to remove.
#======================================================================================================================

remove_files () {
for FILE in "${1}" ; do
[[ ! -f "${FILE}" ]] && continue
bf-echo "Removing expired file ${FILE}." "upload-cleanup"
rm -f ${FILE}
done
}


#======================================================================================================================
# Remove files by their expiry time.
# Files are stored using the number of days they should be kept as the filename prefix.
#======================================================================================================================

bf-debug "Removing files by their expiry time." "upload-cleanup"
for SEC in `echo ${SEND_EXPIRE_TIMES_SECONDS} | tr ',' '\n'` ; do

# calculate the number of minutes (find does not support seconds)
MIN=$((SEC / 60))

# calculate the number of days (making 1 the minimum)
DAY=$((MIN / 60 / 24))
[[ ${DAY} -eq 0 ]] && DAY=1

# search for files with DAY as the prefix and modified more than MIN ago
bf-debug "Searching for files named ${DAY}-* and modified more than ${MIN}m ago..." "upload-cleanup"
FILES=`find ${SEND_FILE_DIR} -type f -name ${DAY}-\* -mmin +${MIN} | xargs`

# use function to remove each found file
remove_files "${FILES}"

done
exit 0

#======================================================================================================================
# In case SEND_EXPIRE_TIMES_SECONDS has been modified and there are uploads with (now) unsupported expiry times,
# use SEND_MAX_EXPIRE_SECONDS to remove any files that have exceeded the maximum expiry time.
#======================================================================================================================

# calculate the number of minutes (find does not support seconds)
bf-debug "Removing files by maximum expiry time." "upload-cleanup"
MAX_MIN=$((SEND_MAX_EXPIRE_SECONDS / 60))

# search for files modified more than MAX_MIN ago
bf-debug "Searching for files modified more than the maximum ${MAX_MIN}m ago..." "upload-cleanup"
FILES=`find ${SEND_FILE_DIR} -type f -mmin +${MIN} | xargs`

# use function to remove each found file
remove_files "${FILES}"

0 comments on commit 366cd81

Please sign in to comment.