Skip to content

Commit

Permalink
Check that MDItemCopyAttribute succeeded
Browse files Browse the repository at this point in the history
Addresses #9
  • Loading branch information
jakewilliami committed Aug 29, 2022
1 parent ddcbd9b commit 4848dab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/utils/darwin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ end

# https://developer.apple.com/documentation/coreservices/1427080-mditemcopyattribute
function _mditem_copy_attribute(mditem::Ptr{UInt32}, cfstr_attr_name::Cstring)
return ccall(:MDItemCopyAttribute, Ptr{UInt32}, (Ptr{UInt32}, Cstring), mditem, cfstr_attr_name)
ptr = ccall(:MDItemCopyAttribute, Ptr{UInt32}, (Ptr{UInt32}, Cstring), mditem, cfstr_attr_name)
ptr == C_NULL && error("Cannot copy MD Item attribute $(repr(cfstr_attr_name)); this attribute name might not exist")
return ptr
end

# https://developer.apple.com/documentation/corefoundation/1388772-cfarraygetcount
Expand Down
11 changes: 8 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ using Test
@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)
@test_throws Exception HiddenFiles._cfstring_create_with_cstring("Julia", 0x1c000101) # this encoding mode should not exist
cfstr_nonexistent = HiddenFiles._cfstring_create_with_cstring(f)
@test_throws Exception HiddenFiles._mditem_create(cfstr_nonexistent)
encoding_mode_nonexistent = 0x1c000101 # this encoding mode should not exist
@test_throws Exception HiddenFiles._cfstring_create_with_cstring("Julia", encoding_mode_nonexistent)
cfstr = HiddenFiles._cfstring_create_with_cstring(@__FILE__)
mditem = HiddenFiles._mditem_create(cfstr)
cfattr_nonexistent = HiddenFiles._cfstring_create_with_cstring("kMDItemNonexistentAttributeName")
@test_throws Exception HiddenFiles._mditem_copy_attribute(mditem, cfattr_nonexistent)
end
else
@testset "HiddenFiles.jl—UNIX excluding macOS" begin
Expand Down

0 comments on commit 4848dab

Please sign in to comment.