Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use os.makedirs with exist_ok=True #292

Merged
merged 1 commit into from
Aug 11, 2022

Conversation

bbayles
Copy link
Contributor

@bbayles bbayles commented Aug 10, 2022

Fixes #291

This PR updates M3U8.dump such that it uses exist_ok=True when creating directories with os.makedirs.

The intended behavior now obtains:

  • if the directory already exists, it will be used.
  • if not, it will be created.
  • if there was some error in creating it, the associated exception will be raised.

if basename:
os.makedirs(basename)
except OSError as error:
if error.errno != errno.EEXIST:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block in the CPython source explains why this check isn't enough:

Cannot rely on checking for EEXIST, since the operating system could give priority to other errors like EACCES or EROFS

In #291, EACCES is the error code rather than EEXIST.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know! Thank you!

finally:
assert raised

def test_dump_should_raise_if_create_sub_directories_fails(tmpdir):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice tests

@mauricioabreu mauricioabreu merged commit a189d8b into globocom:master Aug 11, 2022
@bbayles bbayles deleted the issue-291-makedirs branch August 12, 2022 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

playlist.dump() fails when saving file to root folder on Windows.
2 participants