Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions lib/data/file_manager/file_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import 'package:saber/pages/editor/editor.dart';
import 'package:saver_gallery/saver_gallery.dart';
import 'package:share_plus/share_plus.dart';
import 'package:path/path.dart' as p;

Check notice on line 19 in lib/data/file_manager/file_manager.dart

View workflow job for this annotation

GitHub Actions / Run Flutter tests

Sort directive sections alphabetically.

Try sorting the directives. See https://dart.dev/lints/directives_ordering to learn more about this problem.

/// A collection of cross-platform utility functions for working with a virtual file system.
class FileManager {
Expand Down Expand Up @@ -76,7 +77,7 @@
log.fine('Old data directory is empty or missing, nothing to migrate');
} else {
await moveDirContents(oldDir: oldDir, newDir: newDir);
await oldDir.delete();
await oldDir.delete(recursive: true);
}
}

Expand All @@ -85,14 +86,33 @@
required Directory newDir,
}) async {
await newDir.create(recursive: true);
await for (final entity in oldDir.list()) {
final entityPath =
'${newDir.path}/${entity.path.split(RegExp(r'[\\/]')).last}';
switch (entity) {
case File _:
await entity.rename(entityPath);
case Directory _:
await moveDirContents(oldDir: oldDir, newDir: Directory(entityPath));

await for (final entity in oldDir.list(recursive: true)) {
// Get the path under oldDir and map it into newDir.
final relative = p.relative(entity.path, from: oldDir.path);
final targetPath = p.join(newDir.path, relative);

if (entity is Directory) {
await Directory(targetPath).create(recursive: true);
continue;
}

if (entity is File) {
// Ensure parent exists
await Directory(p.dirname(targetPath)).create(recursive: true);

try {
await entity.rename(targetPath);
} on FileSystemException catch (e) {
// Cross device move, eg. private to public on android
const exdev = 18;
if (e.osError?.errorCode == exdev) {
await entity.copy(targetPath);
await entity.delete();
} else {
rethrow;
}
}
}
}
}
Expand Down