Skip to content

Commit 080efaa

Browse files
authored
Merge pull request #80 from JuliaIO/teh/abspath
Store the absolute path when querying or opening a Stream
2 parents c38ef5a + f7261e7 commit 080efaa

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/query.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,10 @@ function file!{F}(strm::Stream{F})
279279
end
280280

281281
# Implement standard I/O operations for File and Stream
282-
@inline Base.open(file::File, args...) = Stream(file, open(filename(file), args...))
282+
@inline function Base.open{F<:DataFormat}(file::File{F}, args...)
283+
fn = filename(file)
284+
Stream(F, open(fn, args...), abspath(fn))
285+
end
283286
Base.close(s::Stream) = close(stream(s))
284287

285288
Base.position(s::Stream) = position(stream(s))
@@ -369,7 +372,7 @@ function query(filename::AbstractString)
369372
end
370373
!isfile(filename) && return File{unknown_df}(filename) # (no extension || no magic byte) && no file
371374
# Otherwise, check the magic bytes
372-
file!(query(open(filename), filename))
375+
file!(query(open(filename), abspath(filename)))
373376
end
374377

375378
lensym(s::Symbol) = 1

test/loadsave.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ context("Save") do
9292
fn = string(tempname(), ".dmy")
9393
save(fn, a)
9494

95+
# Test for absolute paths
96+
cd(dirname(fn)) do
97+
fnrel = basename(fn)
98+
f = query(fnrel)
99+
@fact isabspath(filename(f)) --> true
100+
@fact endswith(filename(f), fn) --> true # TravisOSX prepends "/private"
101+
f = File(format"DUMMY", fnrel)
102+
@fact isabspath(filename(f)) --> false
103+
open(f) do s
104+
@fact isabspath(get(filename(s))) --> true
105+
@fact endswith(get(filename(s)), fn) --> true
106+
end
107+
end
108+
109+
# Test IO
95110
b = load(query(fn))
96111
@fact a --> b
97112

0 commit comments

Comments
 (0)