Skip to content

Commit

Permalink
Check that MDItemCreate succeeded
Browse files Browse the repository at this point in the history
Addresses #9
  • Loading branch information
jakewilliami committed Aug 29, 2022
1 parent 7af0be2 commit 750cca4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/utils/darwin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ function _cfstring_create_with_cstring(s::AbstractString, encoding::Unsigned = K
end

# https://developer.apple.com/documentation/coreservices/1426917-mditemcreate
function _mditem_create(cstr_f::Cstring)
return ccall(:MDItemCreate, Ptr{UInt32}, (Ptr{Cvoid}, Cstring), C_NULL, cstr_f)
function _mditem_create(cfstr_f::Cstring)
ptr = ccall(:MDItemCreate, Ptr{UInt32}, (Ptr{Cvoid}, Cstring), C_NULL, cfstr_f)
ptr == C_NULL && error("Cannot create MD Item for CF String $(repr(cfstr_f))")
return ptr
end

# https://developer.apple.com/documentation/coreservices/1427080-mditemcopyattribute
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ using Test
@test !HiddenFiles._ispackage_or_bundle("/System/Applications/Utilities/Terminal.app/Contents/")
@test HiddenFiles._exists_inside_package_or_bundle("/System/Applications/Utilities/Terminal.app/Contents/")
@test !HiddenFiles._exists_inside_package_or_bundle("/bin/")
f = String(rand(Char, 32)) # this path shouldn't exist
cfstr = HiddenFiles._cfstring_create_with_cstring(f)
@test_throws Exception HiddenFiles._mditem_create(cfstr)
end
else
@testset "HiddenFiles.jl—UNIX excluding macOS" begin
Expand Down

0 comments on commit 750cca4

Please sign in to comment.