From 492f85789c27d744ae24fb64cb68b98fff9385bb Mon Sep 17 00:00:00 2001 From: DanyLE Date: Fri, 31 Mar 2023 14:38:59 +0200 Subject: [PATCH] fix: creating missing directories from file paths when they are not specified in zip meta-data --- src/core/vfs.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/core/vfs.ts b/src/core/vfs.ts index bae1f50..d2550ab 100644 --- a/src/core/vfs.ts +++ b/src/core/vfs.ts @@ -1723,7 +1723,6 @@ namespace OS { dest.parent().cache[dest.basename] = this; return resolve({result: true, error: false}); } catch (e) { - console.log(this); return reject(__e(e)); } }); @@ -2099,7 +2098,6 @@ namespace OS { if (meta.type === "dir") { const desdir = to.asFileHandle(); await desdir.mk(file.basename); - console.log(desdir, to); const ret = await file.read(); const files = ret.result.map((v: API.FileInfoType) => v.path); if (files.length > 0) { @@ -2271,17 +2269,26 @@ namespace OS { const data = await zfile.asFileHandle().read("binary"); const zip = await JSZip.loadAsync(data); const to = await dest_callback(zip); - const dirs = []; + const dirs = new Set(); const files = []; - for (const name in zip.files) { + for (const _name in zip.files) { + const name = _name.trimFromRight("/"); const file = zip.files[name]; if (file.dir) { - dirs.push(to + "/" + name); + dirs.add(to + "/" + name); } else { + const segs = name.split("/"); + segs.pop(); + let path = to; + for(let seg of segs) + { + path += "/" + seg; + dirs.add(path); + } files.push(name); } } - await mkdirAll(dirs, true); + await mkdirAll(Array.from(dirs), true); const promises = []; for (const file of files) { promises.push(new Promise(async (res, rej) => {