bugfix: run build command directly if user is root
authorhasan wan <hasan.wan@intel.com>
Sun, 3 Jun 2012 10:08:05 +0000 (18:08 +0800)
committerhasan wan <hasan.wan@intel.com>
Sun, 3 Jun 2012 10:08:05 +0000 (18:08 +0800)
gitbuildsys/cmd_build.py

index 2fb061c..7dd09d7 100644 (file)
@@ -86,7 +86,7 @@ def get_reops_conf():
 
     # get repo settings form build section
     repo_urls = []
-    repo_auths = []
+    repo_auths = set()
     for repo in repos:
         repo_auth = ''
         # get repo url
@@ -117,9 +117,9 @@ def get_reops_conf():
         if not valid:
             continue
         repo_auth = repo_auth[:-1]
-        repo_auths.append(repo_auth)
+        repo_auths.add(repo_auth)
 
-    return repo_urls, ''.join(repo_auths)
+    return repo_urls, ' '.join(repo_auths)
 
 def do(opts, args):
 
@@ -211,14 +211,17 @@ def do(opts, args):
         cmd += ['--rsync-src=%s' % os.path.abspath(workdir)]
         cmd += ['--rsync-dest=/home/abuild/rpmbuild/BUILD/%s-%s' % (name, version)]
 
-    sucmd = configmgr.get('su_wrapper', 'build').split()
-    if sucmd[0] == 'su':
-        if sucmd[-1] == '-c':
-            sucmd.pop()
-        cmd = sucmd + ['-s', cmd[0], 'root', '--' ] + cmd[1:]
+    # if current user is root, don't run with sucmd
+    if os.getuid == 0:
+        os.environ['GBS_BUILD_REPOAUTH'] = repo_auth_conf
     else:
-        cmd = sucmd + ['GBS_BUILD_REPOAUTH=%s' % repo_auth_conf ] + cmd
-
+        sucmd = configmgr.get('su_wrapper', 'build').split()
+        if sucmd[0] == 'su':
+            if sucmd[-1] == '-c':
+                sucmd.pop()
+            cmd = sucmd + ['-s', cmd[0], 'root', '--' ] + cmd[1:]
+        else:
+            cmd = sucmd + ['GBS_BUILD_REPOAUTH=%s' % repo_auth_conf ] + cmd
     # runner.show() can't support interactive mode, so use subprocess insterad.
     try:
         rc = subprocess.call(cmd)