User’s home folders are not being seen as actual folders

Running a MacOS Intel app from XCode 14.1, trying to access the user’s home folders, in this case, the ~/Downloads folder.

I get

directoryEnumerator error at file:///Users/maurice/Library/Containers/com.utilitybeltsoftware.icloudstatus2/Data/Downloads/: Error Domain=NSCocoaErrorDomain Code=256 "The file “Downloads” couldn’t be opened." UserInfo={NSURL=file:///Users/maurice/Library/Containers/com.utilitybeltsoftware.icloudstatus2/Data/Downloads/, NSFilePath=/Users/maurice/Library/Containers/com.utilitybeltsoftware.icloudstatus2/Data/Downloads, NSUnderlyingError=0x6000011b2880 {Error Domain=NSPOSIXErrorDomain Code=20 "Not a directory"}}

If I cd to this location, I do get access to the ~/Downloads folder, so the error is not telling the truth.

Here is my entitlements plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>com.apple.security.app-sandbox</key>
	<true/>
	<key>com.apple.security.files.downloads.read-only</key>
	<true/>
	<key>com.apple.security.temporary-exception.files.home-relative-path.read-only</key>
	<array>
		<string>/Documents/</string>
		<string>/Desktop/</string>
	</array>
	<key>com.apple.security.files.user-selected.read-only</key>
	<true/>
</dict>
</plist>

By the way, I don’t get prompted to grant access to the app and that seems suspicious.

In a typical sandboxed app, the Downloads ‘directory’ in your container is actually a symlink to ~/Downloads. Consider:

% ls -l ~/Library/Containers/uk.co.tla-systems.pcalc/Data/Downloads
lrwxr-xr-x  1 quinn  staff  21  2 May  2020 /Users/quinn/Library/Containers/uk.co.tla-systems.pcalc/Data/Downloads -> ../../../../Downloads

I’m not sure how you’re trying to enumerate this directory, but I suspect that it’s not following the symlink.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I tried it two ways,

let documentsURL = try fileManager.url(for: .downloadsDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
// and
let path    = NSSearchPathForDirectoriesInDomains(.downloadsDirectory, .userDomainMask, true)[0] as String
let documentsURL     = URL(fileURLWithPath: path)

I think I got it, I needed to add this

let dest = documentsURL.resolvingSymlinksInPath()

Thanks.

User’s home folders are not being seen as actual folders
 
 
Q