-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor updates * Adding upload-cleanup to remove files after time expiry (download expiry is handled by send)
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.0.17 | ||
1.0.18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |