My code unzips a data file, loads it, and deletes the temporary file. It has worked fine in the past but now it fails on the line that deletes the file. It happens in a module I’m working on, ClimateDataIO.jl in ghg_read.jl (line 89). The recent change was switching between DataFrames.readtable to CSV.read.
The error can be reproduced on Windows machines by running the module tests, Pkg.test("ClimateDataIO").
rm(temp)
ERROR: LoadError: unlink: operation not permitted (EPERM)
Stacktrace:
[1] uv_error at .\libuv.jl:68 [inlined]
[2] unlink(::String) at .\file.jl:500
[3] #rm#7(::Bool, ::Bool, ::Function, ::String) at .\file.jl:145
[4] #ghg_read#4(::Bool, ::Function, ::String) at C:\Users\JohnDoe\.julia\v0.6\ClimateDataIO\src\ghg_read.jl:89
[5] (::ClimateDataIO.#kw##ghg_read)(::Array{Any,1}, ::ClimateDataIO.#ghg_read, ::String) at .\<missing>:0
[6] include_from_node1(::String) at .\loading.jl:569
[7] include(::String) at .\sysimg.jl:14
[8] process_options(::Base.JLOptions) at .\client.jl:305
[9] _start() at .\client.jl:371
while loading C:\Users\JohnDoe\.julia\v0.6\ClimateDataIO\test\runtests.jl, in expression starting on line 275
It’s not a problem in Linux/Mac but I’ve confirmed the problem on two different Windows machines. It runs successfully in Coveralls and Codecov.
Calling rm on the same file in REPL works fine. My guess was that the file wasn’t closing properly until the test failed. The code looks fine, as far as I can tell I’ve closed the file every time I’ve opened it. What is wrong here?
Sorry I don’t know and don’t have window to make tests.
Is a different approach consisting in creating a temporary directory to do your job and then deleting it, may be acceptable ?
like line 30:
replacing : temp_dir = tempdir() with temp_dir = mktempdir()
and replacing lines 89:93 with: rm(temp_dir, true; recursive=true)
It looks the same to me. Line 91 is where the rm command is.
ERROR: LoadError: unlink: operation not permitted (EPERM)
Stacktrace:
[1] uv_error at .\libuv.jl:68 [inlined]
[2] unlink(::String) at .\file.jl:500
[3] #rm#7(::Bool, ::Bool, ::Function, ::String) at .\file.jl:145
[4] (::Base.Filesystem.#kw##rm)(::Array{Any,1}, ::Base.Filesystem.#rm, ::String) at .\<missing>:0
[5] #rm#7(::Bool, ::Bool, ::Function, ::String) at .\file.jl:155
[6] (::Base.Filesystem.#kw##rm)(::Array{Any,1}, ::Base.Filesystem.#rm, ::String) at .\<missing>:0
[7] #ghg_read#4(::Bool, ::Function, ::String) at C:\Users\JohnDoe\.julia\v0.6\ClimateDataIO\src\ghg_read.jl:91
[8] (::ClimateDataIO.#kw##ghg_read)(::Array{Any,1}, ::ClimateDataIO.#ghg_read, ::String) at .\<missing>:0
[9] include_from_node1(::String) at .\loading.jl:576
[10] include(::String) at .\sysimg.jl:14
[11] process_options(::Base.JLOptions) at .\client.jl:305
[12] _start() at .\client.jl:371
while loading C:\Users\JohnDoe\.julia\v0.6\ClimateDataIO\test\runtests.jl, in expression starting on line 275
This command removes the folder without errors. It’s the same usage in the module.