CC: Tweaked

CC: Tweaked

42M Downloads

fs.getDriveCapacity and fs.stat

xAnavrins opened this issue ยท 3 comments

commented

While coding a drive utility to show disk usage of the internal storage or a disk drive, I came up with a few issue;

It is very tricky to figure out the maximum capacity of a computer or disk storage using only fs.getFreeSpace and fs.getSize on all files recursively, due to files that are smaller than 500 bytes being counted as 500 bytes used by getFreeSpace, but not by getSize.
fs.getDriveCapacity('hdd') would return a drive's max capacity to make that process easier.

fs.stat(path) would be a way to check and return a file's size as well as if it is a directory and if it is read-only, without the overhead of calling those three functions for every files.

commented

It is very tricky to figure out the maximum capacity of a computer or disk storage

It's not that hard truth be told - the logic is pretty much just math.max(500, fs.getSize(path)), for every file and directory. That said, I can definitely see why such a function would be useful.

I think it's worth figuring out what fs.getDriveCapacity("rom")1 should return. Both 0 and the sum of all files on the drive technically make sense.

I've been thinking about an fs.stat2 for a while - it might also be nice to expose file modification/update times in there too, though would need to think about that first.

1. Though I'd be inclined to have fs.getCapacity(path) or something. Just so it's consistent with existing methods.
2. Probably fs.attributes, to be inline with lfs. stat is a kinda terrible name.

commented

Definitely agree with both footnotes @SquidDev

As for capacity of ROM, 0 as having it be 0 underlines that it's read only.

commented

It's not that hard truth be told - the logic is pretty much just math.max(500, fs.getSize(path)), for every file and directory. That said, I can definitely see why such a function would be useful.

This is what I've been doing, although there are still some weird cases, of which I can't figure out, where this method gives inaccurate results nonetheless.