Skip to content

File not closed properly when loaded using an IOStream #145

@azurefx

Description

@azurefx

ImageMagick v0.7.1
FileIO v1.0.4
Windows 10 x64 17763

When a file is loaded with an open IOStream (MagickReadImageFile), the file gets locked until the julia process exits. However the native MagickReadImage function (called by load(filename)) can release the file correctly.

To reproduce this problem, open a PWSH (elevated):

PS C:\> Copy-Item .\img1.jpg -Destination img2.jpg
PS C:\> julia --banner=no
julia> using Images

julia> using FileIO

julia> size(load("img1.jpg"))
(1080, 1920)

julia> rm("img1.jpg")

julia> io=open("img2.jpg")
IOStream(<file img2.jpg>)

julia> size(load(io))
(1080, 1920)

julia> close(io)

julia> rm("img2.jpg")
ERROR: IOError: unlink: resource busy or locked (EBUSY)
Stacktrace:
 [1] uv_error at .\libuv.jl:85 [inlined]
 [2] unlink(::String) at .\file.jl:722
 [3] #rm#9(::Bool, ::Bool, ::Function, ::String) at .\file.jl:253
 [4] rm(::String) at .\file.jl:245
 [5] top-level scope at none:0

julia> exit()
PS C:\> Remove-Item .\img2.jpg
PS C:\>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions