From a9d9b3d3b7de2afce0171b0ee62227776e9bf267 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Sun, 29 Mar 2020 21:24:46 -0400 Subject: [PATCH 1/2] In open(f, ...), call flush before calling `close` In #35217, I noticed that if we call `close` on an IOStream, but the device that has the underlying file is full, we silently truncate the file without error. To remidy that, introduce an explicit flush call before closing the file. This should either succeed and reflect the changes on disk, or fail and throw an appropriate error. --- base/io.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/base/io.jl b/base/io.jl index e162996d58fe5..4f5e8ec6c18a0 100644 --- a/base/io.jl +++ b/base/io.jl @@ -296,6 +296,7 @@ function open(f::Function, args...; kwargs...) io = open(args...; kwargs...) try f(io) + flush(io) finally close(io) end From b7537506adca542dfec7be92c00ae74cb676bd35 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Mon, 30 Mar 2020 16:56:41 -0400 Subject: [PATCH 2/2] Update base/io.jl Co-Authored-By: Jameson Nash --- base/io.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/io.jl b/base/io.jl index 4f5e8ec6c18a0..ad81a4075998d 100644 --- a/base/io.jl +++ b/base/io.jl @@ -295,8 +295,9 @@ julia> rm("myfile.txt") function open(f::Function, args...; kwargs...) io = open(args...; kwargs...) try - f(io) + v = f(io) flush(io) + return v finally close(io) end