More fixes for extract_tarball

Signed-off-by: Martin J. Bligh <[email protected]>

Make sure we only look at top level directories, and abort if we get 2



git-svn-id: http://test.kernel.org/svn/autotest/trunk@1438 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/bin/autotest_utils.py b/client/bin/autotest_utils.py
index 31e9a03..5b61510 100755
--- a/client/bin/autotest_utils.py
+++ b/client/bin/autotest_utils.py
@@ -65,16 +65,26 @@
 
 
 def extract_tarball(tarball):
-	"""Returns the first extracted directory by the tarball."""
+	"""Returns the directory extracted by the tarball."""
 	extracted = cat_file_to_cmd(tarball, 'tar xvf - 2>/dev/null',
 					return_output=True).splitlines()
+
+	dir = None
+
 	for line in extracted:
 		line = re.sub(r'^./', '', line)
 		if not line or line == '.':
 			continue
-		if os.path.isdir(line):
-			return line
-	raise NameError('extracting tarball produced no dir')
+		topdir = line.split('/')[0]
+		if os.path.isdir(topdir):
+			if dir:
+				assert(dir == topdir)
+			else:
+				dir = topdir 
+	if dir:
+		return dir
+	else:
+		raise NameError('extracting tarball produced no dir')
 
 
 def get_md5sum(file_path):