]> err.no Git - dak/commitdiff
Handle *.dak-commands files owned by a different user.
authorAnsgar Burchardt <ansgar@debian.org>
Sun, 20 Jan 2013 09:59:40 +0000 (10:59 +0100)
committerAnsgar Burchardt <ansgar@debian.org>
Sun, 20 Jan 2013 09:59:40 +0000 (10:59 +0100)
dak/process_commands.py
daklib/command.py

index d3c794c254c7b8ba6497952b501c6634a38807a4..c679d9c2422acb04582a7fef3d309468c7566216 100644 (file)
@@ -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()
index 3fe47703765a0c8c13e87027172432a390cfdd4e..c1f9c706e02a443145c2065f5cc66850d9e5952b 100644 (file)
@@ -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