gogoair / lavatory

Tooling to define repository specific retention policies in Artifactory.
Apache License 2.0
21 stars 14 forks source link

Support clean up of empty folders #47

Open atrifex opened 4 years ago

zeroepoch commented 2 years ago

We eventually resolved this empty folder problem using code like the following:

# Clean up empty folders
all_folders = [{
    "repo": {"$eq": "repo-local"},
    "path": {"$match": "path/*"},
}]
folders = artifactory.filter(terms=all_folders, depth=None, item_type="folder")
empty_folders = []
for folder in folders:
    folder_path = folder.get('path') + '/' + folder.get('name') + '*'
    folder_terms = [{
        "repo": {"$eq": "repo-local"},
        "path": {"$match": folder_path},
    }]
    sub_items = artifactory.filter(terms=folder_terms, depth=None, item_type="any")
    if len(sub_items) == 0:
        empty_folders.append(folder)