[v5,21/21] zdtm: Don't fail in __construct_root if entries exist

Submitted by Cyrill Gorcunov on May 10, 2018, 2:58 p.m.

Details

Message ID 20180510145801.12322-22-gorcunov@gmail.com
State New
Series "Add support of deleted unix sockets"
Headers show

Commit Message

Cyrill Gorcunov May 10, 2018, 2:58 p.m.
Otherwise we might get

 | OSError: [Errno 17] File exists: '/tmp/criu-root-f8klhI/bin'
 |     os.symlink(".." + ldir, self.root + "/usr" + ldir)
 | OSError: [Errno 17] File exists
 |  File "zdtm.py", line 209, in __mknod
 |     os.mknod(name, stat.S_IFCHR, rdev)
 | OSError: [Errno 17] File exists

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 test/zdtm.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/test/zdtm.py b/test/zdtm.py
index 3531428808a3..e622b4a0e1fc 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -214,16 +214,19 @@  arch = os.uname()[4]
 				rdev = os.stat(name).st_rdev
 
 		name = self.root + name
-		os.mknod(name, stat.S_IFCHR, rdev)
-		os.chmod(name, 0666)
+		if not os.access(name, os.F_OK):
+			os.mknod(name, stat.S_IFCHR, rdev)
+			os.chmod(name, 0666)
 
 	def __construct_root(self):
 		for dir in self.__root_dirs:
-			os.mkdir(self.root + dir)
-			os.chmod(self.root + dir, 0777)
+			if not os.access(self.root + dir, os.F_OK):
+				os.mkdir(self.root + dir)
+				os.chmod(self.root + dir, 0777)
 
 		for ldir in ["/bin", "/sbin", "/lib", "/lib64"]:
-			os.symlink(".." + ldir, self.root + "/usr" + ldir)
+			if not os.access(self.root + "/usr" + ldir, os.F_OK):
+				os.symlink(".." + ldir, self.root + "/usr" + ldir)
 
 		self.__mknod("tty", os.makedev(5, 0))
 		self.__mknod("null", os.makedev(1, 3))