diff --git a/src/FilePathsBase.jl b/src/FilePathsBase.jl index d3d104d..8b44777 100644 --- a/src/FilePathsBase.jl +++ b/src/FilePathsBase.jl @@ -13,6 +13,7 @@ export Path, PosixPath, WindowsPath, + UNCPath, Mode, Status, @@ -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") diff --git a/src/uncpath.jl b/src/uncpath.jl new file mode 100644 index 0000000..19bd864 --- /dev/null +++ b/src/uncpath.jl @@ -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 + + + + + + + diff --git a/test/runtests.jl b/test/runtests.jl index 6f12425..d28deb7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,5 +7,6 @@ using Compat.Test include("mode.jl") include("path.jl") +include("unc.jl") end diff --git a/test/unc.jl b/test/unc.jl new file mode 100644 index 0000000..19e3575 --- /dev/null +++ b/test/unc.jl @@ -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 \ No newline at end of file