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

spec: get_file: don't pollute with files and fds #1191

Merged
merged 2 commits into from
Feb 26, 2023

Conversation

efiop
Copy link
Member

@efiop efiop commented Feb 20, 2023

Currently if anything happens in fs.open we will leave an empty file in user's workspace and also won't close the file descriptor. Both things are pretty bad.

Currently if anything happens in fs.open we will leave an empty file in user's
workspace and also won't close the file descriptor. Both things are pretty bad.
@efiop efiop added the bug Something isn't working label Feb 20, 2023
Comment on lines 849 to +853
if isfilelike(lpath):
outfile = lpath
else:
if self.isdir(rpath):
os.makedirs(lpath, exist_ok=True)
return None
elif self.isdir(rpath):
os.makedirs(lpath, exist_ok=True)
return None
Copy link
Member Author

@efiop efiop Feb 20, 2023

Choose a reason for hiding this comment

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

These don't seem mutually exclusive, but I've preserved logic that was here before. Not sure what outfile argument is even used for, but it is strange that makedirs-behaviour (which is also odd by itself) doesn't affect it.

EDIT: nevermind, indeed they are mutually exclusive.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also calling isdir on every file is very wasteful. Ideally, we should get rid of this at some point in the future, as it seems to be a misplaced piece of logic from fs.get rather than something that is intentional here. From user's perspective I would expect IsADirectoryError here.

efiop added a commit to iterative/scmrepo that referenced this pull request Feb 20, 2023
efiop added a commit to iterative/scmrepo that referenced this pull request Feb 20, 2023
efiop added a commit to iterative/scmrepo that referenced this pull request Feb 20, 2023
@martindurant martindurant merged commit c75410b into fsspec:master Feb 26, 2023
agoodm pushed a commit to agoodm/filesystem_spec that referenced this pull request Mar 14, 2023
* spec: get_file: don't pollute with files and fds

Currently if anything happens in fs.open we will leave an empty file in user's
workspace and also won't close the file descriptor. Both things are pretty bad.

* http: _get_file: don't leak file descriptor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants