https://pantsbuild.org/ logo
#plugins
Title
# plugins
f

fresh-cat-90827

03/14/2023, 7:11 PM
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

fast-nail-55400

03/14/2023, 7:19 PM
The goal rule can perform side effects so just delete the directory first with normal Python code?
f

fresh-cat-90827

03/14/2023, 7:21 PM
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

curved-television-6568

03/14/2023, 7:27 PM
I guess could be an option on the
workspace.write_digest()
?
🤔 1
f

fresh-cat-90827

03/21/2023, 5:07 PM
thanks, Andreas, for the suggestion! https://github.com/pantsbuild/pants/pull/18534 this is now done
💥 1
2 Views