ensure that a directory exists If it doesn't exist, try to create it and protect against a race condition if another process is doing the same. The default permissions are 755, which differ from os.makedirs default of 777.
(path, mode=0o755)
| 419 | shutil.copy(src, dst) |
| 420 | |
| 421 | def ensure_dir_exists(path, mode=0o755): |
| 422 | """ensure that a directory exists |
| 423 | |
| 424 | If it doesn't exist, try to create it and protect against a race condition |
| 425 | if another process is doing the same. |
| 426 | |
| 427 | The default permissions are 755, which differ from os.makedirs default of 777. |
| 428 | """ |
| 429 | if not os.path.exists(path): |
| 430 | try: |
| 431 | os.makedirs(path, mode=mode) |
| 432 | except OSError as e: |
| 433 | if e.errno != errno.EEXIST: |
| 434 | raise |
| 435 | elif not os.path.isdir(path): |
| 436 | raise IOError("%r exists but is not a directory" % path) |
no outgoing calls
no test coverage detected