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

Unable to put a file to a directory in LocalFileSystem #967

Closed
xuepeixin opened this issue May 17, 2022 · 6 comments
Closed

Unable to put a file to a directory in LocalFileSystem #967

xuepeixin opened this issue May 17, 2022 · 6 comments

Comments

@xuepeixin
Copy link

I tried to copy a file to another directory with the put function of LocalFileSystem, the code is

from fsspec.implementations.local import LocalFileSystem

fs = LocalFileSystem()
fs.mkdir('/tmp/test_dir0')
fs.mkdir('/tmp/test_dir1')
with open('/tmp/test_dir0/a', 'w') as fp:
    fp.write('test')
fs.put('/tmp/test_dir0/a', '/tmp/test_dir1/')

but I get an Error traceback like this:

  File "<stdin>", line 1, in <module>
  File "/home/user/anaconda3/envs/py38/lib/python3.8/site-packages/fsspec/spec.py", line 823, in put
    self.put_file(lpath, rpath, **kwargs)
  File "/home/user/anaconda3/envs/py38/lib/python3.8/site-packages/fsspec/implementations/local.py", line 127, in put_file
    return self.cp_file(path1, path2, **kwargs)
  File "/home/user/anaconda3/envs/py38/lib/python3.8/site-packages/fsspec/implementations/local.py", line 117, in cp_file
    shutil.copyfile(path1, path2)
  File "/home/user/anaconda3/envs/py38/lib/python3.8/shutil.py", line 264, in copyfile
    with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
IsADirectoryError: [Errno 21] Is a directory: '/tmp/test_dir1'

However the doc of put tell me that

If rpath ends with a "/", it will be assumed to be a directory, and target files will go within.

I guess directory is supported by design, so is it a bug?

@martindurant
Copy link
Member

I wonder, does cp work? For LocalFileSytem, that should be the same thing (which is why it isn't tested).

@xuepeixin
Copy link
Author

Yes, cp works for me. But the put does not act as I expected.

@martindurant
Copy link
Member

Would you consider making a PR in which

put = cp

forLocalFileSystem to simplify things?

@xuepeixin
Copy link
Author

Ok, I will try.

@ianthomas23
Copy link
Collaborator

This was fixed by #1148. Test code from above:

from fsspec.implementations.local import LocalFileSystem

fs = LocalFileSystem()
fs.mkdir('/tmp/test_dir0')
fs.mkdir('/tmp/test_dir1')
with open('/tmp/test_dir0/a', 'w') as fp:
    fp.write('test')
fs.put('/tmp/test_dir0/a', '/tmp/test_dir1/')
print(fs.find('/tmp/test_dir1'))

produces output

['/tmp/test_dir1/a']

as expected.

@martindurant
Copy link
Member

Nice to see all these closed!

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 a pull request may close this issue.

3 participants