Skip to content

Commit

Permalink
Use copy on write when available. (#925)
Browse files Browse the repository at this point in the history
The local cache strategy will now create copy-on-write files when supported. This can improve performance when copying output files either into the cache or restoring from out of it, as the files' underlying data doesn't need to be copied, only filesystem metadata.
  • Loading branch information
rictic authored Jan 10, 2024
1 parent 0de562c commit 852f41a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Versioning](https://semver.org/spec/v2.0.0.html).
### Changed

- The default logger for non-interactive environments has been switched to the 'quiet-ci' logger.
- The local cache strategy will now create copy-on-write files when supported. This can improve performance when copying output files either into the cache or restoring from out of it, as the files' underlying data doesn't need to be copied, only filesystem metadata.

## [0.14.1] - 2023-10-20

Expand Down
10 changes: 9 additions & 1 deletion src/util/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ export const copyEntries = async (
*/
const copyFileGracefully = async (src: string, dest: string): Promise<void> => {
try {
await fs.copyFile(src, dest, fs.constants.COPYFILE_EXCL);
await fs.copyFile(
src,
dest,
// COPYFILE_FICLONE: Copy the file using copy-on-write semantics, so that
// the copy takes constant time and space. This is a noop currently
// on some platforms, but it's a nice optimization to have.
// See https://github.com/libuv/libuv/issues/2936 for macos support.
fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE,
);
} catch (error) {
const {code} = error as {code: string};
if (code === /* does not exist */ 'ENOENT') {
Expand Down

0 comments on commit 852f41a

Please sign in to comment.