Set correct ownership of the exported files
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 16 Feb 2015 14:28:27 +0000 (16:28 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 17 Feb 2015 11:10:57 +0000 (13:10 +0200)
Change-Id: I3652dd3027576744335abcd6c4f4b0cde2b7592c
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
(cherry picked from commit 5ccc4df5abe500e4c561096fa964b1f54627cea2)

obs_service_gbp/command.py

index cc14c4fc908c8c58f456792253afb97b63e51a98..c217bd0247f5f477ae3c29a84d461c8a772976d9 100644 (file)
@@ -98,6 +98,15 @@ def read_config(filenames):
     # We only use keys from one section, for now
     return dict(parser.items('general'))
 
+def move_dir_content(source, target):
+    """Move files from dir to another and change ownership"""
+    euid = os.geteuid()
+    egid = os.getegid()
+    for fname in os.listdir(source):
+        tgt_path = os.path.join(target, fname)
+        shutil.move(os.path.join(source, fname), tgt_path)
+        os.lchown(tgt_path, euid, egid)
+
 def gbp_export(repo, args, config):
     """Export sources with GBP"""
     # Create output directories
@@ -139,9 +148,7 @@ def gbp_export(repo, args, config):
                 LOGGER.error('Git-buildpackage failed, unable to export Debian '
                              'sources package files')
                 return 3
-        for fname in os.listdir(tmp_out):
-            shutil.move(os.path.join(tmp_out, fname),
-                        os.path.join(args.outdir, fname))
+        move_dir_content(tmp_out, args.outdir)
     except GbpChildBTError as err:
         LOGGER.error('Unhandled exception in GBP:\n'
                      '%s', err.prettyprint_tb())