Commit 1e61ee89 authored by Fabian-Andree Heidemann's avatar Fabian-Andree Heidemann
Browse files

[filesystem] allow custom name for compress, even if is_tmp -> only created in tmp folder

[file] use meaningful name in multiple download, fix #2290
parent be115ed5
......@@ -224,7 +224,7 @@ class FSAjaxController(AbstractController):
def compress(self, paths, path, name="", isTmp=False):
isTmp = isTmp and isTmp.lower() in ("true", "1", "yes")
if not isTmp and not name:
raise AjaxException("Either name or isTmp must be given.")
raise AjaxException("Either name or isTmp must be given.")
self.release_session()
fs = self.get('fs')
self.release_database()
......
......@@ -413,13 +413,19 @@ define([
}).appendTo("body");
}
var date = new Date()
var tempname = "vispa_"
tempname += self.FileBase.helper.filenameFromPath(self.FileBase.instance.getState("path")) + "_";
tempname += date.toISOString().slice(0,10).replace(/-/g,"_") + "_" ;
tempname += date.toISOString().slice(11,19).replace(/:/g,"_") + ".zip";
console.log(tempname)
if (path.length != 1) {
self.compress(undefined, function (err, archive) {
self.compress(tempname, function (err, archive) {
_download(archive, true);
}, true);
} else if (path.length == 1 && self.FileBase.selections.entries[
Object.keys(self.FileBase.selections.entries)].data().data.type == "d") {
self.compress(undefined, function (err, archive) {
self.compress(tempname, function (err, archive) {
_download(archive, true);
}, true);
} else {
......
......@@ -322,8 +322,11 @@ class FileSystem(object):
paths = [self.expand(p) for p in paths]
if is_tmp:
fullpath = os.path.join(tempfile._get_default_tempdir(),
next(tempfile._get_candidate_names()) + ".zip")
tempdir = tempfile._get_default_tempdir()
name = name or next(tempfile._get_candidate_names())
name = name if name.endswith(".zip") else name + ".zip"
name = self.handle_file_name_collision(name, tempdir)
fullpath = os.path.join(tempdir, name)
else:
path = path if not path.endswith(os.sep) else path[:-1]
path = self.expand(path)
......@@ -331,7 +334,6 @@ class FileSystem(object):
name = self.handle_file_name_collision(name, path)
fullpath = os.path.join(path, name)
with ZipFile(fullpath, "w") as archive:
i = 0
while i < len(paths):
......
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