Permalink
Browse files

index.py: handle uid/gid == -1 on cygwin

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>
  • Loading branch information...
1 parent 479b8dd commit 8417c11948532ba890b862dcad9d37810d482616 @apenwarr apenwarr committed Sep 6, 2010
Showing with 15 additions and 1 deletion.
  1. +15 −1 lib/bup/index.py
View
@@ -77,11 +77,15 @@ def __repr__(self):
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 @@ def from_stat(self, st, tstart):
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 @@ def __init__(self, basename, name, dev, ctime, mtime, uid, gid,
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):

0 comments on commit 8417c11

Please sign in to comment.