Skip to content

Commit

Permalink
Let's try just a bit more carefully to keep seek_pos and pos accurate…
Browse files Browse the repository at this point in the history
…. Also allow multiple attempts to close remote dropbox file. References btimby#2
  • Loading branch information
Ryan Johnston committed Jul 29, 2015
1 parent 853caca commit 1b08ef0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions dropboxfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,16 @@ def read(self, amt=None):
elif self.seek_pos > self.pos:
# Read ahead enough to reconcile pos and seek_pos
self.r.read(self.pos - self.seek_pos)
self.pos = self.seek_pos
self.pos = self.seek_pos

# Update position pointers
if amt:
self.pos += amt
self.seek_pos += amt
else:
self.pos = self.bytes
self.seek_pos = self.bytes
return self.r.read(amt)

else:
self.close()

Expand Down Expand Up @@ -206,8 +208,10 @@ def close(self):
is already closed. As a convenience, it is allowed to call this method
more than once; only the first call, however, will have an effect.
"""
if not self.closed:
# It's a memory leak if self.r not closed.
if not self.r.isclosed():
self.r.close()
if not self.closed:
self.closed = True


Expand Down

0 comments on commit 1b08ef0

Please sign in to comment.