]> arthur.barton.de Git - bup.git/commitdiff
Assorted cleanups to Luke's cygwin fixes.
authorAvery Pennarun <apenwarr@gmail.com>
Mon, 11 Jan 2010 20:06:03 +0000 (15:06 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Mon, 11 Jan 2010 20:21:23 +0000 (15:21 -0500)
There were a few things that weren't quite done how I would have done them,
so I changed the implementation.  Should still work in cygwin, though.

The only actual functional changes are:
 - index.Reader.close() now actually sets m=None rather than just closing it
 - removed the "if rename fails, then unlink first" logic, which is
   seemingly not needed after all.
 - rather than special-casing cygwin to use "hostname" instead of "hostname
   -f", it turns out python has a socket.getfqdn() that does what we want.

.gitignore
Makefile
client.py
cmd-index.py
helpers.py
index.py

index 73c2300ec52b4c27ef2941edb8e7ed30b83fa3dc..0cb59087dd67851422f212bc3df7d65d1e167157 100644 (file)
@@ -1,9 +1,9 @@
 bup
 bup-*
 randomgen
-randomgen.exe
 *.o
 *.so
+*.exe
 *.dll
 *~
 *.pyc
index 063b3e5cc3c35e4e2f591fdb075722f44013d555..2249d0e7f376d36fb4aa139d0026872ea7d99c34 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -63,7 +63,7 @@ bup-%: cmd-%.sh
        gcc -c -o $@ $^ $(CPPFLAGS) $(CFLAGS)
 
 clean:
-       rm -f *.o *.so *.dll *~ .*~ *.pyc */*.pyc */*~ \
-               bup bup-* randomgen$(EXT) \
+       rm -f *.o *.so *.dll *.exe *~ .*~ *.pyc */*.pyc */*~ \
+               bup bup-* randomgen \
                out[12] out2[tc] tags[12] tags2[tc]
        rm -rf *.tmp
index 6a373eb5d177b777d2e7d2263d501d42571d0027..7be235a9a5720955f39d40eb3c497d4c60dfec9f 100644 (file)
--- a/client.py
+++ b/client.py
@@ -39,8 +39,8 @@ class Client:
             #log('argv is: %r\n' % argv)
         (self.host, self.dir) = (host, dir)
         self.cachedir = git.repo('index-cache/%s'
-                                 % re.sub(r'[^@:\w]', '_', 
-                                          "%s-%s" % (host, dir)))
+                                 % re.sub(r'[^@\w]', '_', 
+                                          "%s:%s" % (host, dir)))
         try:
             self.p = p = Popen(argv, stdin=PIPE, stdout=PIPE, preexec_fn=fixenv)
         except OSError, e:
index bf1e5036501305540ca32b786ed9c7321b3a58a1..c3b6ce9f3f7e79f7147f59783196eb7b946a1109 100755 (executable)
@@ -3,14 +3,17 @@ import os, sys, stat
 import options, git, index
 from helpers import *
 
+
+try:
+    O_LARGEFILE = os.O_LARGEFILE
+except AttributeError:
+    O_LARGEFILE = 0
+
+
 class OsFile:
     def __init__(self, path):
         self.fd = None
-        try:
-            self.fd = os.open(path, os.O_RDONLY|os.O_LARGEFILE|os.O_NOFOLLOW)
-        except AttributeError:
-            self.fd = os.open(path, os.O_RDONLY|os.O_NOFOLLOW)
-        #self.st = os.fstat(self.fd)
+        self.fd = os.open(path, os.O_RDONLY|O_LARGEFILE|os.O_NOFOLLOW)
         
     def __del__(self):
         if self.fd:
index 344d001a53ece358f1b845b53a9a4eaad8fe9be6..54b099c5b3e8a0c8b8e06f4beec0b10723146816 100644 (file)
@@ -1,4 +1,4 @@
-import sys, os, pwd, subprocess, errno
+import sys, os, pwd, subprocess, errno, socket
 
 
 def log(s):
@@ -50,15 +50,8 @@ _hostname = None
 def hostname():
     global _hostname
     if not _hostname:
-        try:
-            if sys.platform == 'cygwin':
-                hostcmd = ['hostname']
-            else:
-                hostcmd = ['hostname', '-f']
-            _hostname = readpipe(hostcmd).strip()
-        except OSError:
-            pass
-    return _hostname or 'localhost'
+        _hostname = socket.getfqdn()
+    return _hostname
 
 
 class Conn:
index 10ec093596a95b0d18f9c4eed73f59261da98ef4..93841ed5b6a47bc73384241b3f3ac6a13f25b956 100644 (file)
--- a/index.py
+++ b/index.py
@@ -107,13 +107,13 @@ class Reader:
             ofs = eon + 1 + ENTLEN
 
     def save(self):
-        if self.writable:
+        if self.writable and self.m:
             self.m.flush()
 
     def close(self):
         self.save()
-        if self.writable:
-            self.m.close()
+        if self.writable and self.m:
+            self.m = None
             self.writable = False
 
     def filter(self, prefixes):
@@ -195,12 +195,7 @@ class Writer:
         self.f = None
         if f:
             f.close()
-            try:
-                os.rename(self.tmpname, self.filename)
-            except OSError:
-                if os.path.exists(self.filename):
-                    os.unlink(self.filename)
-                os.rename(self.tmpname, self.filename)
+            os.rename(self.tmpname, self.filename)
 
     def _write(self, data):
         self.f.write(data)