Geary.Util.Files.recursive_delete_async: Throw rather than log errors
This commit is contained in:
parent
41c284b416
commit
7100598c56
1 changed files with 23 additions and 45 deletions
|
|
@ -16,67 +16,45 @@ private const int RECURSIVE_DELETE_BATCH_SIZE = 50;
|
|||
*/
|
||||
public async void recursive_delete_async(GLib.File folder,
|
||||
int priority = GLib.Priority.DEFAULT,
|
||||
GLib.Cancellable? cancellable = null) {
|
||||
GLib.Cancellable? cancellable = null)
|
||||
throws GLib.Error {
|
||||
GLib.FileType type = yield query_file_type_async(folder, true, cancellable);
|
||||
|
||||
// If this is a folder, recurse children.
|
||||
FileType file_type = FileType.UNKNOWN;
|
||||
try {
|
||||
file_type = yield query_file_type_async(folder, true, cancellable);
|
||||
} catch (Error err) {
|
||||
debug("Unable to get file type of %s: %s", folder.get_path(), err.message);
|
||||
|
||||
if (err is IOError.CANCELLED)
|
||||
return;
|
||||
}
|
||||
|
||||
if (file_type == FileType.DIRECTORY) {
|
||||
FileEnumerator? enumerator = null;
|
||||
try {
|
||||
enumerator = yield folder.enumerate_children_async(
|
||||
if (type == DIRECTORY) {
|
||||
FileEnumerator? enumerator = yield folder.enumerate_children_async(
|
||||
FileAttribute.STANDARD_NAME,
|
||||
FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
|
||||
NOFOLLOW_SYMLINKS,
|
||||
priority,
|
||||
cancellable
|
||||
);
|
||||
} catch (Error e) {
|
||||
debug("Error enumerating files for deletion: %s", e.message);
|
||||
}
|
||||
);
|
||||
|
||||
// Iterate the enumerated files in batches.
|
||||
if (enumerator != null) {
|
||||
try {
|
||||
while (true) {
|
||||
List<FileInfo>? info_list = yield enumerator.next_files_async(
|
||||
RECURSIVE_DELETE_BATCH_SIZE,
|
||||
while (true) {
|
||||
List<FileInfo>? info_list = yield enumerator.next_files_async(
|
||||
RECURSIVE_DELETE_BATCH_SIZE,
|
||||
priority,
|
||||
cancellable
|
||||
);
|
||||
if (info_list == null) {
|
||||
break; // Stop condition.
|
||||
}
|
||||
|
||||
// Recursive step.
|
||||
foreach (FileInfo info in info_list) {
|
||||
yield recursive_delete_async(
|
||||
folder.get_child(info.get_name()),
|
||||
priority,
|
||||
cancellable
|
||||
);
|
||||
if (info_list == null)
|
||||
break; // Stop condition.
|
||||
|
||||
// Recursive step.
|
||||
foreach (FileInfo info in info_list) {
|
||||
yield recursive_delete_async(
|
||||
folder.get_child(info.get_name()),
|
||||
priority,
|
||||
cancellable
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (Error e) {
|
||||
debug("Error enumerating batch of files: %s", e.message);
|
||||
|
||||
if (e is IOError.CANCELLED)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Children have been deleted, it's now safe to delete this file/folder.
|
||||
try {
|
||||
yield folder.delete_async(priority, cancellable);
|
||||
} catch (Error e) {
|
||||
debug("Error removing file: %s", e.message);
|
||||
}
|
||||
yield folder.delete_async(priority, cancellable);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue