Skip to content

Commit

Permalink
feat(Core): use fsync with atomic_write
Browse files Browse the repository at this point in the history
We can't get around hardware failures, but we can make a best effort
with fsync at least.
  • Loading branch information
tecosaur committed Oct 12, 2024
1 parent 911c1c1 commit 812e6f1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Core/src/model/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 812e6f1

Please sign in to comment.