From 1b08ef0f9c0c8f2c63510ef7e3607fc028e4cc71 Mon Sep 17 00:00:00 2001 From: Ryan Johnston Date: Wed, 29 Jul 2015 09:59:40 -0400 Subject: [PATCH] Let's try just a bit more carefully to keep seek_pos and pos accurate. Also allow multiple attempts to close remote dropbox file. References #2 --- dropboxfs.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dropboxfs.py b/dropboxfs.py index 407c7da..d15a28e 100644 --- a/dropboxfs.py +++ b/dropboxfs.py @@ -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() @@ -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