pub fn clone_dest_cleanable(dest: &Path) -> boolExpand description
R7 clone-cleanup: whether dest is safe to remove if a clone/git_clone
about to run into it fails — either provably absent (read_dir fails
with NotFound), or an already-empty directory. Compute this before
running the clone, and pass the result to cleanup_failed_clone_dest on
the error path — git/jj both refuse to clone into a non-empty
existing directory, so if dest already had contents going in, a failure
means that refusal, and the caller’s pre-existing data must never be
deleted. Re-checking emptiness after the clone ran would be wrong: a
failed clone can leave dest partially populated, so a post-hoc check
could wrongly call a partial clone’s leftovers “empty” (or simply disagree
with the pre-clone state).
Any read_dir failure other than NotFound (permission denied, a
transient I/O error, dest being a plain file — NotADirectory) is
treated as not cleanable: it doesn’t prove dest is absent, and
dest may well be a pre-existing non-empty directory the caller can’t
read into right now. Deleting on an unproven guess would risk
remove_dir_all-ing a directory full of the caller’s data; cleanup simply
becoming a no-op is the safe degradation (the clone itself already failed
with a clear git/jj error).
Shared by vcs_git::clone_repo and vcs_jj::git_clone, which previously
carried a byte-identical copy of this check plus its own best-effort
remove_dir_all on the error path.