So Apple is starting to require declaration when using some APIs that can be used to fingerprint users. I've got a Kotlin Multiplatform library that I use that I think is triggering their NSPrivacyAccessedAPICategoryFileTimestamp enforcement. I've got the following code which retrieves all the attributes of a file just to check if the file size exceeds a threshold (before we roll-over to a separate file).
private fun canWrite(): Boolean {
val filePath = "$folder/$file"
if (file == null || !NSFileManager.defaultManager.fileExistsAtPath(filePath)) {
return false
}
val attr: Map<Any?, *>? = NSFileManager.defaultManager.attributesOfItemAtPath(filePath, null)
if (attr == null || attr.isEmpty()) {
return false
}
val fileSize = attr[NSFileSize] as Long
return fileSize < maxFileSize
}
I guess attributesOfItemAtPath() is doing a getAttrList() in the background, which Apple documents as getting flagged by this check. I know that I can just declare this as a legitimate use of the API, but I really don't need everything else that comes back from an attribute list, I only care about the file size. Is there a better method I could use? All the examples I can find online just use attributesOfItemAtPath without a care and pre-date the privacy disclosures from Apple.