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:
parent
ccb23fdf3d
commit
7c87ef444f
3 changed files with 40 additions and 30 deletions
|
@ -1,3 +1,3 @@
|
|||
class Constants {
|
||||
static const VERSION = "1.2.082424+0723";
|
||||
static const VERSION = "1.2.082424+1243";
|
||||
}
|
||||
|
|
|
@ -221,47 +221,57 @@ 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;*/
|
||||
final size = await File(path).length();
|
||||
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();
|
||||
FIC.addFile(path, FileInfo(path: path, size: size, isFile: true));
|
||||
if (cacheSize) {
|
||||
FileInformationCache FIC = FileInformationCache.obtain();
|
||||
FIC.addFile(path, FileInfo(path: path, size: size, isFile: true));
|
||||
}
|
||||
|
||||
return size;
|
||||
} catch (E) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
Future<int> getDirectorySize(String path,
|
||||
{bool recursive = false,
|
||||
bool cacheSize = false,
|
||||
bool verbose = false}) async {
|
||||
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();
|
||||
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();
|
||||
|
||||
await Future.forEach(entityList, (entity) async {
|
||||
if (entity is File) {
|
||||
totalSize += await getFileSize(entity.path,
|
||||
cacheSize: cacheSize, verbose: verbose);
|
||||
} else if (entity is Directory) {
|
||||
totalSize += await getDirectorySize(entity.path,
|
||||
recursive: true, cacheSize: cacheSize, verbose: verbose);
|
||||
await Future.forEach(entityList, (entity) async {
|
||||
if (entity is File) {
|
||||
totalSize += await getFileSize(entity.path,
|
||||
cacheSize: cacheSize, verbose: verbose);
|
||||
} else if (entity is Directory) {
|
||||
totalSize += await getDirectorySize(entity.path,
|
||||
recursive: true, cacheSize: cacheSize, verbose: verbose);
|
||||
}
|
||||
});
|
||||
|
||||
if (verbose)
|
||||
await prnt("${trunc("\r>> Size of dir $path")} is $totalSize bytes");
|
||||
|
||||
if (cacheSize) {
|
||||
FileInformationCache FIC = FileInformationCache.obtain();
|
||||
FileInfo FI = FileInfo(path: path, size: totalSize, isFile: false);
|
||||
FIC.addFile(path, FI);
|
||||
}
|
||||
});
|
||||
|
||||
if (verbose)
|
||||
await prnt("${trunc("\r>> Size of dir $path")} is $totalSize bytes");
|
||||
|
||||
if (cacheSize) {
|
||||
FileInformationCache FIC = FileInformationCache.obtain();
|
||||
FileInfo FI = FileInfo(path: path, size: totalSize, isFile: false);
|
||||
FIC.addFile(path, FI);
|
||||
return totalSize;
|
||||
} catch (E) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
Future<void> prnt(String text) async {
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue