diff --git a/src/utils/darwin.jl b/src/utils/darwin.jl index 5672ca6..e490469 100644 --- a/src/utils/darwin.jl +++ b/src/utils/darwin.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index a449662..dc8fe54 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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