Skip to content

Commit

Permalink
#955: better error handling and logging for files that are too big
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@10362 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Aug 20, 2015
1 parent ae3ebed commit 5e8c517
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/xpra/server/server_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1419,8 +1419,8 @@ def _process_print(self, proto, packet):
printlog.warn("Warning: client %s does not have a '%s' printer", ss.uuid, printer)
continue
printlog("sending file to %s for printing on %s", ss, printer)
ss.send_file(filename, mimetype, file_data, True, True, options)
sent += 1
if ss.send_file(filename, mimetype, file_data, True, True, options):
sent += 1
#warn if not sent:
if sent==0:
l = printlog.warn
Expand Down
23 changes: 19 additions & 4 deletions src/xpra/server/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,22 +1525,37 @@ def remove_printers(self):


def send_file(self, filename, mimetype, data, printit, openit, options={}):
assert self.file_transfer
filelog("send_file%s", (filename, mimetype, "%s bytes" % len(data), printit, openit, options))
if printit:
if not self.printing:
printlog.warn("Warning: printing is not enabled for %s", self)
return False
action = "print"
l = printlog
else:
if not self.file_transfer:
filelog.warn("Warning: file transfers are not enabled for %s", self)
return False
action = "transfer"
l = filelog
l("send_file%s", (filename, mimetype, "%s bytes" % len(data), printit, openit, options))
#TODO:
# * client ACK
# * stream it (don't load the whole file!)
# * timeouts
# * checksum
# * rate control
# * xpra info with queue and progress
basefilename = os.path.basename(filename)
filesize = len(data)
cdata = self.compressed_wrapper("file-data", data)
assert len(cdata)<=filesize #compressed wrapper ensures this is true
if filesize>self.file_size_limit*1024*1024:
raise Exception("this file is too large: %iMB (the file size limit for this client is %iMB" % (filesize//1024//1024, self.file_size_limit))
b = os.path.basename(filename)
l.warn("Warning: cannot %s the file '%s'", action, b)
l.warn(" this file is too large: %sB", std_unit(filesize, unit=1024))
l.warn(" the file size limit for %s is %iMB", self, self.file_size_limit)
return False
self.send("send-file", basefilename, mimetype, printit, openit, filesize, cdata, options)
return True

def send_client_command(self, *args):
self.send("control", *args)
Expand Down

0 comments on commit 5e8c517

Please sign in to comment.