react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

freeSpace from getFSInfo() does not match actual free space on device

Open sarath40158 opened this issue 3 years ago • 1 comments

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 @

sarath40158 avatar Aug 29 '22 11:08 sarath40158

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 X in our example.
  • NSURLVolumeAvailableCapacityForImportantUsageKey, which returns what is reported by the Settings app, X + 50 in 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.

GGGava avatar Feb 06 '24 14:02 GGGava