flying-circus / pyfilesystem

Automatically exported from code.google.com/p/pyfilesystem
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Not able to create file in memoryfs #48

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello everyone, i try to use your project but i have a problem : i cannot 
create a file when I use memoryfs.

What steps will reproduce the problem?
1. from fs.memoryfs import MemoryFS
2. fs = MemoryFS('/')
3. fs.open('file', 'w')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/venv/fs/fs/fs/base.py", line 536, in createfile
    f = self.open(path, 'wb')
  File "~/venv/fs/fs/fs/base.py", line 122, in acquire_lock
    return func(self, *args, **kwargs)
  File "fs/memoryfs.py", line 365, in open
    raise ResourceLockedError(path)
fs.errors.ResourceLockedError: Resource is locked: coucou

3bis. x.createfile('file2')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/venv/fs/fs/fs/base.py", line 536, in createfile
    f = self.open(path, 'wb')
  File "~/venv/fs/fs/fs/base.py", line 122, in acquire_lock
    return func(self, *args, **kwargs)
  File "fs/memoryfs.py", line 371, in open
    mem_file = self.file_factory(path, self, None, mode)
TypeError: 'str' object is not callable

What is the expected output? What do you see instead?

Open should return an file-like object instead, i think.

What version of the product are you using? On what operating system?

r513 on Mac OS X.6

Original issue reported on code.google.com by Lothiral...@gmail.com on 31 Oct 2010 at 5:55

GoogleCodeExporter commented 9 years ago
MemoryFS doesn't take a path in the constructor. You generally wont need to 
pass any arguments to the constructor.

Try this instead:

    fs = MemoryFS()

http://packages.python.org/fs/memoryfs.html#module-fs.memoryfs

Original comment by willmcgugan on 31 Oct 2010 at 5:58

GoogleCodeExporter commented 9 years ago
Ok, thanks it's works.

But it should be more intuitive if MemoryFS raise an exception if argument is 
not correct.

Original comment by Lothiral...@gmail.com on 31 Oct 2010 at 6:11