MCPcopy
hub / github.com/osnr/TabFS / createWritableDirectory

Function createWritableDirectory

extension/background.js:364–405  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

362 };
363})();
364function createWritableDirectory() {
365 // Returns a 'writable directory' object, which represents a
366 // writable directory that users can put arbitrary stuff into. It's
367 // not itself a route, but it has .routeForRoot and
368 // .routeForFilename properties that are routes.
369
370 const dir = {};
371 return {
372 directory: dir,
373 routeForRoot: {
374 async readdir({path}) {
375 // get just last component of keys (filename)
376 return { entries: [".", "..",
377 ...Object.keys(dir).map(
378 key => key.substr(key.lastIndexOf("/") + 1)
379 )] };
380 },
381 getattr() {
382 return {
383 st_mode: unix.S_IFDIR | 0777, // writable so you can create/rm evals
384 st_nlink: 3,
385 st_size: 0,
386 };
387 },
388 },
389 routeForFilename: {
390 async mknod({path, mode}) {
391 dir[path] = '';
392 return {};
393 },
394 async unlink({path}) {
395 delete dir[path];
396 return {};
397 },
398
399 ...makeRouteWithContents(
400 async ({path}) => dir[path],
401 async ({path}, buf) => { dir[path] = buf; }
402 )
403 }
404 };
405}
406
407
408(function() {

Callers 1

background.jsFile · 0.85

Calls 1

makeRouteWithContentsFunction · 0.85

Tested by

no test coverage detected