Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove empty Carrierwave directories when asset file is removed
Since #373 we've been deleting an asset's underlying file from the filesystem once the file has been uploaded to S3. However, this was leaving behind a bunch of empty directories. This change means that the app now removes all empty parent directories when the file is removed. The immediate motivation behind this change is that once alphagov/govuk-puppet#7016 is applied in production, the Asset Manager Carrierwave directory will no longer be sync-ed from the Asset Master to the Asset Slaves and there will therefore be a danger that the asset_master_and_slave_disk_space_similar_from_xxx Icinga alert [1] might eventually be triggered by the non-zero disk space taken up by the empty directories. The implementation makes use of `FileUtils.rmdir` with the `parents` option which is equivalent to the `rmdir -p` unix command and which recursively removes empty directories from the supplied path upwards. Note that I think this means that in some circumstances top-level directories (e.g. `tmp/test_uploads/assets` in the test environment) might be removed, but I'm pretty confident Carrierwave creates directories using the equivalent of `mkdir -p` and so any missing intermediate directories will be created. []1: https://github.com/alphagov/govuk-puppet/blob/19837b4b351d97d84570bd8a7d01ef3420fbef94/modules/govuk/manifests/node/s_asset_slave.pp#L50-L63
- Loading branch information