-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup.dart
More file actions
executable file
·36 lines (34 loc) · 1.28 KB
/
cleanup.dart
File metadata and controls
executable file
·36 lines (34 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import 'dart:io';
import 'package:create_backup/module.dart';
void main(List<String> arguments) async {
writeLog('Started backup cleanup 🧹 🚀');
final constants = await Constants.getInstance();
final cleanupSuccesses = <bool>[];
for (final backupPath in getBackupPaths(constants)) {
final backupSize = await getBackupSize(backupPath);
final copiedSize =
await getBackupSize(getEncryptedPath(backupPath, constants));
if (backupSize != copiedSize) {
writeLog(
'File sizes do not match for $backupPath; skipping cleanup 🧹 ❌',
logLevel: 1,
);
cleanupSuccesses.add(false);
continue;
}
writeLog('Cleaning up $backupPath 🧹', logLevel: 1);
final success = await removePath(backupPath);
cleanupSuccesses.add(success);
}
Directory(constants.backupDestination).deleteSync();
var logMessage = 'Cleanup done 🧹 🏁 ';
if (cleanupSuccesses.any((result) => result == false)) {
logMessage += 'however, errors are present; you might want to run the '
'encryption again for failed checks or try moving files manually 🔁';
} else {
logMessage += 'you can dismount ${constants.encryptedVolumePath} and eject '
'${constants.backupVolumePath} now ⏏️';
}
writeLog(logMessage);
exit(0);
}