Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement File#fsync on Windows #9257

Merged
merged 1 commit into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/crystal/system/win32/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ module Crystal::System::File
end

private def system_fsync(flush_metadata = true) : Nil
raise NotImplementedError.new("File#fsync")
if LibC._commit(fd) != 0
raise IO::Error.from_errno("Error syncing file")
end
end
end
3 changes: 3 additions & 0 deletions src/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,9 @@ class File < IO::FileDescriptor
# then the syscall *fdatasync* will be used and only data required for
# subsequent data retrieval is flushed. Metadata such as modified time and
# access time is not written.
#
# NOTE: Metadata is flushed even when *flush_metadata* is false on Windows
# and DragonFly BSD.
def fsync(flush_metadata = true) : Nil
flush
system_fsync(flush_metadata)
Expand Down
1 change: 1 addition & 0 deletions src/lib_c/x86_64-windows-msvc/c/io.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ lib LibC
fun _get_osfhandle(fd : Int) : IntPtrT
fun _pipe(pfds : Int*, psize : UInt, textmode : Int) : Int
fun _dup2(fd1 : Int, fd2 : Int) : Int
fun _commit(fd : Int) : Int
end