flying-circus / pyfilesystem

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

Zero-length read behaves as full-file read #161

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

   >>> import fs.memoryfs
   >>> x = fs.memoryfs.MemoryFS()
   >>> x.setcontents("foo.txt", "hello")
   >>> f = x.open("foo.txt", 'r')
   >>> x.read(0)
   hello

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

  I expect to read 0 bytes when passing 0 to the read() method, but it behaves
  as if I passed no argument and returns the rest of the file. I noticed this
  during a unit test which patched __builtin__.open with fs.memoryFS.open. file.read()
  matches my expectation, distinguishing between a 0 argument and a None argument.

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

  This is observed in version 0.4.0 in python 2.6.6 on Scientific Linux 6.3

Original issue reported on code.google.com by clint.he...@gmail.com on 5 Sep 2013 at 7:36

GoogleCodeExporter commented 9 years ago
I can't reproduce this on trunk. It's probably been fixed.

Can you try the latest from svn, and confirm it resolves this issue?

Original comment by willmcgugan on 5 Sep 2013 at 10:24

GoogleCodeExporter commented 9 years ago
I can confirm that the problem is not present in svn, but it appears that the 
newest version requires Python 2.7, due to the use of io.SEEK_* constants. I am 
currently using 0.4.0 with Python 2.6.

Original comment by clint.he...@gmail.com on 6 Sep 2013 at 4:10

GoogleCodeExporter commented 9 years ago
Ah. I've fixed that. We want to maintain 2.6 compatibility for the foreseeable 
future.

Original comment by willmcgugan on 6 Sep 2013 at 9:41

GoogleCodeExporter commented 9 years ago
Regarding the SEEK_* stuff - not that it really matters, but for the sake of 
consistency would it have been better to fix it the same way that 
http://code.google.com/p/pyfilesystem/source/browse/trunk/fs/remote.py#37 does?

In fact, I just did a:
grep -R SEEK_\\\(SET\\\|CUR\\\|END\\\) fs | grep -v '/.svn/' | grep -v ^Binary
and that shows that the only files _not_ using the fs.SEEK_* constants are
fs/tests/__init__.py
fs/iotools.py
fs/expose/dokan/__init__.py
fs/memoryfs.py

so maybe they should all be modified to use the fs versions? *shrug*

Original comment by gc...@loowis.durge.org on 7 Sep 2013 at 7:20

GoogleCodeExporter commented 9 years ago
Good point. I had forgotten we had those constants defined. I'll change that.

Original comment by willmcgugan on 8 Sep 2013 at 11:02

GoogleCodeExporter commented 9 years ago
Good point. I had forgotten we had those constants defined. I'll change that.

Original comment by willmcgugan on 8 Sep 2013 at 11:05

GoogleCodeExporter commented 9 years ago
I just confirmed with the latest version (r865) that the 'read(0)' still reads 
all data when opening the file in binary mode (due, presumably, to the file 
object being an fs.iotools.RawWrapper instead of a io.TextIOWrapper).

Original comment by clint.he...@gmail.com on 9 Sep 2013 at 7:55

GoogleCodeExporter commented 9 years ago
Ah. I found the root cause. I've pushed the fix. Thanks for investigating.

Original comment by willmcgugan on 9 Sep 2013 at 8:24