Skip to content
Draft
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
13 changes: 13 additions & 0 deletions src/FilePathsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ Defines an abstract filesystem path.
"""
abstract type AbstractPath end # Define the AbstractPath here to avoid circular include dependencies

# whether path is a key-value store or true file system
abstract type DirectoriesType end
struct DirectoriesExplicit <: DirectoriesType end
struct DirectoriesImplicit <: DirectoriesType end

# whether path supports permissions
abstract type PermissionsType end
struct HasPermissions <: PermissionsType end
struct NoPermissions <: PermissionsType end

directoriestype(::Type{<:AbstractPath}) = DirectoriesExplicit()
permissionstype(::Type{<:AbstractPath}) = NoPermissions()

"""
register(::Type{<:AbstractPath})

Expand Down
7 changes: 6 additions & 1 deletion src/path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,13 @@ julia> created(p"src/FilePathsBase.jl")
```
"""
created(fp::AbstractPath) = stat(fp).ctime
Base.isdir(fp::AbstractPath) = isdir(mode(fp))

Base.isdir(fp::AbstractPath) = isdir(directoriestype(fp), fp)
Base.isdir(::DirectoriesExplicit, fp::AbstractPath) = isdir(mode(fp))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the assumption is that if I have:

directoriestype(::Type{MyPath}) = DirectoriesImplicit()

Then I also need to implement Base.isdir(::DirectoriesImplicit, fp::MyPath)? So the benefit is just when you throw the MethodError... or are we expecting folks to extend DirectoriesType with some shared logic that could be shared with multiple key-value path types?


Base.isfile(fp::AbstractPath) = isfile(mode(fp))

#TODO: most of these clearly only make sense on local FS, should they have traits?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having a trait for this is a very good idea if the primary goal is to more cleanly fail for unsupported functionality. This could still get weird in the sense that S3Paths do still have permissions, but they work differently.

Base.islink(fp::AbstractPath) = islink(lstat(fp).mode)
Base.issocket(fp::AbstractPath) = issocket(mode(fp))
Base.isfifo(fp::AbstractPath) = issocket(mode(fp))
Expand Down
2 changes: 2 additions & 0 deletions src/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ methods that wrap base functionality.
"""
abstract type SystemPath <: AbstractPath end

permissionstype(::Type{<:SystemPath}) = HasPermissions()

Path() = @static Sys.isunix() ? PosixPath() : WindowsPath()
Path(pieces::Tuple{Vararg{String}}) =
@static Sys.isunix() ? PosixPath(pieces) : WindowsPath(pieces)
Expand Down