Skip to content

Commit

Permalink
Merge pull request #8 from pfitzseb/sp/normalized
Browse files Browse the repository at this point in the history
make sure path is actually normalized in all regards
  • Loading branch information
shashi committed Sep 12, 2018
2 parents 5beb191 + 7739c34 commit 31a2ae3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/AssetRegistry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ filekey(key) = key[length(baseurl[])+1:end]
"""
register("path/to/asset")
Register an asset. Returns a unique key which is
the unique URL where the asset can be accessed.
Register an asset. Returns a unique key which is
the unique URL where the asset can be accessed.
For example:
```julia
Expand All @@ -26,8 +26,8 @@ julia> key = AssetRegistry.register("/Users/ranjan/.julia/v0.6/Tachyons/assets/t
```
"""
function register(path; registry_file = joinpath(homedir(), ".jlassetregistry.json"))
target = abspath(path)
(isfile(target) || isdir(target)) ||
target = normpath(abspath(expanduser(path)))
(isfile(target) || isdir(target)) ||
error("Asset not found")

key = getkey(target)
Expand Down Expand Up @@ -74,7 +74,7 @@ function register(path; registry_file = joinpath(homedir(), ".jlassetregistry.js
end

function deregister(path; registry_file = joinpath(homedir(), ".jlassetregistry.json"))
target = abspath(path)
target = normpath(abspath(expanduser(path)))

key = getkey(target)
if !haskey(registry, key)
Expand Down
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ using JSON
@test !AssetRegistry.isregistered(pwd())
@test JSON.parse(String(read(joinpath(homedir(), ".jlassetregistry.json")))) == Dict()
end

@testset "register for not normalized paths" begin
path = joinpath(pwd(), "..", "src")
key = AssetRegistry.register(path)
@test startswith(key, ENV["JULIA_ASSETREGISTRY_BASEURL"])
@test key == AssetRegistry.getkey(path)
@test AssetRegistry.isregistered(path)
@test JSON.parse(String(read(joinpath(homedir(), ".jlassetregistry.json")))) == Dict(AssetRegistry.filekey(key) => [normpath(path), 1])
AssetRegistry.deregister(path)
@test !AssetRegistry.isregistered(path)
@test JSON.parse(String(read(joinpath(homedir(), ".jlassetregistry.json")))) == Dict()
end

0 comments on commit 31a2ae3

Please sign in to comment.