Skip to content

Commit

Permalink
SFTPStorage: Fix reopen file (#746)
Browse files Browse the repository at this point in the history
Default Django implementation uses os.path.exists and open(), which is wrong.
  • Loading branch information
igerko authored and jschneier committed Sep 7, 2019
1 parent b7b2f7b commit 5b8d46f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions storages/backends/sftpstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ def write(self, content):
self._is_dirty = True
self._is_read = True

def open(self, mode=None):
if not self.closed:
self.seek(0)
elif self.name and self._storage.exists(self.name):
self.file = self._storage._open(self.name, mode or self.mode)
else:
raise ValueError("The file cannot be reopened.")

def close(self):
if self._is_dirty:
self._storage._save(self.name, self)
Expand Down

0 comments on commit 5b8d46f

Please sign in to comment.