--- dispatch-conf 2003-08-12 08:38:10.000000000 -0700 +++ dispatch-conf 2003-08-12 10:14:47.000000000 -0700 @@ -20,6 +20,7 @@ DIFF_CONTENTS = 'diff -Nau %s %s' DIFF_CVS_INTERP = 'diff -Nau %s %s | grep "^[+-][^+-]" | grep -v "# .Header:.*"' DIFF_WSCOMMENTS = 'diff -Nau %s %s | grep "^[+-][^+-]" | grep -v "^[-+]#" | grep -v "^[-+][:space:]*$"' +MKTEMP = 'mktemp /tmp/dispatch-conf.merged.%i.XXXXXX' MERGE = 'sdiff --suppress-common-lines --output=%s %s %s' MANDATORY_OPTS = [ 'archive-dir', 'diff', 'pager', 'replace-cvs', 'replace-wscomments' ] @@ -95,10 +96,10 @@ elif c == 'n': break elif c == 'f': - merged = '/tmp/dispatch-conf.merged.%i' % (os.getpid (),) + merged = commands.getoutput (MKTEMP % (os.getpid ())) print os.system (MERGE % (merged, conf ['current'], conf ['new'])) - os.rename (merged, conf ['new']) + self.replace (merged, conf ['new']) continue elif c == 'k': os.remove (conf ['new']) @@ -132,11 +133,18 @@ except (IOError, os.error), why: print >> sys.stderr, 'dispatch-conf: Error copying %s to %s: %s; fatal' % \ (curconf, archive, str(why)) + + # this should be changed to shutil.move() when we move to python 2.3 try: - os.rename (newconf, curconf) + shutil.copy2 (newconf, curconf) except (IOError, os.error), why: - print >> sys.stderr, 'dispatch-conf: Error renaming %s to %s: %s; fatal' % \ + print >> sys.stderr, 'dispatch-conf: Error copying %s to %s: %s; fatal' % \ (newconf, curconf, str(why)) + try: + os.unlink (newconf) + except (IOError, os.error), why: + print >> sys.stderr, 'dispatch-conf: Error removing %s: %s; fatal' % \ + (newconf, str(why)) break else: print >> sys.stderr, 'dispatch-conf: Error archiving files -- exhausted slots???; fatal'