Skip to content
Merged
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
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
- 1.0
- nightly
notifications:
Expand All @@ -15,7 +13,6 @@ matrix:
after_success:
- |
julia -e '
VERSION >= v"0.7.0-DEV.3656" && using Pkg
VERSION >= v"0.7.0-DEV.5183" || cd(Pkg.dir("FilePathsBase"))
using Pkg;
Pkg.add("Coverage"); using Coverage
Codecov.submit(process_folder())'
3 changes: 1 addition & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
julia 0.6
Compat 1.0.0
julia 0.7
2 changes: 0 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
environment:
matrix:
- julia_version: 0.6
- julia_version: 0.7
- julia_version: 1
- julia_version: latest

Expand Down
15 changes: 6 additions & 9 deletions src/FilePathsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ __precompile__()

module FilePathsBase

using Compat

using Compat.Printf, Compat.LinearAlgebra, Compat.Dates
using Dates
using LinearAlgebra
using Printf

import Base: ==
export
Expand Down Expand Up @@ -56,11 +56,8 @@ export
WRITE,
EXEC

@static if VERSION < v"0.6.0-dev.2514"
import Base: isexecutable
else
export isexecutable
end

export isexecutable

const PATH_TYPES = DataType[]

Expand All @@ -87,7 +84,7 @@ function register(T::Type{<:AbstractPath})
# We add the type to the beginning of our PATH_TYPES,
# so that they can take precedence over the Posix and
# Windows paths.
Compat.pushfirst!(PATH_TYPES, T)
pushfirst!(PATH_TYPES, T)
end

#=
Expand Down
16 changes: 8 additions & 8 deletions src/libc.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@static if Compat.Sys.isapple()
@static if Sys.isapple()
struct Cpasswd
pw_name::Cstring
pw_passwd::Cstring
Expand All @@ -12,7 +12,7 @@
pw_expire::Cint
pw_fields::Cint
end
elseif Compat.Sys.islinux()
elseif Sys.islinux()
struct Cpasswd
pw_name::Cstring
pw_passwd::Cstring
Expand Down Expand Up @@ -67,7 +67,7 @@ function Base.show(io::IO, user::User)
end

function User(name::String)
ps = @static if Compat.Sys.isunix()
ps = @static if Sys.isunix()
ccall(:getpwnam, Ptr{Cpasswd}, (Ptr{UInt8},), name)
else
Cpasswd()
Expand All @@ -77,7 +77,7 @@ function User(name::String)
end

function User(uid::UInt)
ps = @static if Compat.Sys.isunix()
ps = @static if Sys.isunix()
ccall(:getpwuid, Ptr{Cpasswd}, (UInt64,), uid)
else
Cpasswd()
Expand All @@ -87,7 +87,7 @@ function User(uid::UInt)
end

function User()
uid = @static Compat.Sys.isunix() ? ccall(:geteuid, Cint, ()) : 0
uid = @static Sys.isunix() ? ccall(:geteuid, Cint, ()) : 0
User(UInt64(uid))
end

Expand All @@ -105,7 +105,7 @@ function Base.show(io::IO, group::Group)
end

function Group(name::String)
ps = @static if Compat.Sys.isunix()
ps = @static if Sys.isunix()
ccall(:getgrnam, Ptr{Cgroup}, (Ptr{UInt8},), name)
else
Cgroup()
Expand All @@ -115,7 +115,7 @@ function Group(name::String)
end

function Group(gid::UInt)
gr = @static if Compat.Sys.isunix()
gr = @static if Sys.isunix()
ccall(:getgrgid, Ptr{Cgroup}, (UInt64,), gid)
else
Cgroup()
Expand All @@ -125,6 +125,6 @@ function Group(gid::UInt)
end

function Group()
gid = @static Compat.Sys.isunix() ? ccall(:getegid, Cint, ()) : 0
gid = @static Sys.isunix() ? ccall(:getegid, Cint, ()) : 0
Group(UInt64(gid))
end
75 changes: 47 additions & 28 deletions src/path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
Responsible for creating the appropriate platform specific path
(e.g., `PosixPath` and `WindowsPath` for Unix and Windows systems respectively)
"""
Path() = @static Compat.Sys.isunix() ? PosixPath() : WindowsPath()
Path() = @static Sys.isunix() ? PosixPath() : WindowsPath()
Path(path::AbstractPath) = path
Path(pieces::Tuple{Vararg{String}}) =
@static Compat.Sys.isunix() ? PosixPath(pieces) : WindowsPath(pieces)
@static Sys.isunix() ? PosixPath(pieces) : WindowsPath(pieces)

# May want to support using the registry for other constructors as well
function Path(str::AbstractString; debug=false)
types = filter(t -> ispathtype(t, str), PATH_TYPES)

if length(types) > 1
Compat.@debug(
@debug(
string(
"Found multiple path types that match the string specified ($types). ",
"Please use a specific constructor if $(first(types)) is not the correct type."
Expand Down Expand Up @@ -51,12 +51,8 @@ of the file containing the macro. Returns an empty Path if run from a REPL or
if evaluated by julia -e <expr>.
"""
macro __PATH__()
if VERSION >= v"0.7-"
p = Path(dirname(string(__source__.file)))
return p===nothing ? :(Path()) : :($p)
else
return :(Path(@__DIR__()===nothing ? Path() : @__DIR__))
end
p = Path(dirname(string(__source__.file)))
return p === nothing ? :(Path()) : :($p)
end

"""
Expand All @@ -67,12 +63,8 @@ containing the macro. Returns an empty Path if run from a REPL or if
evaluated by julia -e <expr>.
"""
macro __FILEPATH__()
if VERSION >= v"0.7-"
p = Path(string(__source__.file))
return p===nothing ? :(Path()) : :($p)
else
return :(Path(@__FILE__()===nothing ? Path() : @__FILE__))
end
p = Path(string(__source__.file))
return p === nothing ? :(Path()) : :($p)
end

"""
Expand All @@ -82,12 +74,8 @@ Construct an absolute path to `filespec` relative to the source file
containing the macro call.
"""
macro LOCAL(filespec)
if VERSION >= v"0.7-"
p = join(Path(dirname(string(__source__.file))), Path(filespec))
return :($p)
else
return :(join(@__PATH__, Path($(esc(filespec)))))
end
p = join(Path(dirname(string(__source__.file))), Path(filespec))
return :($p)
end

#=
Expand Down Expand Up @@ -144,6 +132,39 @@ function parents(path::T) where {T <: AbstractPath}
end
end

"""
*(a::T, b::Union{T, AbstractString, AbstractChar}...) where {T <: AbstractPath} -> T

Concatenate paths, strings and/or characters, producing a new path.
This is equivalent to concatenating the string representations of paths and other strings
and then constructing a new path.

# Example

julia> p"foo" * "bar"
p"foobar"
"""
function Base.:(*)(a::T, b::Union{T, AbstractString, AbstractChar}...) where T <: AbstractPath
T(*(string(a), string.(b)...))
end

"""
/(a::AbstractPath, b::Union{AbstractPath, AbstractString}...) -> AbstractPath

Join the path components into a new fulll path, equivalent to calling `joinpath`

# Example

julia> p"foo" / "bar"
p"foo/bar"

julia> p"foo" / "bar" / "baz"
p"foo/bar/baz"
"""
function Base.:(/)(root::AbstractPath, pieces::Union{AbstractPath, AbstractString}...)
join(root, pieces...)
end

"""
join(root::AbstractPath, pieces::Union{AbstractPath, AbstractString}...) -> AbstractPath

Expand Down Expand Up @@ -263,7 +284,7 @@ Base.real(path::AbstractPath) = Path(realpath(string(path)))

Normalizes a path by removing "." and ".." entries.
"""
function Compat.LinearAlgebra.norm(path::T) where {T <: AbstractPath}
function LinearAlgebra.norm(path::T) where {T <: AbstractPath}
p = parts(path)
result = String[]
rem = length(p)
Expand Down Expand Up @@ -322,7 +343,7 @@ function relative(path::T, start::T=T(".")) where {T <: AbstractPath}
i = 0
while i < min(length(p), length(s))
i += 1
@static if Compat.Sys.iswindows()
@static if Sys.iswindows()
if lowercase(p[i]) != lowercase(s[i])
i -= 1
break
Expand Down Expand Up @@ -495,9 +516,7 @@ function Base.mkdir(path::AbstractPath; mode=0o777, recursive=false, exist_ok=fa
end
end


VERSION >= v"0.7-" ? mkdir(string(path), mode=mode) : mkdir(string(path), mode)

mkdir(string(path), mode=mode)
end
end

Expand Down Expand Up @@ -562,7 +581,7 @@ function move(src::AbstractPath, dest::AbstractPath; recursive=false, exist_ok=f
end

function Base.cp(src::AbstractPath, dest::AbstractPath; force::Bool=false, follow_symlinks::Bool=false)
Compat.cp(string(src), string(dest); force=force, follow_symlinks=follow_symlinks)
cp(string(src), string(dest); force=force, follow_symlinks=follow_symlinks)
end

remove(path::AbstractPath; recursive=false) = rm(string(path); recursive=recursive)
Expand Down Expand Up @@ -603,7 +622,7 @@ end
Change the `user` and `group` of the `path`.
"""
function Base.chown(path::AbstractPath, user::AbstractString, group::AbstractString; recursive=false)
@static if Compat.Sys.isunix()
@static if Sys.isunix()
chown_cmd = String["chown"]
if recursive
push!(chown_cmd, "-R")
Expand Down
2 changes: 1 addition & 1 deletion src/posix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end
# The following should be implemented in the concrete types
==(a::PosixPath, b::PosixPath) = parts(a) == parts(b)
parts(path::PosixPath) = path.parts
ispathtype(::Type{PosixPath}, str::AbstractString) = Compat.Sys.isunix()
ispathtype(::Type{PosixPath}, str::AbstractString) = Sys.isunix()

function isabs(path::PosixPath)
if parts(path)[1] == POSIX_PATH_SEPARATOR
Expand Down
2 changes: 1 addition & 1 deletion src/status.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Compat.Dates
using Dates

import Base.Filesystem: StatStruct

Expand Down
2 changes: 1 addition & 1 deletion src/windows.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ end
parts(path::WindowsPath) = path.parts
drive(path::WindowsPath) = path.drive
root(path::WindowsPath) = path.root
ispathtype(::Type{WindowsPath}, str::AbstractString) = Compat.Sys.iswindows()
ispathtype(::Type{WindowsPath}, str::AbstractString) = Sys.iswindows()

function Base.show(io::IO, path::WindowsPath)
print(io, "p\"")
Expand Down
11 changes: 7 additions & 4 deletions test/path.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

cd(abs(parent(Path(@__FILE__)))) do
@testset "Simple Path Usage" begin
reg = Compat.Sys.iswindows() ? "..\\src\\FilePathsBase.jl" : "../src/FilePathsBase.jl"
reg = Sys.iswindows() ? "..\\src\\FilePathsBase.jl" : "../src/FilePathsBase.jl"
@test ispath(reg)

p = Path(reg)
Expand All @@ -20,6 +20,9 @@ cd(abs(parent(Path(@__FILE__)))) do
@test basename(p) == "FilePathsBase.jl"
@test join(parent(p), Path(basename(p))) == p
@test joinpath(parent(p), Path(basename(p))) == p
@test parent(p) / basename(p) == p
@test parent(p) * "/" * basename(p) == p
@test p"foo" / "bar" * ".txt" == p"foo/bar.txt"
@test filename(p) == "FilePathsBase"

@test extension(p) == "jl"
Expand All @@ -36,7 +39,7 @@ cd(abs(parent(Path(@__FILE__)))) do
# This works around an issue with Base.relpath: that function does not take
# into account the paths on Windows should be compared case insensitive.
homedir_patched = homedir()
if Compat.Sys.iswindows()
if Sys.iswindows()
conv_f = isuppercase(abspath(string(p))[1]) ? uppercase : lowercase
homedir_patched = conv_f(homedir_patched[1]) * homedir_patched[2:end]
end
Expand Down Expand Up @@ -135,7 +138,7 @@ mktmpdir() do d
println(io)
end

@static if Compat.Sys.isunix()
@static if Sys.isunix()
if haskey(ENV, "USER")
if ENV["USER"] == "root"
chown(p"newfile", "nobody", "nogroup"; recursive=true)
Expand All @@ -147,7 +150,7 @@ mktmpdir() do d
@test_throws ErrorException chown(p"newfile", "nobody", "nogroup"; recursive=true)
end

@static if Compat.Sys.isunix()
@static if Sys.isunix()
chmod(p"newfile", user=(READ+WRITE+EXEC), group=(READ+EXEC), other=READ)
@test string(mode(p"newfile")) == "-rwxr-xr--"
@test isexecutable(p"newfile")
Expand Down
5 changes: 2 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Compat
using FilePathsBase
using Compat.LinearAlgebra
using Compat.Test
using LinearAlgebra
using Test

include("testpaths.jl")

Expand Down