freeSpace from getFSInfo() does not match actual free space on device
Issue : freeSpace from getFSInfo() does not match actual free space on device
Device Info OS : iOS Device : Any ios device
@genki @Empact @javache @cpunion @af @
I bumped into this same issue. This library uses attributesOfFileSystemForPath and gets the key NSFileSystemFreeSize to get the free storage. Although, Apple suggests another way to get this info.
What seems to happen is that iOS manages some files from the filesystem, deleting or uploading them to cloud to free some space if necessary. So, for example, if an iPhone has X GB's of free storage, and it has 50GBs of "ephemeral" files, the total free space is "X + 50". The iPhone "Settings" app actually reports "X + 50", and this lib reports only "X".
By using Apple's suggested method to get free space (resourceValues(forKeys: [...]), we can use three keys:
- NSURLVolumeAvailableCapacityKey, which returns the actual free space in the file system without any management from the OS, should return
Xin our example. - NSURLVolumeAvailableCapacityForImportantUsageKey, which returns what is reported by the Settings app,
X + 50in our example. This is probably what you want to use. - NSURLVolumeAvailableCapacityForOpportunisticUsageKey, which returns the free space for these "ephemeral" files.
This post also explains the same thing.
I can submit a PR if the maintainers agree.