Skip to content

Commit

Permalink
Added support for file deletion in FileRef
Browse files Browse the repository at this point in the history
  • Loading branch information
Elmo Todurov committed Aug 29, 2013
1 parent 234537e commit a7f1778
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spinoff/contrib/filetransfer/fileref.py
Expand Up @@ -105,6 +105,10 @@ def upload(self, url):
raise FileNotFound
return response

def delete(self):
if not self.server.ask(('delete', self.file_id)):
raise FileNotFound

def _transfer(self, fh, on_progress):
request = get_context().spawn(Request.using(server=self.server, file_id=self.file_id, size=self.size, abstract_path=self.abstract_path))
more = True
Expand Down
9 changes: 9 additions & 0 deletions spinoff/contrib/filetransfer/server.py
Expand Up @@ -62,6 +62,15 @@ def receive(self, msg):
file_path, _ = self.published[file_id]
r = requests.post(url, files={'file': open(file_path, 'rb')})
self.reply((True, (r.status_code, dict(r.headers), r.text)))
elif ('delete', ANY) == msg:
_, file_id = msg
if file_id not in self.published:
self.reply(False)
else:
file_path, _ = self.published[file_id]
del self.published[file_id]
os.unlink(file_path)
self.reply(True)

def _touch_file(self, file_id):
file_path, time_added = self.published[file_id]
Expand Down

0 comments on commit a7f1778

Please sign in to comment.