-
Notifications
You must be signed in to change notification settings - Fork 68
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
feat: add direct source code to clean up empty folders instead of depending on additional plugin #48
Conversation
…ending on additional plugin
74e6917
to
23313b1
Compare
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
This feature has been implemented in Artifactory already. please see comments below. |
artifactory_cleanup/rules/delete.py
Outdated
# convert list of files to dict | ||
# Source: https://stackoverflow.com/a/58917078 | ||
|
||
def nested_dict(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inline functions are not readable here, it's hard to get the idea from it. Could we move as much as possible outside of the class?
I see there's no self
usages here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will move this to a new utils.py file. It's more readable then.
I would still keep it as inline functions since this is a function very specific to the conversion of list to dict, and not used anywhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be either a separate function or class method, but differently not a function inside class method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did some refactoring now. From my point of view it's now ready to be merged.
I would still argue against putting this as a separate function. It would be out of context. If you still disagree, feel free to direclty update this MR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thank you for your time and the contribution!
I like the idea to get rid of the plugin! But have some questions about the code, we should make it more readable and clean.
I don't have Artifactory instance, so can only rely on the code and right now the code does not inspire confidence in me that everything will work :D Let's rearrange it a little
@zhan9san thank you for noticing it! As @Pro mentioned in the issue about conan metadata #47
We can't achieve it with Artifactory. It's tricky, but it should work! |
@@ -8,7 +8,7 @@ | |||
| `delete_without_downloads()` | Deletes artifacts that have never been downloaded (DownloadCount=0). Better to use with `delete_older_than` rule | | |||
| `delete_older_than_n_days_without_downloads(days=N)` | Deletes artifacts that are older than N days and have not been downloaded | | |||
| `delete_not_used_since(days=N)` | Delete artifacts that were downloaded, but for a long time. N days passed. Or not downloaded at all from the moment of creation and it's been N days | | |||
| `delete_empty_folder()` | Clean up empty folders in local repositories. A special rule that runs separately on all repositories. Refers to [deleteEmptyDirs](https://github.com/jfrog/artifactory-user-plugins/tree/master/cleanup/deleteEmptyDirs) plugin | | |||
| `delete_empty_folder()` | Clean up empty folders in given repository list | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a note about delete_empty_folder
at the end
If you use Artifactory higher then 7.8.1 - it removes empty folders automaticly. We use the rule for some advanced usages, see FAQ section below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave this up to you to extend this MR with some additional descriptions.
Understood. For the Artifactory lower than 7.8.1, they have been EOL.
I prefer to remove the user plugin related function. Maybe adding a waring message first or get feedback from a poll. Regarding to the special empty dirs like those dirs which only contain If we use AQL here, the list would be too big if the repo contains lots of files. |
Thanks for your comments! @zhan9san as @allburov mentioned, the Artifactory Built-in Empty Folder deletion would not work here, since the folders still contain metadata files. I see two solutions to this metadata leftover issue:
For these specific rules we could then implement the recusrive deletion as proposed by @zhan9san
@allburov I can work on your comments. I would also like to add a few unit tests for the methods, especially the filter. |
I would just simply remove it. With semantic versioning and 0.x versions, a change from 0.3 to 0.4 means breaking change. If one really needs the plugin, he can stick with the old version. |
Let's do it then with a record in changelod.md about it!
Is the set of metadata files well defined for Conan? If it does and from path to class ConanMixin:
""" Also removes all metatada files for conan packages v1 """
index_files = ['.timestamp', 'index.json']
def _aql_add_filter(aql_query_list):
aql = super().__aql_add_filter(aql_query_list)
exclude_filename(self.index_files)._aql_add_filter(aql_query_list)
return aql
def _filter_result(self, result_artifact):
for conan_package_path in result_artifact:
index_path = ... # build path to some index
other_metadata_path = ... # build other paths
result_artifact.append(index_path)
result_artifact.append(other_metadata_path)
return result_artifact
class conan_delete_older_than(ConanMixin, delete_older_than):
pass
class conan_delete_not_used_since(ConanMixin, delete_not_used_since):
pass It doesn't look to hard to support it. |
I thought we're running them already... Feel free to create a PR for it, not a problem! |
I added now an additional Github action. See #51 Would be good if you can merge that first, then I will include it in this MR |
Unfortunately it's not that easy. It depends a bit on your conan settings (i.e., package references enabled/disabled). You can see the additional level of folders in the first one. And the cleanup may only also delete a subset of specific packages. Not sure though. Better to move the discussion to a new issue/MR. I will stick for now with the solution proposed in this MR. |
@Pro yep, let's add |
@allburov I did a refactoring. From my side I would see this MR ready to be merged. |
for more information, see https://pre-commit.ci
@Pro I'll look at this when I have free time and will ask to test the code because I don't have an Artifactory instance where I can test it. |
Could you look and test changes from #52? |
closed in favor #52 |
I added a bit more logic to the
delete_empty_folder()
rule to directly delete empty folders from the script, instead of depending on an additional plugin