From b9bbf3a15fd9162fecef160c5c32d1628014671b Mon Sep 17 00:00:00 2001 From: Expanding Man Date: Tue, 25 Jan 2022 18:37:42 -0500 Subject: [PATCH] experimental traits to more cleanly extend to key-value stores --- src/FilePathsBase.jl | 13 +++++++++++++ src/path.jl | 7 ++++++- src/system.jl | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/FilePathsBase.jl b/src/FilePathsBase.jl index d3b35d1..21d15a1 100644 --- a/src/FilePathsBase.jl +++ b/src/FilePathsBase.jl @@ -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}) diff --git a/src/path.jl b/src/path.jl index 62f8e8d..3c56394 100644 --- a/src/path.jl +++ b/src/path.jl @@ -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)) + Base.isfile(fp::AbstractPath) = isfile(mode(fp)) + +#TODO: most of these clearly only make sense on local FS, should they have traits? Base.islink(fp::AbstractPath) = islink(lstat(fp).mode) Base.issocket(fp::AbstractPath) = issocket(mode(fp)) Base.isfifo(fp::AbstractPath) = issocket(mode(fp)) diff --git a/src/system.jl b/src/system.jl index ffc38d9..5dc2658 100644 --- a/src/system.jl +++ b/src/system.jl @@ -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)