rx: _remove_existing after accept
This commit is contained in:
parent
56a0a1f584
commit
33526b2180
|
@ -1,5 +1,5 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import os, sys, six, tempfile, zipfile, hashlib
|
import os, sys, six, tempfile, zipfile, hashlib, shutil
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
from humanize import naturalsize
|
from humanize import naturalsize
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
|
@ -259,16 +259,26 @@ class TwistedReceiver:
|
||||||
if os.path.exists(abs_destname):
|
if os.path.exists(abs_destname):
|
||||||
if self.args.output_file: # overwrite is intentional
|
if self.args.output_file: # overwrite is intentional
|
||||||
self._msg(u"Overwriting '%s'" % destname)
|
self._msg(u"Overwriting '%s'" % destname)
|
||||||
|
if self.args.accept_file:
|
||||||
|
self._remove_existing(abs_destname)
|
||||||
else:
|
else:
|
||||||
self._msg(u"Error: refusing to overwrite existing '%s'" % destname)
|
self._msg(u"Error: refusing to overwrite existing '%s'" % destname)
|
||||||
raise TransferRejectedError()
|
raise TransferRejectedError()
|
||||||
return abs_destname
|
return abs_destname
|
||||||
|
|
||||||
|
def _remove_existing(self, path):
|
||||||
|
if os.path.isfile(path):
|
||||||
|
os.remove(path)
|
||||||
|
elif os.path.isdir(path):
|
||||||
|
shutil.rmtree(path)
|
||||||
|
|
||||||
def _ask_permission(self):
|
def _ask_permission(self):
|
||||||
with self.args.timing.add("permission", waiting="user") as t:
|
with self.args.timing.add("permission", waiting="user") as t:
|
||||||
while True and not self.args.accept_file:
|
while True and not self.args.accept_file:
|
||||||
ok = six.moves.input("ok? (y/n): ")
|
ok = six.moves.input("ok? (y/n): ")
|
||||||
if ok.lower().startswith("y"):
|
if ok.lower().startswith("y"):
|
||||||
|
if os.path.exists(self.abs_destname):
|
||||||
|
self._remove_existing(self.abs_destname)
|
||||||
break
|
break
|
||||||
print(u"transfer rejected", file=sys.stderr)
|
print(u"transfer rejected", file=sys.stderr)
|
||||||
t.detail(answer="no")
|
t.detail(answer="no")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user