[baobab/wip/vala: 36/53] Bubble up scanner errors.
- From: Stefano Facchini <sfacchini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab/wip/vala: 36/53] Bubble up scanner errors.
- Date: Thu, 5 Apr 2012 21:36:45 +0000 (UTC)
commit a0e4fd60b8a1eb0dfdc989c48e3422f63527df67
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Jan 29 12:02:31 2012 +0100
Bubble up scanner errors.
For now this is very strict: we abort the scan on every error, which
means that scan filesystem will never work unless running as root. We
probably need to be more permissive and simply mark directories where
we do not have permissions and warn that the results may be not
accurate.
src/baobab-scanner.vala | 8 ++++++++
src/baobab-threaded-scanner.vala | 18 ++++++++++++------
src/baobab-window.vala | 13 ++++++++++++-
3 files changed, 32 insertions(+), 7 deletions(-)
---
diff --git a/src/baobab-scanner.vala b/src/baobab-scanner.vala
index 5871cef..e96de17 100644
--- a/src/baobab-scanner.vala
+++ b/src/baobab-scanner.vala
@@ -31,6 +31,7 @@ namespace Baobab {
protected Cancellable cancellable;
protected HashTable<File, unowned File> excluded_locations;
protected HardLink[] hardlinks;
+ protected Error? scan_error;
protected static const string ATTRIBUTES =
FileAttribute.STANDARD_NAME + "," +
@@ -55,9 +56,16 @@ namespace Baobab {
cancellable.cancel ();
}
+ public virtual void finish () throws Error {
+ if (scan_error != null) {
+ throw scan_error;
+ }
+ }
+
public Scanner (File directory) {
this.directory = directory;
cancellable = new Cancellable();
+ scan_error = null;
set_column_types (new Type[] {
typeof (string), // DIR_NAME
typeof (string), // PARSE_NAME
diff --git a/src/baobab-threaded-scanner.vala b/src/baobab-threaded-scanner.vala
index a17bf24..d798d70 100644
--- a/src/baobab-threaded-scanner.vala
+++ b/src/baobab-threaded-scanner.vala
@@ -58,6 +58,7 @@ namespace Baobab {
internal uint64 elements;
internal double percent;
internal int max_depth;
+ internal Error? error;
// accessed only by the main thread
internal Gtk.TreeIter iter;
@@ -81,15 +82,12 @@ namespace Baobab {
results.alloc_size = info.get_attribute_uint64 (FileAttribute.STANDARD_ALLOCATED_SIZE);
}
results.elements = 1;
+ results.error = null;
try {
var children = directory.enumerate_children (ATTRIBUTES, FileQueryInfoFlags.NOFOLLOW_SYMLINKS, cancellable);
FileInfo? child_info;
while ((child_info = children.next_file (cancellable)) != null) {
- if (cancellable.is_cancelled ()) {
- break;
- }
-
switch (child_info.get_file_type ()) {
case FileType.DIRECTORY:
var child = directory.get_child (child_info.get_name ());
@@ -130,9 +128,8 @@ namespace Baobab {
break;
}
}
- } catch (IOError.PERMISSION_DENIED e) {
} catch (Error e) {
- warning ("couldn't iterate %s: %s", results.parse_name, e.message);
+ results.error = e;
}
foreach (unowned Results child_results in results_array.results) {
@@ -208,8 +205,17 @@ namespace Baobab {
max_depth = results.max_depth;
}
+ // only on the first error
+ if (scan_error == null && results.error != null) {
+ scan_error = results.error;
+ cancellable.cancel ();
+ completed ();
+ return false;
+ }
+
if (results.parent == null) {
completed ();
+ return false;
}
}
}
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 1efd979..b205033 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -384,7 +384,18 @@ namespace Baobab {
set_busy (true);
scanner.completed.connect(() => {
- set_busy (false);
+ try {
+ scanner.finish();
+ } catch (IOError.CANCELLED e) {
+ // Handle cancellation silently
+ scanner.clear ();
+ } catch (Error e) {
+ var primary = _("Could not scan folder \"%s\"").printf (scanner.directory.get_parse_name ());
+ message (primary, e.message, Gtk.MessageType.INFO);
+ scanner.clear ();
+ } finally {
+ set_busy (false);
+ }
});
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]