From c823518e790c9cac4087ab0677b8d127efc431c4 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Mon, 11 Jan 2010 15:06:03 -0500 Subject: [PATCH] Assorted cleanups to Luke's cygwin fixes. 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 | 2 +- Makefile | 4 ++-- client.py | 4 ++-- cmd-index.py | 13 ++++++++----- helpers.py | 13 +++---------- index.py | 13 ++++--------- 6 files changed, 20 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 73c2300..0cb5908 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,9 @@ bup bup-* randomgen -randomgen.exe *.o *.so +*.exe *.dll *~ *.pyc diff --git a/Makefile b/Makefile index 063b3e5..2249d0e 100644 --- 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 diff --git a/client.py b/client.py index 6a373eb..7be235a 100644 --- 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: diff --git a/cmd-index.py b/cmd-index.py index bf1e503..c3b6ce9 100755 --- a/cmd-index.py +++ b/cmd-index.py @@ -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: diff --git a/helpers.py b/helpers.py index 344d001..54b099c 100644 --- a/helpers.py +++ b/helpers.py @@ -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: diff --git a/index.py b/index.py index 10ec093..93841ed 100644 --- 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) -- 2.39.2