Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[antlir2][remove] add must_be_empty flag
Summary: In some cases it may be desirable to delete an empty directory but fail if it has any contents. Test Plan: This is impossible to unittest without T166070409 ``` ❯ hg diff diff --git a/fbcode/antlir/antlir2/test_images/remove/TARGETS b/fbcode/antlir/antlir2/test_images/remove/TARGETS --- a/fbcode/antlir/antlir2/test_images/remove/TARGETS +++ b/fbcode/antlir/antlir2/test_images/remove/TARGETS @@ -31,6 +31,17 @@ parent_layer = ":base", ) +image.layer( + name = "remove-empty-dir", + features = [ + feature.remove( + must_be_empty = True, + path = "/b", + ), + ], + parent_layer = ":base", +) + image_diff_test( name = "remove-test", diff = "remove.toml", ❯ buck2 build fbcode//antlir/antlir2/test_images/remove:remove-empty-dir 2023-10-19T14:21:52.466415Z ERROR compile:remove{self=Remove { path: "/b", must_exist: true, must_be_empty: true }}: remove: error=Directory not empty (os error 39) 2023-10-19T14:21:52.466666Z ERROR compile: antlir2::cmd::compile: error=Directory not empty (os error 39) 2023-10-19T14:21:52.470541Z ERROR map: antlir2::cmd::map: error="isolated command failed: exit status: 1" stderr: Compile( IO( Os { code: 39, kind: DirectoryNotEmpty, message: "Directory not empty", }, ), ) Directory not empty (os error 39) ``` Reviewed By: justintrudell Differential Revision: D50456566 fbshipit-source-id: 7123779f182853819a7176f81bfbb473f2917425
- Loading branch information