remove dirty components from cache
authorTimo Savola <tsavola@movial.fi>
Tue, 8 Apr 2008 19:36:54 +0000 (22:36 +0300)
committerTimo Savola <tsavola@movial.fi>
Tue, 8 Apr 2008 19:36:54 +0000 (22:36 +0300)
matrix/cache.py
matrix/components.py

index e9e9d41..d5e0c84 100644 (file)
@@ -19,14 +19,21 @@ def contains(c):
        return c.cached
 
 def __contains(c):
-       for repo in (c.repo, c.meta):
-               if repo.dirty_files():
-                       if config.force:
-                               return False
-                       else:
-                               raise Error('Dirty files in %s' % repo)
-
        path = get_path(c)
+
+       if c.is_dirty():
+               if os.path.exists(path):
+                       os.remove(path)
+
+               msg = 'Dirty files in %s' % c.repo
+               if config.force:
+                       if config.debug:
+                               print msg
+
+                       return False
+               else:
+                       raise Error(msg)
+
        if not os.path.exists(path):
                return False
 
@@ -60,6 +67,9 @@ def __contains(c):
        return True
 
 def update(c):
+       if c.is_dirty():
+               return
+
        path = get_path(c)
 
        dir = os.path.dirname(path)
index 03523df..d7ce852 100644 (file)
@@ -13,6 +13,8 @@ from repositories import Repository
 Error = RuntimeError
 
 class Component(object):
+       __dirty = None
+
        cached = None
 
        rdepends = None
@@ -42,6 +44,15 @@ class Component(object):
                self.packages = {}
                self.depends = set()
 
+       def is_dirty(self):
+               if self.__dirty is None:
+                       self.__dirty = False
+                       for repo in (self.repo, self.meta):
+                               if repo.dirty_files():
+                                       self.__dirty = True
+                                       break
+               return self.__dirty
+
        def add_depend(self, c):
                self.depends.add(c)