extension: allow deletion of TAB/evals/*

This commit is contained in:
Omar Rizwan 2021-02-22 16:18:07 -08:00
parent dffc41a3e1
commit ad80383242

View file

@ -336,7 +336,7 @@ router["/tabs/by-id/*/execute-script"] = {
}, },
getattr() { getattr() {
return { return {
st_mode: unix.S_IFDIR | 0777, // writable so you can create evals st_mode: unix.S_IFDIR | 0777, // writable so you can create/rm evals
st_nlink: 3, st_nlink: 3,
st_size: 0, st_size: 0,
}; };
@ -352,14 +352,22 @@ router["/tabs/by-id/*/execute-script"] = {
}; };
return {}; return {};
}, },
async unlink({path}) {
const [tabId, expr] = [parseInt(pathComponent(path, -3)), pathComponent(path, -1)];
delete evals[tabId][expr]; // TODO: also delete evals[tabId] if empty
return {};
},
...defineFile(async path => { ...defineFile(async path => {
const [tabId, expr] = [parseInt(pathComponent(path, -3)), pathComponent(path, -1)]; const [tabId, expr] = [parseInt(pathComponent(path, -3)), pathComponent(path, -1)];
if (!evals[tabId] || !(expr in evals[tabId])) { throw new UnixError(unix.ENOENT); } if (!evals[tabId] || !(expr in evals[tabId])) { throw new UnixError(unix.ENOENT); }
return JSON.stringify(await evals[tabId][expr]()) + '\n'; return JSON.stringify(await evals[tabId][expr]()) + '\n';
}, () => {
// setData handler -- only providing this so that getattr reports
// that the file is writable, so it can be deleted without annoying prompt.
throw new UnixError(unix.EPERM);
}) })
}; };
// TODO: allow deletion of evals
})(); })();
// TODO: imports // TODO: imports