Commit 51bbf002 authored by Graeme A Stewart's avatar Graeme A Stewart
Browse files

Handle case where destdir is a file correctly; add test case

Distinguish between file/directory on OSError 17 (file = bad; directory
= ok)
Added testcase - N.B. only fails on RACE CONDITION, so reproduce the
race manually in by doing “makedirs(dest_path)” twice!
parent 317f634b
......@@ -214,14 +214,15 @@ def update(src,dest,old_dest = None, syml = False, logdir = realpath(".")):
realdest = normpath(join(logdir, dest))
dest_path = split(realdest)[0]
realsrc = normpath(join(dest_path,src))
# To avoid race conditions, use EAFP
# To avoid race conditions on makedirs(), use EAFP (see GAUDI-1105)
if (not exists(realdest)) or (getmtime(realsrc) > getmtime(realdest)):
print "Create dir '{0}'".format(dest_path)
makedirs(dest_path) # <- manual race condition
print "Created dir '{0}'".format(dest_path)
except OSError as e:
# OSerror no. 17 is "file exists" - harmless for the directory
if e.errno != 17:
# OSerror no. 17 is "file exists" - harmless as long as the directory is there
if not(e.errno == 17 and isdir(dest_path)):
# the destination file is missing or older than the source
if syml and sys.platform != "win32" :
#! /usr/bin/env python
## @Package
# @brief Unittests for
import os
import os.path
import subprocess
import unittest
import uuid
import logging
msg = logging.getLogger(__name__)
# Unittests for this module
class installTests(unittest.TestCase):
def setUp(self):
self.fileToInstall = "testModule-" + str(uuid.uuid4()) + ".py"
with open(self.fileToInstall, "w") as fh:
fh.write('''#!/usr/bin/env python\npass\n''')
self.targetDir = "testModuleDir-" + str(uuid.uuid4())
def tearDown(self):
for path in (os.path.join(self.targetDir, self.fileToInstall), self.fileToInstall, "install.log"):
except OSError:
except OSError:
def test_installToExisitingPath(self):
cmd = ["", self.fileToInstall, self.targetDir]
rc =
self.assertEqual(rc, 0)
if __name__ == '__main__':
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment