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 {
|
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")}");
|
if (verbose) await prnt("${trunc("\r> Checking size of file $path")}");
|
||||||
/*final fileBytes = await File(path).readAsBytes();
|
/*final fileBytes = await File(path).readAsBytes();
|
||||||
int size = fileBytes.lengthInBytes;*/
|
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) {
|
if (cacheSize) {
|
||||||
FileInformationCache FIC = FileInformationCache.obtain();
|
FileInformationCache FIC = FileInformationCache.obtain();
|
||||||
FIC.addFile(path, FileInfo(path: path, size: size, isFile: true));
|
FIC.addFile(path, FileInfo(path: path, size: size, isFile: true));
|
||||||
|
}
|
||||||
|
|
||||||
|
return size;
|
||||||
|
} catch (E) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> getDirectorySize(String path,
|
Future<int> getDirectorySize(String path,
|
||||||
{bool recursive = false,
|
{bool recursive = false,
|
||||||
bool cacheSize = false,
|
bool cacheSize = false,
|
||||||
bool verbose = false}) async {
|
bool verbose = false}) async {
|
||||||
int totalSize = 0;
|
try {
|
||||||
if (verbose) await prnt("\r${trunc("> Check dir size of $path")}");
|
int totalSize = 0;
|
||||||
final entityList =
|
if (verbose) await prnt("\r${trunc("> Check dir size of $path")}");
|
||||||
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 {
|
await Future.forEach(entityList, (entity) async {
|
||||||
if (entity is File) {
|
if (entity is File) {
|
||||||
totalSize += await getFileSize(entity.path,
|
totalSize += await getFileSize(entity.path,
|
||||||
cacheSize: cacheSize, verbose: verbose);
|
cacheSize: cacheSize, verbose: verbose);
|
||||||
} else if (entity is Directory) {
|
} else if (entity is Directory) {
|
||||||
totalSize += await getDirectorySize(entity.path,
|
totalSize += await getDirectorySize(entity.path,
|
||||||
recursive: true, cacheSize: cacheSize, verbose: verbose);
|
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)
|
return totalSize;
|
||||||
await prnt("${trunc("\r>> Size of dir $path")} is $totalSize bytes");
|
} catch (E) {
|
||||||
|
return 0;
|
||||||
if (cacheSize) {
|
|
||||||
FileInformationCache FIC = FileInformationCache.obtain();
|
|
||||||
FileInfo FI = FileInfo(path: path, size: totalSize, isFile: false);
|
|
||||||
FIC.addFile(path, FI);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return totalSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> prnt(String text) async {
|
Future<void> prnt(String text) async {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: libac_dart
|
name: libac_dart
|
||||||
description: "Aria's Creations code library"
|
description: "Aria's Creations code library"
|
||||||
version: 1.2.082424+0723
|
version: 1.2.082424+1243
|
||||||
homepage: "https://zontreck.com"
|
homepage: "https://zontreck.com"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue