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: str, mode: int=0o755)
| 337 | shutil.copy(src, dst) |
| 338 | |
| 339 | def ensure_dir_exists(path: str, mode: int=0o755): |
| 340 | """ensure that a directory exists |
| 341 | |
| 342 | If it doesn't exist, try to create it and protect against a race condition |
| 343 | if another process is doing the same. |
| 344 | |
| 345 | The default permissions are 755, which differ from os.makedirs default of 777. |
| 346 | """ |
| 347 | if not os.path.exists(path): |
| 348 | try: |
| 349 | os.makedirs(path, mode=mode) |
| 350 | except OSError as e: |
| 351 | if e.errno != errno.EEXIST: |
| 352 | raise |
| 353 | elif not os.path.isdir(path): |
| 354 | raise IOError("%r exists but is not a directory" % path) |
no outgoing calls
no test coverage detected
searching dependent graphs…