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

Create filesystem if it does not exist and 'create' flag is set in open_fs #15

Open
nb-programmer opened this issue Nov 16, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@nb-programmer
Copy link

open_fs function takes in the create optional argument, which when set, will create the filesystem instead raising an exception on opening a (non-existent) disk image file.
Currently, pyfatfs does not make use of this argument and raises a pyfatfs._exceptions.PyFATException when opening a .img file.

For example:

>>> import fs
>>> fatfile = fs.opener.open_fs('fat://test.img', create=True) 
Traceback (most recent call last):
  File "C:\Users\[removed]\AppData\Local\Programs\Python\Python39\lib\site-packages\pyfatfs\PyFat.py", line 241, in open
    self.__set_fp(open(filename, mode=mode))
FileNotFoundError: [Errno 2] No such file or directory: 'test.img'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\[removed]\AppData\Local\Programs\Python\Python39\lib\site-packages\fs\opener\registry.py", line 229, in open_fs
    _fs, _path = self.open(
  File "C:\Users\[removed]\AppData\Local\Programs\Python\Python39\lib\site-packages\fs\opener\registry.py", line 186, in open
    open_fs = opener.open_fs(fs_url, parse_result, writeable, create, cwd)
  File "C:\Users\[removed]\AppData\Local\Programs\Python\Python39\lib\site-packages\pyfatfs\PyFatFSOpener.py", line 36, in open_fs
    fs = PyFatFS(filename=parse_result.resource,
  File "C:\Users\[removed]\AppData\Local\Programs\Python\Python39\lib\site-packages\pyfatfs\PyFatFS.py", line 53, in __init__
    self.fs.open(filename, read_only=read_only)
  File "C:\Users\[removed]\AppData\Local\Programs\Python\Python39\lib\site-packages\pyfatfs\PyFat.py", line 243, in open
    raise PyFATException(f"Cannot open given file \'{filename}\'.",
pyfatfs._exceptions.PyFATException: Cannot open given file 'test.img'.

But for a different file, it works as expected:

>>> zipfile = fs.opener.open_fs('zip://test.zip', create=True)
>>> print(zipfile) 
<zipfs-write 'test.zip'>

So an option to create a blank filesystem would be nice

@nathanhi nathanhi added the enhancement New feature or request label Nov 21, 2021
@nathanhi
Copy link
Owner

nathanhi commented Nov 21, 2021

I agree, adding mkfs support is desirable and is indeed planned for 1.0. Not too sure if a simple create=True will be enough though due to the vast amount of configuration options a FAT fs has. For now, only a dedicated mkfs function is planned but I will consider it once we have working mkfs code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants