From: Ansgar Burchardt Date: Sun, 20 Jan 2013 09:59:40 +0000 (+0100) Subject: Handle *.dak-commands files owned by a different user. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3348848da60163e2aeaaa94454147764f5edd1d;p=dak Handle *.dak-commands files owned by a different user. --- diff --git a/dak/process_commands.py b/dak/process_commands.py index d3c794c2..c679d9c2 100644 --- a/dak/process_commands.py +++ b/dak/process_commands.py @@ -66,8 +66,11 @@ def main(argv=None): log.log(['unexpected filename', basename]) continue + with open(fn, 'r') as fh: + data = fh.read() + try: - command = CommandFile(fn, log) + command = CommandFile(basename, data, log) command.evaluate() except: created = os.stat(fn).st_mtime @@ -83,7 +86,8 @@ def main(argv=None): dst = find_next_free(os.path.join(donedir, basename)) with FilesystemTransaction() as fs: - fs.move(fn, dst, mode=0o644) + fs.unlink(fn) + fs.create(dst, mode=0o644).write(data) fs.commit() log.close() diff --git a/daklib/command.py b/daklib/command.py index 3fe47703..c1f9c706 100644 --- a/daklib/command.py +++ b/daklib/command.py @@ -35,15 +35,15 @@ class CommandError(Exception): pass class CommandFile(object): - def __init__(self, path, log=None): + def __init__(self, filename, data, log=None): if log is None: from daklib.daklog import Logger log = Logger() self.cc = [] self.result = [] self.log = log - self.path = path - self.filename = os.path.basename(path) + self.filename = filename + self.data = data def _check_replay(self, signed_file, session): """check for replays @@ -130,8 +130,7 @@ class CommandFile(object): keyrings = session.query(Keyring).filter_by(active=True).order_by(Keyring.priority) keyring_files = [ k.keyring_name for k in keyrings ] - raw_contents = open(self.path, 'r').read() - signed_file = SignedFile(raw_contents, keyring_files) + signed_file = SignedFile(self.data, keyring_files) if not signed_file.valid: self.log.log(['invalid signature', self.filename]) return False