howdy. I have a file produced in a build directory...
# development
f
howdy. I have a file produced in a build directory after running
Process
. There was a file produced. I need to rename that file.
Copy code
files = await Get(DigestEntries, Digest, result.output_digest)  # result is from "await Get(ProcessResult, Process(...))"
    for file in files:
        print(f"Path: {file.path}")
        print(f"Path: {file.file_digest}")
get
Copy code
stdout: "Path: file.data"
stdout: "\n"
stdout: "Path: FileDigest('a5958f492644f5abe6f784fb1840b70e279143cbbc5d3a0770d7554a8b80d982', 796)"
Reading https://www.pantsbuild.org/docs/rules-api-file-system#digestentries. Do I need to write the
FileDigest
on disk (to produce a brand new file) with
Workspace.write_digest()
or is there a mechanism to update the filename in place?
c
From what I know, there’s no intrinsic rule for renaming files, only moving them.
However, if it is not a huge file, you could read it into memory, and then create a new digest from that, so no need to write it out into the workspace solely for the purpose of renaming it.
f
oh, I am happy to move the file beside the original one i.e. what
mv origin dest
command would do 🙂
Ah, move as in
mv origin/file dest/file
The
AddPrefix
and
RemovePrefix
does the moving…
Hmm… perhaps it doesn’t work well with singling out just one file though… so might need to get that as a subset first…
Would perhaps make sense to have a more powerful digest mutation intrinsic where you can more freely alter the contents of a digest..
f
You can pass a list of
FileEntry
to
CreateDigest
to make a new digest.
So male a new
FileEntry
with the new name but with the digest set to the
FileDigest
from the previous
FileEntry
. Then pass to
await Get(Digest, CreateDigest(…))
It is a much more of a “raw” API then
AddPrefix
/
RemovePrefix
but you can pretty much do whatever you want with it.
(which is why I added it since
AddPrefix
/
RemovePrefix
had been too high level for my needs)
Would perhaps make sense to have a more powerful digest mutation intrinsic where you can more freely alter the contents of a digest..
CreateDigest
with the list of
FileEntry
🙂
2
Ideas for an “intermediate” way of altering a digest definitely welcome.
c
Great, I overlooked that there’s two kinds for files, the
FileEntry
and the
FileContent
.
f
yeah
FileContent
was the original API but it brings the file into memory which is a problem in the JVM backends when manipulating large jar files
💯 2
c
Yeah,
FileEntry
makes a ton of sense when working with the files, rather than the contents.
f
Thanks folks, let me give that a try today
👍 3
worked perfectly, thanks a lot @fast-nail-55400 and @curved-television-6568
👍 1