mirror of
https://github.com/drillster/drone-volume-cache.git
synced 2026-06-04 18:24:02 +08:00
Add TTL feature for cached files and folders
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user