Skip to content

Commit

Permalink
Expand home path in fs.PathExists (#3270)
Browse files Browse the repository at this point in the history
* Expand home path in `fs.PathExists`

A build rule like this

```python
genrule(
    name = name,
    secrets = ["~/test.yaml"],
)
```

fails building with this error

```
failed to calculate hash: Attempting to record rule hash: cannot calculate hash for ~/test.yaml: file does not exist
```

The hash functions use `os.Lstat` to check for file existence, and
`lstat(2)` does not seem to expand the home path itself.

So this PR calls the `ExpandHomePath` before `os.Lstat` in the functions
which check file presence. I've tested it by bootstrapping `please` on
this branch and building the rule that initially failed.

* Expand path at call site

---------

Co-authored-by: Cezar El-Nazli <[email protected]>
  • Loading branch information
cezarelnazli and Cezar El-Nazli authored Oct 10, 2024
1 parent 04cbb40 commit 53f05bb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/build/incrementality.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func secretHash(state *core.BuildState, target *core.BuildTarget) ([]byte, error
}
h := sha1.New()
for _, secret := range target.Secrets {
ph, err := state.PathHasher.Hash(secret, false, false, false)
ph, err := state.PathHasher.Hash(fs.ExpandHomePath(secret), false, false, false)
if err != nil && os.IsNotExist(err) {
return noSecrets, nil // Not having the secrets is not an error yet.
} else if err != nil {
Expand Down

0 comments on commit 53f05bb

Please sign in to comment.