Commit 1c0160bc authored by ThorbenQuast's avatar ThorbenQuast
Browse files

[editor] limit loaded size of content chunk to 15MB (value linked to vispa.ini)

parent 3b229cd6
......@@ -101,6 +101,8 @@ sender_address = vispa@domain.tld
smtp.host = 127.0.0.1
smtp.port = 25
[filesystem]
max_get_size = 20
[extensions]
ignore = [dummy]
......
......@@ -10,6 +10,7 @@ from cherrypy.lib import file_generator, cptools, httputil
import cherrypy
import rpyc
import vispa
from vispa import AjaxException
from vispa.controller import AbstractController
......@@ -381,7 +382,8 @@ class FSAjaxController(AbstractController):
return fs.get_file(path, utf8=utf8,
window_id=self.get('window_id'),
view_id=self.get('view_id'),
watch_id=watch_id)
watch_id=watch_id,
max_size=vispa.config("filesystem", "max_get_size", 15))
@cherrypy.expose
@cherrypy.tools.method(accept="POST")
......
......@@ -80,6 +80,10 @@ define(["jquery", "emitter"], function($, Emitter) {
"<br /> The editor has been closed. </html>");
self.view.close();
}
if (res.size_limit) {
self.view.alert("<html> The file size exceeds " + String(res.max_size) + " MB. <br />" +
"Only the first lines are displayed and the mode is 'read-only'. </html>");
}
self.editor.path = path;
self.view.setState("writable", self.view.getState("writable") && res.writable, 1);
self.view.setState("path", path);
......@@ -234,7 +238,7 @@ define(["jquery", "emitter"], function($, Emitter) {
//case: problems-->addtional confirm
var msg = "";
if (existingFile)
if (existingFile)
msg = "<html> File already exists. <br />" +
"Do you want to overwrite it ? </html>";
self.view.confirm(msg, function(confirmed) {
......@@ -338,4 +342,4 @@ define(["jquery", "emitter"], function($, Emitter) {
});
return CodeEditorActions;
});
\ No newline at end of file
});
......@@ -11,7 +11,7 @@ from subprocess import call, check_output
import ConfigParser
import json
import logging
import os
import os, sys
import re
import shutil
import stat
......@@ -428,28 +428,44 @@ class FileSystem(object):
})
def get_file(self, path, binary=False,
utf8=False, window_id=None, view_id=None, watch_id=None):
utf8=False, window_id=None, view_id=None, watch_id=None, max_size=20):
# inline watch
if window_id and view_id and watch_id:
watch_error = self.watch(path, window_id, view_id, watch_id)
else:
watch_error = ""
max_size *= 1024*1024#
# actual function
path = self.expand(path)
try:
with open(path, "rb" if binary else "r") as f:
content = f.read()
if os.path.getsize(path) > max_size:
content = ""
with open(path, "rb" if binary else "r") as f:
while sys.getsizeof(content) < max_size:
content += f.next()
writable = False
error = None
size_limit = True
else:
with open(path, "rb" if binary else "r") as f:
content = f.read()
writable = self.checkPermissions(path)
error = None
size_limit = False
if utf8:
content = content.decode('utf8')
# new: check for writing rights
writable = self.checkPermissions(path)
error = None
mtime = os.path.getmtime(path)
except Exception as e:
mtime = 0
content = ""
size_limit = False
writable = None
error = str(e)
......@@ -459,6 +475,8 @@ class FileSystem(object):
"success": mtime > 0,
"watch_error": watch_error,
"writable": writable,
"size_limit": size_limit,
"max_size": max_size/(1024*1024),
"error": error
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment