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

WIP: Support absolute/relative and file/directory types #80

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
35 changes: 31 additions & 4 deletions src/FilePathsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export
SystemPath,
PosixPath,
WindowsPath,
FilePath,
DirectoryPath,
RelativePath,
AbsolutePath,
Mode,
Status,
FileBuffer,
Expand Down Expand Up @@ -68,15 +72,24 @@ export

export isexecutable

const PATH_TYPES = DataType[]
const PATH_TYPES = Type[]

function __init__()
register(PosixPath)
register(WindowsPath)
end

abstract type Form end
struct Abs <: Form end
struct Rel <: Form end

abstract type Kind end
struct Dir <: Kind end
struct File <: Kind end
# Could choose to extend this with Symlink?

"""
AbstractPath
AbstractPath{F<:Form, K<:Kind}

Defines an abstract filesystem path.

Expand All @@ -98,7 +111,15 @@ Defines an abstract filesystem path.
- `rm(path::T; kwags...)` - Remove a file or directory
- `readdir(path::T)` - Scan all files and directories at a specific path level
"""
abstract type AbstractPath end # Define the AbstractPath here to avoid circular include dependencies
abstract type AbstractPath{F<:Form, K<:Kind} end # Define the AbstractPath here to avoid circular include dependencies

# A couple utility methods to extract the form and kind from a type.
form(fp::AbstractPath{F}) where {F<:Form} = F
kind(fp::AbstractPath{F, K}) where {F<:Form, K<:Kind} = K
function fptype(fp::AbstractPath)
i = findfirst(T -> fp isa T, PATH_TYPES)
return PATH_TYPES[i]
end

"""
register(::Type{<:AbstractPath})
Expand All @@ -120,6 +141,12 @@ Return a boolean as to whether the string `x` fits the specified the path type.
"""
function ispathtype end

# define some aliases for parameterized abstract paths
const AbsolutePath = AbstractPath{Abs}
const RelativePath = AbstractPath{Rel}
const FilePath = AbstractPath{<:Form, File}
const DirectoryPath = AbstractPath{<:Form, Dir}

include("constants.jl")
include("utils.jl")
include("libc.jl")
Expand All @@ -128,9 +155,9 @@ include("status.jl")
include("buffer.jl")
include("path.jl")
include("aliases.jl")
include("system.jl")
include("posix.jl")
include("windows.jl")
include("system.jl")
include("test.jl")
include("deprecates.jl")

Expand Down
Loading