[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master] Handle *.dak-commands files owned by a different user.



---
 dak/process_commands.py |    8 ++++++--
 daklib/command.py       |    9 ++++-----
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/dak/process_commands.py b/dak/process_commands.py
index d3c794c..c679d9c 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 3fe4770..c1f9c70 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
-- 
1.7.2.5


Reply to: