Skip to content
Permalink
Browse files
Add delay before BundleRegistry.add_bundle
As discussed in SL#4841, when installing activities via system
packages there is no guarantee that diretory contents are available
yet even if the GFileMonitor has detected the directory creation.

Therefore some delay before trying actually calling BundleRegistry
add_bundle method. Plus, use a best-effort approach to cover different
ranges of delay.

Signed-off-by: Martin Abente Lahaye <tch@sugarlabs.org>
  • Loading branch information
tchx84 committed Jul 31, 2015
1 parent 24bf6d1 commit 7743b90
Showing 1 changed file with 18 additions and 1 deletion.
@@ -71,6 +71,8 @@ class BundleRegistry(GObject.GObject):
([GObject.TYPE_PYOBJECT])),
}

_MAX_DELAY = 10000

def __init__(self):
logging.debug('STARTUP: Loading the bundle registry')
GObject.GObject.__init__(self)
@@ -137,10 +139,25 @@ def __desktop_view_icons_changed_cb(self, model):
def __file_monitor_changed_cb(self, monitor, one_file, other_file,
event_type):
if event_type == Gio.FileMonitorEvent.CREATED:
self.add_bundle(one_file.get_path(), set_favorite=True)
bundle_path = one_file.get_path()
# XXX ignore debian packages temporary directories
if bundle_path.endswith('.dpkg-new'):
return
# XXX SL4841 we can't guarantee the contents are all set yet
delay = 100
GLib.timeout_add(delay, self.__timeout_add_cb, bundle_path, delay)
elif event_type == Gio.FileMonitorEvent.DELETED:
self.remove_bundle(one_file.get_path())

def __timeout_add_cb(self, bundle_path, delay):
bundle = self.add_bundle(bundle_path, set_favorite=True)
if not bundle and delay < self._MAX_DELAY:
delay *= 10
GLib.timeout_add(delay, self.__timeout_add_cb, bundle_path, delay)
else:
logging.debug('stopping for %s after %d ms', bundle_path, delay)
return False

def _load_mime_defaults(self):
defaults = {}

6 comments on commit 7743b90

@godiard
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can use GLib.timeout_add_seconds(with 1, 10 and 100 values) given that is designed to cause less cpu wakeups:
http://pygtk.org/docs/pygobject/glib-functions.html#function-glib--timeout-add-seconds

@tchx84
Copy link
Owner Author

@tchx84 tchx84 commented on 7743b90 Jul 31, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though about it, but I want to use 100ms delay, and that is not possible with _seconds.

@godiard
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, what is the rationale to use 100ms delay?

@tchx84
Copy link
Owner Author

@tchx84 tchx84 commented on 7743b90 Jul 31, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minimum delay IMHO, but is just as arbitrary as any other number.

@tchx84
Copy link
Owner Author

@tchx84 tchx84 commented on 7743b90 Jul 31, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100 seconds would be too much, BTW.

@quozl
Copy link

@quozl quozl commented on 7743b90 Jul 31, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for 0.108.

Long term there should be a post-install notification method for an activity package to notify the shell, and control panel updaters should generate this signal instead of calling add bundle directly.

Please sign in to comment.