From 1f206e12d44802ef81884bd581b0a9bbb58bbe35 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Fri, 23 Aug 2013 00:13:36 +0800 Subject: [PATCH] support symlinks --- README.mkd | 5 ++++- repomon.py | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.mkd b/README.mkd index 5d98b9b..8c5393d 100644 --- a/README.mkd +++ b/README.mkd @@ -11,6 +11,10 @@ DEPENDENCIES * pyinotify, tested with 0.9.4 * winterpy (add `pylib` to `$PYTHONPATH`) +NOTE +==== +* relative symlinks may be broken when moving to the right architecture directory + TODO ==== * [high] adding and then removing it before adding complete will result in not-in-database removing @@ -18,5 +22,4 @@ TODO * [middle] `setup.py` support * [middle] disable "any" architecture via config * [low] use one common command queue (now one each repo) -* [low] support symlinking packages here * [low] verify packages diff --git a/repomon.py b/repomon.py index 6382cf7..dcea20e 100755 --- a/repomon.py +++ b/repomon.py @@ -202,6 +202,7 @@ class EventHandler(pyinotify.ProcessEvent): def my_init(self, config, wm, ioloop=None): self.moved_away = {} self.repomans = {} + self.our_links = set() self._ioloop = ioloop or IOLoop.instance() base = config.get('path') @@ -261,6 +262,16 @@ class EventHandler(pyinotify.ProcessEvent): # symlinks haven't been added pass + def process_IN_CREATE(self, event): + file = event.pathname + if os.path.islink(file): + if file in self.our_links: + self.our_links.remove(file) + else: + logger.debug('Symlinked: %s', file) + self.dispatch(file, 'add') + self.files.add(file) + def movedOut(self, event): logger.debug('Moved away: %s', event.pathname) self.dispatch(event.pathname, 'remove') @@ -295,9 +306,7 @@ class EventHandler(pyinotify.ProcessEvent): base, arch = os.path.split(d) # rename if a packager has added to a wrong directory - # but not for a link that has arch=any, as that's what we created - if action == 'add' and act.arch != arch and not \ - (os.path.islink(path) and act.arch == 'any'): + if action == 'add' and act.arch != arch: newd = os.path.join(base, act.arch) newpath = os.path.join(newd, file) os.rename(path, newpath) @@ -313,6 +322,7 @@ class EventHandler(pyinotify.ProcessEvent): newpath = os.path.join(newd, file) if action == 'add': try: + self.our_links.add(newpath) os.symlink(os.path.join('..', arch, file), newpath) except FileExistsError: pass