Homec4science

add Filesystem::writeFileIfChanged

Authored by Wez Furlong <wez@fb.com> on Apr 1 2013, 22:08.

Description

add Filesystem::writeFileIfChanged

Summary:
porting this from FB to libphutil. We've been using this
internally for a couple of months. The intention is to ensure that
build steps atomically write the entire contents from the perspective
of readers.

For example, we had cases where reasonably large PHP source files were
being generated concurrently with another process attempting to read
the file. Since the file was in the middle of being re-written, the
reader hit a parse error.

While this doesn't guarantee consistency from an overall code-base
perspective, it does mean that the contents of the file are internally
consistent.

Since we use this method in build steps, we only replace the file if
its contents are different. This avoids touching the file and causing
a false rebuild of the dependents. In this scenario, we assume that
some other mechanism exists to ensure that there is only one writer
(such as locking in the build scripts), and that it is "OK" for there
to be concurrent readers.

Test Plan:
It's a port from our Filesystem library. I tried it out
from our build workflow. We already found and fixed the umask bug ;-)

Reviewers: nh, epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5523

Details

Committed
Wez Furlong <wez@fb.com>Apr 1 2013, 22:08
Pushed
aubortMar 17 2017, 12:03
Parents
rPHU8d38e4cf3c88: Improve remarkup performance (libphutil)
Branches
Unknown
Tags
Unknown

Event Timeline

Wez Furlong <wez@fb.com> committed rPHUcd18134951c3: add Filesystem::writeFileIfChanged (authored by Wez Furlong <wez@fb.com>).Apr 1 2013, 22:08