Identify binary files in plainblob.
Wed Dec 21 15:00:33 UTC 2005 Alberto Bertogli <albertogli@telpin.com.ar>
* Identify binary files in plainblob.
If we want to do a plainblob of a binary file, it's better to offer a proper
download than to display it as text/plain.
This patch identifies binary files (looking at darcs' information) and offers
them for download with the proper name.
diff -rN -u old-darcsweb/darcsweb.cgi new-darcsweb/darcsweb.cgi
--- old-darcsweb/darcsweb.cgi 2013-07-13 15:15:53.000000000 +0000
+++ new-darcsweb/darcsweb.cgi 2013-07-13 15:15:53.000000000 +0000
@@ -395,6 +395,11 @@
def print_plain_header():
print "Content-type: text/plain; charset=utf-8\n"
+def print_binary_header(fname = None):
+ print "Content-type: application/octet-stream"
+ if fname:
+ print "Content-Disposition:attachment;filename=%s" % fname
+ print
#
@@ -1673,10 +1678,16 @@
def do_plainblob(fname):
- print_plain_header()
f = open(realpath(fname), 'r')
- for l in f:
- sys.stdout.write(fixu8(l))
+
+ if isbinary(fname):
+ print_binary_header(os.path.basename(fname))
+ for l in f:
+ sys.stdout.write(l)
+ else:
+ print_plain_header()
+ for l in f:
+ sys.stdout.write(fixu8(l))
def do_annotate(fname, phash, style):