when writing files on disk with <Workspace.write_d...
# plugins
f
when writing files on disk with Workspace.write_digest(), is there a way to overwrite the directory instead of adding files to the existing directory? I.e. if I have
foo/bar/
created and non-empty, with my digests being
foo/bar/file1.txt
and
foo/bar/file2.txt
I want to ensure the
foo/bar
won't have anything else after the write (essentially truncating the directory first). Is that possible at all?
f
The goal rule can perform side effects so just delete the directory first with normal Python code?
f
I've tried
Copy code
dir_digest = await Get(Digest, CreateDigest([Directory(f"foo/bar")]))
        workspace.write_digest(dir_digest)
before creating files (hoping it would overwrite the existing directory with an empty one), but that didn't work.
The goal rule can perform side effects so just delete the directory first with normal Python code?
Thanks, that's an option I have, I guess. It would be nice to be able to do this from Pants to avoid mixing Pants and non-Pants operations
c
I guess could be an option on the
workspace.write_digest()
?
🤔 1
f
thanks, Andreas, for the suggestion! https://github.com/pantsbuild/pants/pull/18534 this is now done
💥 1