diff --git a/dvc/output.py b/dvc/output.py index b9122006ce..7003d4717a 100644 --- a/dvc/output.py +++ b/dvc/output.py @@ -965,7 +965,10 @@ def relative_update(self, inc: int = 1) -> None: return added, False if added else modified def remove(self, ignore_remove=False): - self.fs.remove(self.fs_path, recursive=True) + try: + self.fs.remove(self.fs_path, recursive=True) + except FileNotFoundError: + pass if self.protocol != Schemes.LOCAL: return diff --git a/tests/func/repro/test_repro.py b/tests/func/repro/test_repro.py index f6e460bb95..1da583db5c 100644 --- a/tests/func/repro/test_repro.py +++ b/tests/func/repro/test_repro.py @@ -1273,3 +1273,12 @@ def test_repro_missing_lock_info(tmp_dir, dvc, copy_script): stages = dvc.reproduce(stage.addressing) assert len(stages) == 1 + + +def test_repro_rm_recursive(tmp_dir, dvc): + # check that dir output recursively removes files in the dir + tmp_dir.gen({"dir": {"foo": "foo"}}) + dvc.stage.add(name="dir", cmd="mkdir dir", outs=["dir"]) + dvc.reproduce() + assert (tmp_dir / "dir").exists() + assert not (tmp_dir / "dir" / "foo").exists()