Skip to content

Commit

Permalink
o
Browse files Browse the repository at this point in the history
  • Loading branch information
bung87 committed Mar 21, 2020
1 parent e1fa38f commit fe34cd9
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 28 deletions.
13 changes: 12 additions & 1 deletion lib/apps/mac.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ import 'package:path/path.dart' as path;
import 'package:event_bus/event_bus.dart';
import '../filesize.dart';

const skipDirs = ["/Library/Caches/ColorSync",
"/Library/logs/DiagnosticReports",
"/Library/logs/CrashReporter",
"/var/log/displaypolicy",
"/var/log/powermanagement",
"/var/log/asl",
"/var/log/DiagnosticMessages",
"/var/log/Bluetooth",
"/var/log/com.apple.wifivelocity",
];

class MacTask extends Task{
String app = "Mac";
MacTask(EventBus _globalBus) : super(_globalBus) {
Expand All @@ -29,7 +40,7 @@ class MacTask extends Task{
scan(){
int total = 0;
var task = new DirsCleanTask(this.dirs);
task.eventBus.on<DirInfo>().listen( (event ) {
task.eventBus.on<DirInfo>().skipWhile((element) => skipDirs.indexOf(element.name) != -1 ).listen( (event ) {
total += event.size;

this.eventBus.fire( TaskData(this.app,event.toString() ) );
Expand Down
6 changes: 3 additions & 3 deletions lib/apps/python.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class PythonTask extends Task {
// );

ReceivePort receivePort = ReceivePort();
var isolate = await Isolate.spawn(runGetDirectorySize, receivePort.sendPort,
onExit: receivePort.sendPort);
var isolate = await Isolate.spawn(runGetDirectorySize, receivePort.sendPort);

receivePort.listen((data) {
_scan(data);
isolate.kill(priority: 0);
_scan(data);

});
}

Expand Down
20 changes: 12 additions & 8 deletions lib/apps/ruby.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'dart:convert';
import './ruby_utils.dart';
import 'dart:isolate';

final RegExp re = new RegExp(r'\.rvm/gems/ruby\-(\d+\.\d+(?:\.\d+)?)/gems');
// final RegExp re = new RegExp(r'\.rvm/gems/ruby\-(\d+\.\d+(?:\.\d+)?)/cache');

void runGetDirectorySize(SendPort sendPort) {
filesInDirectoryWithDepth(
Expand All @@ -30,21 +30,25 @@ class RubyTask extends Task {
// this.eventBus.fire(TaskData(this.app, e.toString()));
// } );
ReceivePort receivePort = ReceivePort();
var isolate = await Isolate.spawn(runGetDirectorySize, receivePort.sendPort,
onExit: receivePort.sendPort);
var isolate = await Isolate.spawn(runGetDirectorySize, receivePort.sendPort);

receivePort.listen((data) {
_scan(data);
isolate.kill(priority: 0);
_scan(data);

});
}

_scan(out) async {
final days = new DateTime.now().subtract(new Duration(days: 90));
var dirs = await filesInDirectory(out, FileSystemEntityType.directory);
if(out == null){
return;
}
// final days = new DateTime.now().subtract(new Duration(days: 90));
// var dirs = await filesInDirectory(out, FileSystemEntityType.file);
int total = 0;
Stream.fromIterable(dirs)
.skipWhile((element) => element.statSync().accessed.isAfter(days))
// Stream.fromFuture(dirs)
out.list(recursive: false, followLinks: false)
// .skipWhile((element) => element.statSync().accessed.isAfter(days))
.asyncMap((event) async {
var size = await directorySize(event);
var data = {"dir": event, "size": size};
Expand Down
2 changes: 1 addition & 1 deletion lib/apps/ruby_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:path/path.dart' as path;
import 'dart:io' show Directory, File, FileSystemEntity, FileSystemEntityType;
import 'dart:isolate';

final RegExp re = new RegExp(r'\.rvm/gems/ruby\-(\d+\.\d+(?:\.\d+)?)/gems');
final RegExp re = new RegExp(r'\.rvm/gems/ruby\-(\d+\.\d+(?:\.\d+)?)/cache');

filesInDirectoryWithDepth(Directory dir, FileSystemEntityType typ,
int currentLevel, int maxLevel,SendPort sendPort) {
Expand Down
9 changes: 8 additions & 1 deletion lib/task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class Task {
Stream.fromIterable(cache).listen((element) {
if (element["dir"] is Directory) {
(element["dir"] as Directory).delete(recursive: true);
}else{
element["dir"].delete();
}
}).onDone(() {
this
Expand All @@ -64,7 +66,12 @@ class Task {
.asyncMap((event) => directorySize(event["dir"]))
.reduce((previous, element) => previous + element)
.then((value) {
this.eventBus.fire(TaskData(this.app, fileSizeHumanReadable(value)));
if(value == 0){
this.eventBus.fire(TaskData(this.app, "empty"));
}else{
this.eventBus.fire(TaskData(this.app, fileSizeHumanReadable(value)));
}

this.cache.clear();
});
}
Expand Down
31 changes: 19 additions & 12 deletions lib/utils.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'dart:io' show Directory, File, FileSystemEntity, FileSystemEntityType,Platform;
import 'dart:io'
show Directory, File, FileSystemEntity, FileSystemEntityType, Platform;

final String userHome =
Platform.environment['HOME'] ?? Platform.environment['USERPROFILE'];
Platform.environment['HOME'] ?? Platform.environment['USERPROFILE'];

filesInDirectory(Directory dir, FileSystemEntityType typ) async {
List<dynamic> files = <dynamic>[];
Expand All @@ -19,21 +20,27 @@ filesInDirectory(Directory dir, FileSystemEntityType typ) async {
return files;
}


directorySize(Directory dir) async {
if(!dir.existsSync()){
directorySize( dir) async {
if (!dir.existsSync()) {
return 0;
}
var total = 0;
await for (var entity in dir.list(recursive: true, followLinks: false)) {
FileSystemEntityType type =
await FileSystemEntity.type(entity.path, followLinks: false);

if (type == FileSystemEntityType.file) {
var stat = await entity.stat();
total += stat.size;
if (await FileSystemEntity.type(dir.path, followLinks: false) ==
FileSystemEntityType.directory) {
await for (var entity in dir.list(recursive: true, followLinks: false)) {
FileSystemEntityType type =
await FileSystemEntity.type(entity.path, followLinks: false);

if (type == FileSystemEntityType.file) {
var stat = await entity.stat();
total += stat.size;
}
}
} else {
var stat = await dir.stat();
total += stat.size;
}

return total;
}

Expand Down
4 changes: 2 additions & 2 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PODS:

DEPENDENCIES:
- disk_space (from `Flutter/ephemeral/.symlinks/plugins/disk_space/macos`)
- FlutterMacOS (from `Flutter/ephemeral/.symlinks/flutter/darwin-x64-release`)
- FlutterMacOS (from `Flutter/ephemeral/.symlinks/flutter/darwin-x64`)
- path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`)
- url_launcher (from `Flutter/ephemeral/.symlinks/plugins/url_launcher/macos`)
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)
Expand All @@ -19,7 +19,7 @@ EXTERNAL SOURCES:
disk_space:
:path: Flutter/ephemeral/.symlinks/plugins/disk_space/macos
FlutterMacOS:
:path: Flutter/ephemeral/.symlinks/flutter/darwin-x64-release
:path: Flutter/ephemeral/.symlinks/flutter/darwin-x64
path_provider_macos:
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos
url_launcher:
Expand Down

0 comments on commit fe34cd9

Please sign in to comment.