mirror of
https://github.com/osnr/TabFS.git
synced 2024-05-03 22:33:11 +02:00
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:
parent
b18fc10e14
commit
a3f25d346f
|
@ -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',
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue