Always set file modified time after writing to a file (#414)

Two problems:
1. We are incorrectly writing to a file if the destination file has more
   content than the source file during copying.
2. We aren't updating the timestamp of the file when the destiination
   file has zero bytes.

Both these would be fixed by just setting the file open mode to
os.O_TRUNC which would truncate the file if it already exists.

Test:
1. Unit tests
2. Tested in Android build with:
```
rm -f out/reproxy* && touch frameworks/opt/net/voip/src/java/com/android/server/sip/SipWakeupTimer.java && RBE_v=3 RBE_instance="projects/foundry-x-experiments/instances/default-instance" RBE_use_unified_cas_ops=false RBE_use_batches=false RBE_METALAVA=true m out/soong/.intermediates/frameworks/base/api-stubs-docs-non-updatable/android_common/metalava/check_last_released_api.timestamp
```

and confirmed that `restat` warnings were no longer popping up during
rebuilds.
2 files changed
tree: 918c12fe8e2a4ecbb24b13c7b24b17c5da77822a
  1. .bazelci/
  2. .githooks/
  3. .github/
  4. external/
  5. go/
  6. .gitignore
  7. .golangci.yml
  8. AUTHORS
  9. BUILD.bazel
  10. check-gofmt.sh
  11. CONTRIBUTING.md
  12. CONTRIBUTORS
  13. go.mod
  14. go.sum
  15. LICENSE
  16. README.md
  17. remote-apis-sdks-deps.bzl
  18. setup-githooks.sh
  19. WORKSPACE
README.md

Remote Execution API SDKs

CI status: Build Status

PkgGoDev

This repository contains SDKs for the Remote Execution API.

See each language subdirectory's README.md for more specific instructions on using the SDK for that language.