[baobab/wip/vala] Bubble up scanner errors.
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab/wip/vala] Bubble up scanner errors.
- Date: Sun, 29 Jan 2012 11:05:04 +0000 (UTC)
commit 4c85958cfbcbaa6725be7de1f8b85596e431c848
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 | 10 +++++++++-
src/baobab-threaded-scanner.vala | 22 ++++++++++++++--------
src/baobab-window.vala | 13 ++++++++++++-
3 files changed, 35 insertions(+), 10 deletions(-)
---
diff --git a/src/baobab-scanner.vala b/src/baobab-scanner.vala
index 306fc2c..3994b23 100644
--- a/src/baobab-scanner.vala
+++ b/src/baobab-scanner.vala
@@ -29,8 +29,9 @@ namespace Baobab {
}
protected HashTable<File, unowned File> excluded_locations;
- protected Cancellable cancellable;
protected HardLink[] hardlinks;
+ protected Cancellable cancellable;
+ 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 850941b..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 ());
@@ -109,7 +107,7 @@ namespace Baobab {
if (child_info.get_attribute_uint32 (FileAttribute.UNIX_NLINK) > 1) {
var hl = HardLink (child_info);
- /* check if we've already encountered this file */
+ // check if we've already encountered this file
if (hl in hardlinks) {
continue;
}
@@ -126,13 +124,12 @@ namespace Baobab {
break;
default:
- /* ignore other types (symlinks, sockets, devices, etc) */
+ // ignore other types (symlinks, sockets, devices, etc)
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 2e33962..a2bcfd6 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -385,7 +385,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]