From a822465cf48b7da3ed61f5b526d2a0bbf4ae952b Mon Sep 17 00:00:00 2001 From: Lisa Milne Date: Fri, 10 Nov 2023 18:32:48 +1000 Subject: [PATCH] make full paths when needed --- clite/core.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/clite/core.js b/clite/core.js index b36292d..36624d9 100644 --- a/clite/core.js +++ b/clite/core.js @@ -119,7 +119,8 @@ var clite = { clite/core.js:/usr/clite/core.js:0:0:-rw-r----- clite/core.css:/usr/clite/web/core.css:0:0:-rw-r----- data/intro.txt:/usr/share/introduction:0:0:-rw-rw-r-- -data/about.txt:/usr/share/site/about:0:0:-rw-rw-r--`; +data/about.txt:/usr/share/site/about:0:0:-rw-rw-r-- +data/about.txt:/usr/bin/stuff/foo:0:0:-rw-rw-rw-`; init2(d); return; } @@ -154,11 +155,12 @@ data/about.txt:/usr/share/site/about:0:0:-rw-rw-r--`; var perms = parts[4]; var fn = vfsapi.getNode(path); - // TODO: make the full path if needed if (!fn) { if (perms[0] == 'd') { - vfsapi.mkDir(path); + vfsapi.mkPath(path); }else{ + var dir = clite.lib.dirname(path); + vfsapi.mkPath(dir); vfsapi.mkFile(path); } fn = vfsapi.getNode(path); @@ -681,6 +683,19 @@ clite.vfs = { parent.data.content.push(n); return true; } + vfsdata.api.mkPath = function(path) { + var parts = path.split('/'); + var p = ''; + parts.forEach(function(part) { + if (part == '') + return; + p += '/'+part; + vfsdata.api.mkDir(p); + }); + if (vfsdata.api.getNode(path)) + return true; + return false; + } vfsdata.api.remove = function(path) { return false; }