Mercurial > moin > 1.9
changeset 3572:870cc4c47705
AttachFile: fix saving of drawing files
author | Thomas Waldmann <tw AT waldmann-edv DOT de> |
---|---|
date | Sat, 10 May 2008 17:28:44 +0200 |
parents | 35cd758720e8 |
children | 124d0ef138aa |
files | MoinMoin/action/AttachFile.py |
diffstat | 1 files changed, 17 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/MoinMoin/action/AttachFile.py Sat May 10 11:06:40 2008 +0200 +++ b/MoinMoin/action/AttachFile.py Sat May 10 17:28:44 2008 +0200 @@ -624,29 +624,36 @@ # get directory, and possibly create it attach_dir = getAttachDir(request, pagename, create=1) + savepath = os.path.join(attach_dir, basename + ext) + + # XXX would be better if it worked without this (at least for the png), + # XXX but it does not: + filecontent = filecontent.read() # read file completely into memory if ext == '.draw': _addLogEntry(request, 'ATTDRW', pagename, basename + ext) filecontent = filecontent.replace("\r", "") + elif ext == '.map': + filecontent = filecontent.strip() - savepath = os.path.join(attach_dir, basename + ext) - if ext == '.map' and not filecontent.strip(): - # delete map file if it is empty + if filecontent: + # filecontent is either a file or a non-empty string + stream = open(savepath, 'wb') + try: + _write_stream(filecontent, stream) + finally: + stream.close() + else: + # filecontent is empty string (e.g. empty map file), delete the target file try: os.unlink(savepath) except OSError, err: if err.errno != errno.ENOENT: # no such file raise - else: - stream = open(savepath, 'wb') - try: - _write_stream(filecontent, stream) - finally: - stream.close() # touch attachment directory to invalidate cache if new map is saved if ext == '.map': - os.utime(getAttachDir(request, pagename), None) + os.utime(attach_dir, None) request.emit_http_headers() request.write("OK")