Skip to content

Commit

Permalink
Merge pull request #25 from jakewilliami/fix-dot-behaviour
Browse files Browse the repository at this point in the history
Ensure directory references are hidden
  • Loading branch information
jakewilliami authored Apr 25, 2023
2 parents 72ef5ca + 48a47fe commit f0cf6cf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "HiddenFiles"
uuid = "d01c2003-3cc0-4d61-912c-b250feb01c5b"
authors = ["Jake Ireland <[email protected]> and contributors"]
version = "0.1.2"
version = "0.1.3"

[compat]
julia = "1"
Expand Down
13 changes: 11 additions & 2 deletions src/HiddenFiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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


Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f0cf6cf

Please sign in to comment.