From a73fd309f5f23c95fac299ce96c501187c463c9b Mon Sep 17 00:00:00 2001 From: Steve Milner Date: Wed, 29 Nov 2017 15:55:19 -0500 Subject: [PATCH] syscontainers: ensure destdir exists Closes: https://github.com/projectatomic/atomic/issues/1138 --- Atomic/syscontainers.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Atomic/syscontainers.py b/Atomic/syscontainers.py index c5d3f2ec..185c1036 100644 --- a/Atomic/syscontainers.py +++ b/Atomic/syscontainers.py @@ -688,17 +688,20 @@ def _is_repo_on_the_same_filesystem(repo, destdir): :type destdir: str """ repo_stat = os.stat(repo) - destdir_stat = os.stat(destdir) + try: + destdir_stat = os.stat(destdir) + except OSError as e: + if e.errno == errno.ENOENT: + # The directory doesn't exist + os.makedirs(destdir) + destdir_stat = os.stat(destdir) + else: + raise e + # Simple case: st_dev is different if repo_stat.st_dev != destdir_stat.st_dev: return False - try: - os.makedirs(destdir) - except OSError as e: - if e.errno != errno.EEXIST: - raise - src_file = os.path.join(repo, "config") dest_file = os.path.join(destdir, "samefs-check-{}".format(os.getpid())) # Try to create a link, check if it fails with EXDEV