diff --git a/Project.toml b/Project.toml index fec4a01..fe8c591 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "HiddenFiles" uuid = "d01c2003-3cc0-4d61-912c-b250feb01c5b" authors = ["Jake Ireland and contributors"] -version = "0.1.2" +version = "0.1.3" [compat] julia = "1" diff --git a/src/HiddenFiles.jl b/src/HiddenFiles.jl index ba0505e..e12f87a 100644 --- a/src/HiddenFiles.jl +++ b/src/HiddenFiles.jl @@ -13,6 +13,9 @@ Check if a file or directory is hidden. On Unix-like systems, a file or directory is hidden if it starts with a full stop/period (`U+002e`). On Windows systems, this function will parse file attributes to determine if the given file or directory is hidden. +!!! note + Directory references (i.e., `.` or `..`) are always hidden. To check if the underlying path is hidden, you should run `ishidden` on its `realpath`. + !!! note On Unix-like systems, in order to correctly determine if the file begins with a full stop, we must first expand the path to its real path. @@ -27,6 +30,7 @@ ishidden include("docs.jl") include("path.jl") + @static if Sys.isunix() include("utils/zfs.jl") if iszfs() # @static breaks here # ZFS @@ -37,8 +41,9 @@ include("path.jl") # Trivial Unix check _isdotfile(f::AbstractString) = startswith(basename(f), '.') + # Check dotfiles, but also account for ZFS - _ishidden_unix(ps::PathStruct) = _isdotfile(ps.realpath) || (iszfs() && _ishidden_zfs("", "")) + _ishidden_unix(ps::PathStruct) = _isdotfile(ps.realpath) || (iszfs() && _ishidden_zfs(ps)) @static if Sys.isbsd() # BDS-related; this is true for macOS as well # https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/chflags.2.html @@ -202,12 +207,16 @@ else end +# Check if the file is actually a directory reference to the current or parent directory +_isdirref(f::AbstractString) = basename(f) ∈ (".", "..") # see issue #24 + + # Each OS branch defines its own _ishidden function. In the main ishidden function, # we check construct our PathStruct object to pass around to the branch's _ishidden # function to use as the function necessitates function ishidden(f::AbstractString) ps = PathStruct(f; err_prefix = :ishidden) - return _ishidden(ps) + return _isdirref(ps.path) || _ishidden(ps) end diff --git a/test/runtests.jl b/test/runtests.jl index 4469e04..1525335 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -131,4 +131,13 @@ using Test # ishidden calls to PathStruct @test_throws Union{Base.IOError, SystemError} ishidden(f) end + + @testset "HiddenFiles.jl—Directory references" begin + d = homedir() + @test HiddenFiles.ishidden(".") + @test HiddenFiles.ishidden(joinpath(d, ".")) + @test HiddenFiles.ishidden(joinpath(d, "..", ".")) + @test HiddenFiles.ishidden("..") + @test HiddenFiles.ishidden(joinpath(d, "..")) + end end