registrator icon indicating copy to clipboard operation
registrator copied to clipboard

feature(etcd): Directory garbage collection

Open majidgolshadi opened this issue 8 years ago • 6 comments

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.

majidgolshadi avatar Oct 28 '15 13:10 majidgolshadi

ping @progrium

majidgolshadi avatar Nov 08 '15 06:11 majidgolshadi

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.

mgood avatar Nov 22 '15 22:11 mgood

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.

majidgolshadi avatar Nov 30 '15 06:11 majidgolshadi

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.

mgood avatar Dec 01 '15 02:12 mgood

You right. :+1: Changed my code; stop garbage collecting at r.path directory and fix code style format.

majidgolshadi avatar Dec 04 '15 08:12 majidgolshadi

thanx, LGTM

vidarl avatar Nov 17 '16 10:11 vidarl