Add tabs/by-title. Fix symlink stuff to make it work?

FUSE readlink needing to return 0 + getattr needing to return correct
st_size was _not_ obvious, lol.
This commit is contained in:
Omar Rizwan 2019-02-28 01:05:28 -08:00
parent b18fc10e14
commit a3f25d346f
2 changed files with 36 additions and 3 deletions

View file

@ -74,6 +74,28 @@ const router = {
* }
* },
*/
"by-title": {
async readdir() {
const tabs = await queryTabs();
return tabs.map(tab => sanitize(String(tab.title)) + "_" + String(tab.id));
},
"*": {
async getattr(path) {
const st_size = (await this.readlink(path)).length + 1;
return {
st_mode: unix.S_IFLNK | 0444,
st_nlink: 1,
// You _must_ return correct linkee path length from getattr!
st_size
};
},
async readlink(path) {
const parts = path.split("_");
const id = parts[parts.length - 1];
return "../by-id/" + id;
}
}
},
"by-id": {
async readdir() {
const tabs = await queryTabs();
@ -190,6 +212,10 @@ async function read(path, fh, size, offset) {
let route = findRoute(path);
if (route.read) return route.read(path, fh, size, offset);
}
async function readlink(path) {
let route = findRoute(path);
if (route.readlink) return route.readlink(path);
}
async function release(path, fh) {
let route = findRoute(path);
@ -248,6 +274,13 @@ async function onmessage(event) {
op: 'release'
};
} else if (req.op === 'readlink') {
const buf = await readlink(req.path)
response = {
op: 'readlink',
buf
};
} else if (req.op === 'opendir') {
response = {
op: 'opendir',

View file

@ -85,12 +85,12 @@ static int tabfs_readlink(const char *path, char *buf, size_t size) {
cJSON *resp_buf_item = cJSON_GetObjectItemCaseSensitive(resp, "buf");
// FIXME: fix
char *resp_buf = cJSON_GetStringValue(resp_buf_item);
size_t resp_buf_len = strlen(resp_buf);
size = resp_buf_len < size ? resp_buf_len : size;
size_t resp_buf_size = strlen(resp_buf) + 1;
size = resp_buf_size < size ? resp_buf_size : size;
memcpy(buf, resp_buf, size);
ret = size;
ret = 0;
});
}