Skip to content

perf: Copy file mode with chmod instead of stat and write_stat - #15754

Open
tomciopp wants to merge 1 commit into
elixir-lang:mainfrom
tomciopp:perf/file-copy-mode-chmod
Open

perf: Copy file mode with chmod instead of stat and write_stat#15754
tomciopp wants to merge 1 commit into
elixir-lang:mainfrom
tomciopp:perf/file-copy-mode-chmod

Conversation

@tomciopp

Copy link
Copy Markdown
Contributor

copy_file_mode/2 read the destination's file_info purely to rebuild
a full record and write it back with only :mode changed. The
destination stat served no purpose: :file.change_mode/2 is
implemented as write_file_info with a mode-only record, so applying
the source mode directly performs the same operation with one fewer
file-server round trip per file copied by File.cp/3 and File.cp_r/3.

Writing the full record back also had two unintended effects that
this removes: it attempted to set the destination's owner, which
POSIX permits to fail with EPERM for non-owner copies even when the
value is unchanged, and it rewrote the destination's timestamps with
the second-precision values read by stat, truncating the sub-second
mtime of the freshly written file.

Assisted by: Claude Fable.

@tomciopp

Copy link
Copy Markdown
Contributor Author

Filesystem benchmarks on macOS were too noisy to certify the wall clock effect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant