diff --git a/src/common.jl b/src/common.jl index ac61508..5ef770c 100644 --- a/src/common.jl +++ b/src/common.jl @@ -39,26 +39,28 @@ function modgroup(prop::Symbol, mats::Union{Nothing,Vector{<:AbstractString}}) prop in keys(MATRIXCLASS) && daterr("$prop can not be modified.") user = abspath(user_dir(), "group.jl") - s = read(user, String) # read complete file into s - rg = Regex(repr(prop) * r"\W*=>\W*(\[.*\]\W*,\W*\n)".pattern) - ppos = findfirst(rg, s) # locate the prop in user.jl to remove. - if ppos !== nothing - start_char = first(ppos) - 1 # the start of the line - end_char = last(ppos) # the end of the line - else - ppos = findnext(r"\);", s, 1) - start_char = ppos !== nothing ? first(ppos) - 1 : length(s) - end_char = start_char - end - if mats !== nothing - mats = sort(mats) - end - open(user, "w") do io - write(io, s[1:start_char]) + if isfile(user) + s = read(user, String) # read complete file into s + rg = Regex(repr(prop) * r"\W*=>\W*(\[.*\]\W*,\W*\n)".pattern) + ppos = findfirst(rg, s) # locate the prop in user.jl to remove. + if ppos !== nothing + start_char = first(ppos) - 1 # the start of the line + end_char = last(ppos) # the end of the line + else + ppos = findnext(r"\);", s, 1) + start_char = ppos !== nothing ? first(ppos) - 1 : length(s) + end_char = start_char + end if mats !== nothing - propline(io, prop, mats) + mats = sort(mats) + end + open(user, "w") do io + write(io, s[1:start_char]) + if mats !== nothing + propline(io, prop, mats) + end + write(io, s[end_char+1:end]) end - write(io, s[end_char+1:end]) end if mats !== nothing usermatrixclass[prop] = mats diff --git a/src/download.jl b/src/download.jl index f1736f5..6d0d4dd 100644 --- a/src/download.jl +++ b/src/download.jl @@ -111,14 +111,19 @@ function gunzip(fname) destname = rsplit(fname, ".gz", limit=2)[1] BUFFSIZE = 1000000 - open(destname, "w") do f - open(GzipDecompressorStream, fname) do g - buffer = read(g, BUFFSIZE) - while length(buffer) > 0 - write(f, buffer) + try + open(destname, "w") do f + open(GzipDecompressorStream, fname) do g buffer = read(g, BUFFSIZE) + while length(buffer) > 0 + write(f, buffer) + buffer = read(g, BUFFSIZE) + end end end + catch + @warn "decompression error - file $destname set to empty." + open(destname, "w") do f; end end destname end @@ -142,6 +147,7 @@ function loadmatrix(data::RemoteMatrixData) dirfn = localfile(data) dir = dirname(localdir(data)) url = redirect(dataurl(data)) + tarfile = "" isdir(dir) || mkpath(dir) wdir = pwd() @@ -155,6 +161,8 @@ function loadmatrix(data::RemoteMatrixData) run(`tar -xf $rfile`) rm(tarfile; force=true) end + catch + finally cd(wdir) rm(dirfn, force=true) diff --git a/src/logical.jl b/src/logical.jl index 395f5b0..9af6627 100644 --- a/src/logical.jl +++ b/src/logical.jl @@ -109,13 +109,13 @@ isreal(data::MatrixData) = false isinteger(data::MatrixData) = false isboolean(data::MatrixData) = false -hasinfo(data::RemoteMatrixData) = data.header.m > 0 && data.header.n > 0 +hasinfo(data::RemoteMatrixData) = data.header.m > 0 && data.header.n > 0 # isassigned(data.properties) && data.properties[] !== nothing hasinfo(data::MatrixData) = false isremote(data::RemoteMatrixData) = true isremote(data::MatrixData) = false -isloaded(data::RemoteMatrixData) = !isempty(data.metadata) +isloaded(data::RemoteMatrixData) = hasinfo(data) && !isempty(data.metadata) isloaded(data::MatrixData) = false -isunloaded(data::RemoteMatrixData) = isempty(data.metadata) +isunloaded(data::RemoteMatrixData) = !isloaded(data) isunloaded(data::MatrixData) = false isuser(data::GeneratedMatrixData{:U}) = true isuser(data::MatrixData) = false diff --git a/src/matrixmarket.jl b/src/matrixmarket.jl index c73c39b..f532210 100644 --- a/src/matrixmarket.jl +++ b/src/matrixmarket.jl @@ -9,6 +9,9 @@ They may be converted to numerical types by multiplying with a number. """ function mmread(filename::AbstractString) open(filename, "r") do file + if stat(file).size == 0 + throw(DataError("matrix file $filename is empty")) + end mmread(file) end end @@ -258,6 +261,9 @@ Read header information from mtx file. function mmreadheader(file::AbstractString) if isfile(file) open(file) do io + if stat(io).size == 0 + return nothing + end line = lowercase(readline(io)) while true token = split(line) diff --git a/test/common.jl b/test/common.jl index 253436a..5d3fdce 100644 --- a/test/common.jl +++ b/test/common.jl @@ -33,14 +33,14 @@ REM = length(mdlist("*/*")) @test REM >= 2500 #@test REM in [2757, 2856] # depends on whether UFL or TAMU url has been used @test length(mdlist(:builtin)) == 59 -@test length(mdlist(:user)) in [0, 1] +@test mdlist(:user) == String["randorth", "randsym"] @test mdlist("") == [] @test mdlist("HB/1138_bus") == ["HB/1138_bus"] @test mdlist(sp(1)) == ["HB/1138_bus"] @test mdlist(mm(1)) == ["Harwell-Boeing/psadmit/1138_bus"] -@test sort(mdlist(sp(1:3000))) == mdlist("*/*") -@test sort(mdlist(mm(1:3000))) == mdlist("*/*/*") +@test sort(mdlist(sp(:))) == mdlist("*/*") +@test sort(mdlist(mm(1:1000))) == mdlist("*/*/*") @test mdlist(builtin(:)) == mdlist(isbuiltin) @test mdlist(user(:)) == mdlist(isuser) @test mdlist("*") == mdlist(islocal) diff --git a/test/data/math.nist.gov/pub/MatrixMarket2/Harwell-Boeing/cegb/cegb2802.mtx.gz b/test/data/math.nist.gov/pub/MatrixMarket2/Harwell-Boeing/cegb/cegb2802.mtx.gz new file mode 100644 index 0000000..bd7fcf7 --- /dev/null +++ b/test/data/math.nist.gov/pub/MatrixMarket2/Harwell-Boeing/cegb/cegb2802.mtx.gz @@ -0,0 +1,15 @@ + +
+/pub/MatrixMarket2/Harwell-Boeing/cegb/cegb2802.mtx.gz
) could not be found on this server.
+However, we found documents with names similar to the one you requested.Available documents: +