registrator
registrator copied to clipboard
feature(etcd): Directory garbage collection
In our story we need to keep directory list clear from empty ones. So I add this code to remove a directory when it's empty.
ping @progrium
Thanks. I think this should stop at r.path
instead of going all the way to up to /
to ensure that registrator doesn't accidentally delete parent directories of the path it's using.
Also, can you run this through the gofmt tool? I just noticed a missing space before one of the {
brackets, though gofmt is quite nice for making sure that all of your Go code follows the standard formatting guidelines.
Thank you Matt for your comment.
etcd client DeleteDir
method throw an error if directory is not empty and on the other hand in creation time child dirs will be create if requested.
so I think that's not important if we remove empty directories.
Thanks yes, I see that DeleteDir will not allow deleting non-empty directories, so that should be ok.
I agree that it would usually be harmless to delete empty parent directories, however I still want to make sure registrator doesn't make any changes outside of it's root
. This may surprise or confuse users if registrator's directory disappears, and may in some uncommon circumstances cause issues if registrator deleted a directory the user expected to exist.
I can make the change myself, but if you have a chance it may help me get this merged a little sooner. Please also run gofmt
to format the code as well.
You right. :+1:
Changed my code; stop garbage collecting at r.path
directory and fix code style format.
thanx, LGTM