From 812e6f19dc5f31506ea283d5456635f7bcf6e74c Mon Sep 17 00:00:00 2001 From: TEC Date: Sat, 12 Oct 2024 16:12:37 +0800 Subject: [PATCH] feat(Core): use fsync with atomic_write We can't get around hardware failures, but we can make a best effort with fsync at least. --- Core/src/model/utils.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Core/src/model/utils.jl b/Core/src/model/utils.jl index 13cdc2b03..a481964b3 100644 --- a/Core/src/model/utils.jl +++ b/Core/src/model/utils.jl @@ -72,7 +72,12 @@ function atomic_write end function atomic_write(f::Function, as::Union{Type{IO}, Type{String}}, dest::AbstractString, temp::AbstractString) try if as == IO - open(f, temp, "w") + io = open(temp, "w") + f(io) + req = Libc.malloc(Base._sizeof_uv_fs) + @ccall uv_fs_fsync(C_NULL::Ptr{Cvoid}, req::Ptr{Cvoid}, fd(io)::Base.OS_HANDLE, C_NULL::Ptr{Cvoid})::Cint + Libc.free(req) + close(io) else # String f(temp) end