Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unwanted artifact deletion with checking remote_downloads field #157

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading