Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f5f01d4

Browse files
author
George Wright
committed
Implement WriteAtomically using write/fsync on all platforms, and enable
file unittests on Fuchsia
1 parent e37f2fc commit f5f01d4

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

fml/platform/posix/file_posix.cc

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,23 @@ bool WriteAtomically(const fml::UniqueFD& base_directory,
206206
return false;
207207
}
208208

209-
FileMapping mapping(temp_file, {FileMapping::Protection::kWrite});
210-
if (mapping.GetMutableMapping() == nullptr ||
211-
data.GetSize() != mapping.GetSize()) {
212-
return false;
213-
}
209+
ssize_t remaining = data.GetSize();
210+
ssize_t written = 0;
211+
ssize_t offset = 0;
212+
213+
while (remaining > 0) {
214+
written = FML_HANDLE_EINTR(
215+
::write(temp_file.get(), data.GetMapping() + offset, remaining));
214216

215-
::memcpy(mapping.GetMutableMapping(), data.GetMapping(), data.GetSize());
217+
if (written == -1) {
218+
return false;
219+
}
220+
221+
remaining -= written;
222+
offset += written;
223+
}
216224

217-
if (::msync(mapping.GetMutableMapping(), data.GetSize(), MS_SYNC) != 0) {
225+
if (::fsync(temp_file.get()) != 0) {
218226
return false;
219227
}
220228

testing/fuchsia/meta/fuchsia_test.cmx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"features": [
77
"vulkan",
88
"deprecated-ambient-replace-as-executable",
9-
"isolated-cache-storage"
9+
"isolated-cache-storage",
10+
"isolated-temp"
1011
],
1112
"services": [
1213
"fuchsia.accessibility.semantics.SemanticsManager",

testing/fuchsia/run_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ echo "$(date) START:fml_tests ---------------------------------------"
100100
./fuchsia_ctl -d $device_name test \
101101
-f fml_tests-0.far \
102102
-t fml_tests \
103-
-a "--gtest_filter=-FileTest*" \
103+
-a "--gtest_filter=-FileTest.CanTruncateAndWrite:FileTest.CreateDirectoryStructure" \
104104
--identity-file $pkey \
105105
--timeout-seconds $test_timeout_seconds \
106106
--packages-directory packages

0 commit comments

Comments
 (0)