Patches a bug in IOTools#getFileSize and #getDirectorySize on platforms with hard links which point to folders that no longer exist as a part of the base OS design (I am looking at you... windows)

This commit is contained in:
zontreck 2024-08-24 12:44:19 -07:00
parent ccb23fdf3d
commit 7c87ef444f
3 changed files with 40 additions and 30 deletions

View file

@ -1,3 +1,3 @@
class Constants {
static const VERSION = "1.2.082424+0723";
static const VERSION = "1.2.082424+1243";
}

View file

@ -221,9 +221,11 @@ Future<int> getFileSize(String path,
if (verbose) await prnt("${trunc("\r> Checking size of file $path")}");
/*final fileBytes = await File(path).readAsBytes();
int size = fileBytes.lengthInBytes;*/
try {
final size = await File(path).length();
if (verbose) await prnt("${trunc("\r>> Size of file $path")} is $size bytes");
if (verbose)
await prnt("${trunc("\r>> Size of file $path")} is $size bytes");
if (cacheSize) {
FileInformationCache FIC = FileInformationCache.obtain();
@ -231,16 +233,21 @@ Future<int> getFileSize(String path,
}
return size;
} catch (E) {
return 0;
}
}
Future<int> getDirectorySize(String path,
{bool recursive = false,
bool cacheSize = false,
bool verbose = false}) async {
try {
int totalSize = 0;
if (verbose) await prnt("\r${trunc("> Check dir size of $path")}");
final entityList =
await Directory(path).list(recursive: false, followLinks: true).toList();
final entityList = await Directory(path)
.list(recursive: false, followLinks: true)
.toList();
await Future.forEach(entityList, (entity) async {
if (entity is File) {
@ -262,6 +269,9 @@ Future<int> getDirectorySize(String path,
}
return totalSize;
} catch (E) {
return 0;
}
}
Future<void> prnt(String text) async {

View file

@ -1,6 +1,6 @@
name: libac_dart
description: "Aria's Creations code library"
version: 1.2.082424+0723
version: 1.2.082424+1243
homepage: "https://zontreck.com"