Problem
The rm: cannot remove XXX: Directory not empty message is misleading. The error occurs not because the directory has something in it, but because some process is attached to a file within the directory, which makes it so it cannot be removed. See for instance https://stackoverflow.com/questions/64852408/cannot-remove-git-directory-not-empty.
Solution
During the cleanup procedure of publish-crates, for non-CI environments, first use fuser to kill all processes attached to files within the $tmp directory, then proceed with rm.
#32 (comment) for context