Add TTL feature for cached files and folders

This commit is contained in:
Michael de Wit
2017-07-03 09:25:05 +02:00
parent 65ee2c6d06
commit d0637d0fba
3 changed files with 30 additions and 1 deletions
+10
View File
@@ -36,6 +36,16 @@ if [[ -n "$PLUGIN_REBUILD" && "$PLUGIN_REBUILD" == "true" ]]; then
fi
done
elif [[ -n "$PLUGIN_RESTORE" && "$PLUGIN_RESTORE" == "true" ]]; then
# Remove files older than TTL
if [[ -n "$PLUGIN_TTL" && "$PLUGIN_TTL" > "0" ]]; then
if [[ $PLUGIN_TTL =~ ^[0-9]+$ ]]; then
echo "Removing files and (empty) folders older than $PLUGIN_TTL days..."
find "/cache/$DRONE_REPO_OWNER/$DRONE_REPO_NAME/$DRONE_JOB_NUMBER" -type f -ctime +$PLUGIN_TTL -delete
find "/cache/$DRONE_REPO_OWNER/$DRONE_REPO_NAME/$DRONE_JOB_NUMBER" -type d -ctime +$PLUGIN_TTL -empty -delete
else
echo "Invalid value for ttl, please enter a positive integer. Plugin will ignore ttl."
fi
fi
# Restore from cache
for source in "${SOURCES[@]}"; do
if [ -d "/cache/$DRONE_REPO_OWNER/$DRONE_REPO_NAME/$DRONE_JOB_NUMBER/$source" ]; then