add: raise DoesNotExistError only if the output path does not exist (#10373)

`dvc add` command incorrectly raises a `DoesNotExistError` when a
broken symlink exists in an output directory, and the target name
is same as the directory's name.

eg: If `data` is an output, and is the command is invoked as `dvc add data`
(i.e. no virtual directory operations to perform).

The expected behavior to raise a `FileNotFoundError`.
`DoesNotExistError` should only be raised if the output itself does not
exist.

Related: https://github.com/iterative/dvc/issues/3717
This commit is contained in:
skshetry
2024-03-26 11:16:35 +00:00
committed by GitHub
parent 3375a7c39f
commit 5379aa2348
+1 -1
View File
@@ -1365,7 +1365,7 @@ class Output:
dry_run=not self.use_cache,
)
except FileNotFoundError as exc:
if self.fs_path == path:
if not self.exists:
raise self.DoesNotExistError(self) from exc
if not self.is_dir_checksum:
raise