Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add first version of UNCPath #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/FilePathsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export
Path,
PosixPath,
WindowsPath,
UNCPath,
Mode,
Status,

Expand Down Expand Up @@ -89,6 +90,7 @@ include("mode.jl")
include("status.jl")
include("posix.jl")
include("windows.jl")
include("uncpath.jl")
include("path.jl")
include("deprecates.jl")

Expand Down
71 changes: 71 additions & 0 deletions src/uncpath.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
struct UNCPath <: AbstractPath
parts::Tuple{Vararg{String}}
end

UNC_PATH_START = "\\\\"

UNCPath() = UNCPath(tuple())

function UNCPath(str::AbstractString)
if isempty(str)
return UNCPath(tuple())
end

if startswith(str, "\\\\")
tokenized = split(str, WIN_PATH_SEPARATOR)

return UNCPath(tuple(UNC_PATH_START, String.(tokenized[3:end])...))
else
error("UNC path not formatted correctly.")
end
end

==(a::UNCPath, b::UNCPath) = lowercase.(parts(a)) == lowercase.(parts(b))

function Base.String(path::UNCPath)
if parts(path)[1] == UNC_PATH_START
return UNC_PATH_START * joinpath(parts(path)[2:end]...)
else
return joinpath(parts(path)...)
end
end

parts(path::UNCPath) = path.parts

function Base.show(io::IO, path::UNCPath)
print(io, "p\"")
if isabs(path)
print(io, join(parts(path)[2:end], "/"))
else
print(io, join(parts(path), "/"))
end
print(io, "\"")

end

function isabs(path::UNCPath)
if parts(path)[1] == UNC_PATH_START
return true
else
return false
end
end

drive(path::UNCPath) = ""

function root(path::UNCPath)
if parts(path)[1] == UNC_PATH_START
return UNC_PATH_START
else
return ""
end
end

# expanduser(path::UNCPath) = path







1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ using Compat.Test

include("mode.jl")
include("path.jl")
include("unc.jl")

end
11 changes: 11 additions & 0 deletions test/unc.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cd(abs(parent(Path(@__FILE__)))) do
@testset "UNC Path Usage" begin

p1 = UNCPath(tuple(["\\\\", "foo", "bar"]...))
@test p1.parts == ("\\\\", "foo", "bar")

p2 = UNCPath(tuple(["foo", "bar"]...))
@test p2.parts == ("foo", "bar")

end
end