Skip to content

Commit

Permalink
Fix unwanted artifact deletion with checking remote_downloads field (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
philippe-granet authored Jan 13, 2025
1 parent fce5b54 commit e1b74fa
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
28 changes: 26 additions & 2 deletions artifactory_cleanup/rules/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ class DeleteWithoutDownloads(Rule):
"""

def aql_add_filter(self, filters):
filter_ = {"stat.downloads": {"$eq": None}}
filter_ = {
"$and": [
{"stat.downloads": {"$eq": None}},
{"stat.remote_downloads":{"$eq": None}},
],
}
filters.append(filter_)
return filters

Expand All @@ -49,6 +54,7 @@ def aql_add_filter(self, filters):
filter_ = {
"$and": [
{"stat.downloads": {"$eq": None}},
{"stat.remote_downloads":{"$eq": None}},
{"created": {"$lte": last_day.isoformat()}},
],
}
Expand All @@ -70,10 +76,28 @@ def aql_add_filter(self, filters):

filter_ = {
"$or": [
{"stat.downloaded": {"$lte": str(last_day)}},
{
"$and": [
{"stat.downloaded": {"$lte": str(last_day)}},
{"stat.remote_downloaded": {"$lte": str(last_day)}},
]
},
{
"$and": [
{"stat.downloaded": {"$lte": str(last_day)}},
{"stat.remote_downloads": {"$eq": None}},
]
},
{
"$and": [
{"stat.downloads": {"$eq": None}},
{"stat.remote_downloaded": {"$lte": str(last_day)}},
]
},
{
"$and": [
{"stat.downloads": {"$eq": None}},
{"stat.remote_downloads": {"$eq": None}},
{"created": {"$lte": str(last_day)}},
]
},
Expand Down
21 changes: 20 additions & 1 deletion artifactory_cleanup/rules/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def aql_add_filter(self, filters):
last_day = self.today - self.days
filter_ = [
{"stat.downloads": {"$eq": None}},
{"stat.remote_downloads": {"$eq": None}},
{"created": {"$lte": last_day.isoformat()}},
]
filters.extend(filter_)
Expand All @@ -131,10 +132,28 @@ def aql_add_filter(self, filters):
print("Delete docker images not used from {}".format(last_day.isoformat()))
filter_ = {
"$or": [
{"stat.downloaded": {"$lte": last_day.isoformat()}},
{
"$and": [
{"stat.downloaded": {"$lte": last_day.isoformat()}},
{"stat.remote_downloaded": {"$lte": last_day.isoformat()}},
]
},
{
"$and": [
{"stat.downloaded": {"$lte": last_day.isoformat()}},
{"stat.remote_downloads": {"$eq": None}},
]
},
{
"$and": [
{"stat.downloads": {"$eq": None}},
{"stat.remote_downloaded": {"$lte": last_day.isoformat()}},
]
},
{
"$and": [
{"stat.downloads": {"$eq": None}},
{"stat.remote_downloads": {"$eq": None}},
{"created": {"$lte": last_day.isoformat()}},
]
},
Expand Down

0 comments on commit e1b74fa

Please sign in to comment.