diff options
author | Omar Rizwan <omar@omar.website> | 2020-12-18 23:54:36 -0800 |
---|---|---|
committer | Omar Rizwan <omar@omar.website> | 2020-12-18 23:54:36 -0800 |
commit | bb0376c407f0745e5bfc5c4d88fd5bc0a40a7d33 (patch) | |
tree | 8c6db4ed58ee839eb281e6687503789a9e0bcbf9 | |
parent | d21c9eace16593446cdedbd85ba780b7f4368b70 (diff) |
checkpoint: starting work on truncate. more README stubs.
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | extension/background.js | 17 | ||||
-rw-r--r-- | fs/tabfs.c | 74 |
3 files changed, 31 insertions, 67 deletions
@@ -64,6 +64,13 @@ $ cat mnt/tabs/by-id/*/text > text.txt I do this +### TODO: Live edit + + + +### TODO: Something with live view of variables + + ## Setup **disclaimer**: security, functionality, blah blah. applications may diff --git a/extension/background.js b/extension/background.js index e92069e..18848d7 100644 --- a/extension/background.js +++ b/extension/background.js @@ -142,15 +142,25 @@ const defineFile = (getData, setData) => ({ st_size: toArray(await getData(path)).length }; }, + async open({path}) { return { fh: Cache.storeObject(toArray(await getData(path))) }; }, async read({path, fh, size, offset}) { return { buf: String.fromCharCode(...Cache.getObjectForHandle(fh).slice(offset, offset + size)) } }, async write({path, buf}) { // FIXME: patch + // I guess caller should override write() if they want to actually + // patch and not just re-set the whole string (for example, + // if they want to hot-reload just one function the user modified) setData(path, buf); return { size: utf8(buf).length }; }, - async release({fh}) { Cache.removeObjectForHandle(fh); return {}; } + async release({fh}) { Cache.removeObjectForHandle(fh); return {}; }, + + async truncate({path, size}) { + // TODO: weird case if they truncate while the file is open + // (but `echo hi > foo.txt` uses O_TRUNC which doesn't do that) + setData(path, (await getData(path)).truncate(size)); return {}; + } }); router["/tabs/by-id"] = { @@ -169,12 +179,15 @@ router["/tabs/by-id"] = { // TODO: mem (?) // TODO: cpu (?) +// TODO: dom/ ? +// TODO: globals/ ? + // screenshot.png (FIXME: how to keep from blocking when unfocused?) // TODO: archive.mhtml ? // TODO: printed.pdf // control // resources/ -// TODO: scripts/ +// TODO: scripts/ TODO: allow creation, eval immediately (function() { const withTab = (readHandler, writeHandler) => defineFile(async path => { @@ -105,31 +105,6 @@ tabfs_read(const char *path, char *buf, size_t size, off_t offset, memcpy(buf, scan_buf, scan_len < size ? scan_len : size); free(scan_buf); return scan_len; - - /* MAKE_REQ("read", { */ - /* cJSON_AddStringToObject(req, "path", path); */ - /* cJSON_AddNumberToObject(req, "size", size); */ - /* cJSON_AddNumberToObject(req, "offset", offset); */ - - /* cJSON_AddNumberToObject(req, "fh", fi->fh); */ - /* cJSON_AddNumberToObject(req, "flags", fi->flags); */ - /* }, { */ - /* cJSON *resp_buf_item = cJSON_GetObjectItemCaseSensitive(resp, "buf"); */ - /* if (!resp_buf_item) return -EIO; */ - - /* char *resp_buf = cJSON_GetStringValue(resp_buf_item); */ - /* if (!resp_buf) return -EIO; */ - /* size_t resp_buf_len = strlen(resp_buf); */ - - /* cJSON *base64_encoded_item = cJSON_GetObjectItemCaseSensitive(resp, "base64Encoded"); */ - /* if (base64_encoded_item && cJSON_IsTrue(base64_encoded_item)) { */ - /* size = base64_decode(resp_buf, resp_buf_len, (unsigned char *) buf); */ - /* } else { */ - /* size = resp_buf_len < size ? resp_buf_len : size; */ - /* memcpy(buf, resp_buf, size); */ - /* } */ - /* ret = size; */ - /* }); */ } static int @@ -140,18 +115,6 @@ tabfs_write(const char *path, const char *buf, size_t size, off_t offset, "write", path, buf, size, offset, fi->fh, fi->flags); int ret; receive_response("{size: %d}", &ret); return ret; - - /* MAKE_REQ("write", { */ - /* cJSON_AddStringToObject(req, "path", path); */ - - /* char base64_buf[size + 1]; // ughh. */ - /* base64_encode((const unsigned char *) buf, size, base64_buf); */ - - /* cJSON_AddStringToObject(req, "buf", base64_buf); */ - /* cJSON_AddNumberToObject(req, "offset", offset); */ - /* }, { */ - /* ret = size; */ - /* }); */ } static int tabfs_release(const char *path, struct fuse_file_info *fi) { @@ -159,15 +122,7 @@ static int tabfs_release(const char *path, struct fuse_file_info *fi) { "release", path, fi->fh); receive_response("{}", NULL); - return 0; - - /* MAKE_REQ("release", { */ - /* cJSON_AddStringToObject(req, "path", path); */ - /* cJSON_AddNumberToObject(req, "fh", fi->fh); */ - /* }, { */ - /* ret = 0; */ - /* }); */ } static int tabfs_opendir(const char *path, struct fuse_file_info *fi) { @@ -175,18 +130,7 @@ static int tabfs_opendir(const char *path, struct fuse_file_info *fi) { "opendir", path, fi->flags); receive_response("{fh: %d}", &fi->fh); - return 0; - - /* MAKE_REQ("opendir", { */ - /* cJSON_AddStringToObject(req, "path", path); */ - /* cJSON_AddNumberToObject(req, "flags", fi->flags); */ - /* }, { */ - /* cJSON *fh_item = cJSON_GetObjectItemCaseSensitive(resp, "fh"); */ - /* if (fh_item) fi->fh = fh_item->valueint; */ - - /* ret = 0; */ - /* }); */ } static int @@ -209,27 +153,26 @@ tabfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, return 0; } -static int -tabfs_releasedir(const char *path, struct fuse_file_info *fi) { +static int tabfs_releasedir(const char *path, struct fuse_file_info *fi) { send_request("{op: %Q, path: %Q, fh: %d}", "releasedir", path, fi->fh); receive_response("{}", NULL); + return 0; +} +static int tabfs_truncate(const char *path, off_t size) { + send_request("{op: %Q, path: %Q, size: %d}", + "truncate", path, size); + + receive_response("{}", NULL); return 0; - /* MAKE_REQ("releasedir", { */ - /* cJSON_AddStringToObject(req, "path", path); */ - /* cJSON_AddNumberToObject(req, "fh", fi->fh); */ - /* }, { */ - /* ret = 0; */ - /* }); */ } static int tabfs_unlink(const char *path) { send_request("{op: %Q, path: %Q}", "unlink", path); receive_response("{}", NULL); - return 0; } @@ -246,6 +189,7 @@ static struct fuse_operations tabfs_filesystem_operations = { .readdir = tabfs_readdir, /* To provide directory listing. */ .releasedir = tabfs_releasedir, + .truncate = tabfs_truncate, .unlink = tabfs_unlink }; |