]> arthur.barton.de Git - bup.git/commitdiff
index.py: handle uid/gid == -1 on cygwin bup-0.17b
authorAvery Pennarun <apenwarr@gmail.com>
Mon, 6 Sep 2010 07:32:59 +0000 (00:32 -0700)
committerAvery Pennarun <apenwarr@gmail.com>
Mon, 6 Sep 2010 07:47:20 +0000 (00:47 -0700)
On cygwin, the uid or gid might be -1 for some reason.  struct.pack()
complains about a DeprecationWarning when packing a negative number into an
unsigned int, so fix it up first.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
lib/bup/index.py

index c6329c48948430a5a6780bf4eb91958a063ec960..2818fb534a622b6e0e82f8fa0146745e08b73935 100644 (file)
@@ -77,11 +77,15 @@ class Entry:
                    self.flags, self.children_ofs, self.children_n))
 
     def packed(self):
-        return struct.pack(INDEX_SIG,
+        try:
+            return struct.pack(INDEX_SIG,
                            self.dev, self.ctime, self.mtime, 
                            self.uid, self.gid, self.size, self.mode,
                            self.gitmode, self.sha, self.flags,
                            self.children_ofs, self.children_n)
+        except DeprecationWarning, e:
+            log('pack error: %s (%r)\n' % (e, self))
+            raise
 
     def from_stat(self, st, tstart):
         old = (self.dev, self.ctime, self.mtime,
@@ -99,6 +103,15 @@ class Entry:
         if int(st.st_ctime) >= tstart or old != new \
               or self.sha == EMPTY_SHA or not self.gitmode:
             self.invalidate()
+        self._fixup()
+        
+    def _fixup(self):
+        if self.uid < 0:
+            self.uid += 0x100000000
+        if self.gid < 0:
+            self.gid += 0x100000000
+        assert(self.uid >= 0)
+        assert(self.gid >= 0)
 
     def is_valid(self):
         f = IX_HASHVALID|IX_EXISTS
@@ -151,6 +164,7 @@ class NewEntry(Entry):
          self.flags, self.children_ofs, self.children_n
          ) = (dev, int(ctime), int(mtime), uid, gid,
               size, mode, gitmode, sha, flags, children_ofs, children_n)
+        self._fixup()
 
 
 class BlankNewEntry(NewEntry):