Skip to content
Snippets Groups Projects
Commit 7100598c authored by Michael Gratton's avatar Michael Gratton
Browse files

Geary.Util.Files.recursive_delete_async: Throw rather than log errors

parent 41c284b4
No related branches found
No related tags found
1 merge request!14Update to git snapshot
......@@ -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) {
// 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);
GLib.Cancellable? cancellable = null)
throws GLib.Error {
GLib.FileType type = yield query_file_type_async(folder, true, cancellable);
if (err is IOError.CANCELLED)
return;
}
if (file_type == FileType.DIRECTORY) {
FileEnumerator? enumerator = null;
try {
enumerator = yield folder.enumerate_children_async(
// If this is a folder, recurse children.
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);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment