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>
Mon, 16 Feb 2015 15:37:11 +0000 (17:37 +0200)
Change-Id: I3652dd3027576744335abcd6c4f4b0cde2b7592c
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
obs_service_gbp/command.py

index edc2eb435d1f7bc07e92c22b525e03c7885ebc44..0f7d8ea4b13795de6737a0896d6627267bcd1652 100644 (file)
@@ -108,6 +108,15 @@ def read_config(filenames=None):
     # 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
@@ -149,9 +158,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())