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
Add async wrapper for commonly used filesystem functions #3584
base: main
Are you sure you want to change the base?
Conversation
if await async_exists(self.hacs.hass, path): | ||
await async_remove(self.hacs.hass, path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's bad to go into the executor twice. Can we add a feature to async_remove
to not fail if a file doesn't exist ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's changed to use Path(filepath).unlink(missing_ok=True)
it would be a single one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could give async_remove
a missing_ok
flag
@@ -467,7 +468,7 @@ def _write_file(): | |||
self.log.error("Could not write data to %s - %s", file_path, error) | |||
return False | |||
|
|||
return os.path.exists(file_path) | |||
return await async_exists(self.hass, file_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check should be part of the _write_file
function, that should be fixed in a separate PR though.
Add async wrapper for commonly used filesystem functions
os.path.exists
andos.remove
This PR simply wraps file system accesses which currently happen from the event loop, separate follow-up PRs will handle optimizing the number of file system calls as needed.