Commit 99b42ab2 authored by Tulir Asokan's avatar Tulir Asokan

Update stuff

parent 92dfc627
// mautrixfs - A Matrix client as a FUSE filesystem.
// Copyright (C) 2019 Tulir Asokan
// Copyright (C) 2020 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
......@@ -33,10 +33,10 @@ type AliasRoot struct {
client *mautrix.Client
}
var _ = (fs.NodeGetattrer)((*AliasRoot)(nil))
var _ = (fs.NodeLookuper)((*AliasRoot)(nil))
var _ fs.NodeGetattrer = (*AliasRoot)(nil)
var _ fs.NodeLookuper = (*AliasRoot)(nil)
var ServerNameRegex = regexp.MustCompile("(?:(?:\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})|(?:\\[(?:[0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}])|(?:[\\w-.]{1,255}))(?::\\d{1,5})?")
var ServerNameRegex = regexp.MustCompile(`(?:(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|(?:\[(?:[0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}])|(?:[\w-.]{1,255}))(?::\d{1,5})?`)
func (alias *AliasRoot) Getattr(ctx context.Context, fh fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
out.Mode = 0555
......
// mautrixfs - A Matrix client as a FUSE filesystem.
// Copyright (C) 2019 Tulir Asokan
// Copyright (C) 2020 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
......@@ -25,6 +25,7 @@ import (
"github.com/hanwen/go-fuse/v2/fuse"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/id"
)
type AliasServerRoot struct {
......@@ -34,9 +35,9 @@ type AliasServerRoot struct {
client *mautrix.Client
}
var _ = (fs.NodeGetattrer)((*AliasServerRoot)(nil))
var _ = (fs.NodeLookuper)((*AliasServerRoot)(nil))
var _ = (fs.NodeUnlinker)((*AliasServerRoot)(nil))
var _ fs.NodeGetattrer = (*AliasServerRoot)(nil)
var _ fs.NodeLookuper = (*AliasServerRoot)(nil)
var _ fs.NodeUnlinker = (*AliasServerRoot)(nil)
func (aliasServer *AliasServerRoot) Getattr(ctx context.Context, fh fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
out.Mode = 0555
......@@ -48,7 +49,7 @@ func (aliasServer *AliasServerRoot) Lookup(ctx context.Context, name string, out
if resolved != nil {
return resolved, OK
}
alias := fmt.Sprintf("#%s:%s", name, aliasServer.server)
alias := id.NewRoomAlias(name, aliasServer.server)
fmt.Println("Alias lookup", alias)
data, err := aliasServer.client.ResolveAlias(alias)
if err != nil || data == nil {
......@@ -62,7 +63,7 @@ func (aliasServer *AliasServerRoot) Lookup(ctx context.Context, name string, out
}
func (aliasServer *AliasServerRoot) Unlink(ctx context.Context, name string) syscall.Errno {
alias := fmt.Sprintf("#%s:%s", name, aliasServer.server)
alias := id.NewRoomAlias(name, aliasServer.server)
fmt.Println("Alias unlink", alias)
_, err := aliasServer.client.DeleteAlias(alias)
return httpToErrno(err, true)
......
// mautrixfs - A Matrix client as a FUSE filesystem.
// Copyright (C) 2019 Tulir Asokan
// Copyright (C) 2020 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
......@@ -24,20 +24,21 @@ import (
"github.com/hanwen/go-fuse/v2/fuse"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/id"
)
type RoomEventNode struct {
fs.Inode
room *RoomNode
id string
id id.EventID
data []byte
client *mautrix.Client
}
var _ = (fs.NodeGetattrer)((*RoomEventNode)(nil))
var _ = (fs.NodeOpener)((*RoomEventNode)(nil))
var _ = (fs.NodeReader)((*RoomEventNode)(nil))
var _ fs.NodeGetattrer = (*RoomEventNode)(nil)
var _ fs.NodeOpener = (*RoomEventNode)(nil)
var _ fs.NodeReader = (*RoomEventNode)(nil)
func (event *RoomEventNode) Getattr(ctx context.Context, fh fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
out.Mode = 0444
......
module maunium.net/go/mautrixfs
go 1.13
go 1.14
require (
github.com/hanwen/go-fuse/v2 v2.0.2
maunium.net/go/mautrix v0.1.0-alpha.3.0.20191110191816-178ce1f1561d
github.com/hanwen/go-fuse/v2 v2.0.3
maunium.net/go/mautrix v0.2.0-beta.4
)
replace gopkg.in/russross/blackfriday.v2 => github.com/russross/blackfriday/v2 v2.0.1
replace maunium.net/go/mautrix => ../../Matrix/mautrix-go
replace github.com/hanwen/go-fuse/v2 => ../../Go/go-fuse
replace maunium.net/go/mautrix => ../mautrix-go
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/hanwen/go-fuse v1.0.0 h1:GxS9Zrn6c35/BnfiVsZVWmsG803xwE7eVRDvcf/BEVc=
github.com/hanwen/go-fuse v1.0.0/go.mod h1:unqXarDXqzAk0rt98O2tVndEPIpUgLD9+rwFisZH3Ok=
github.com/hanwen/go-fuse/v2 v2.0.2 h1:BtsqKI5RXOqDMnTgpCb0IWgvRgGLJdqYVZ/Hm6KgKto=
github.com/hanwen/go-fuse/v2 v2.0.2/go.mod h1:HH3ygZOoyRbP9y2q7y3+JM6hPL+Epe29IbWaS0UA81o=
github.com/hanwen/go-fuse/v2 v2.0.3 h1:kpV28BKeSyVgZREItBLnaVBvOEwv2PuhNdKetwnvNHo=
github.com/hanwen/go-fuse/v2 v2.0.3/go.mod h1:0EQM6aH2ctVpvZ6a+onrQ/vaykxh2GH7hy3e13vzTUY=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc=
github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/pretty v1.0.1 h1:WE4RBSZ1x6McVVC8S/Md+Qse8YUv6HRObAx6ke00NY8=
github.com/tidwall/pretty v1.0.1/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/sjson v1.1.1 h1:7h1vk049Jnd5EH9NyzNiEuwYW4b5qgreBbqRC19AS3U=
github.com/tidwall/sjson v1.1.1/go.mod h1:yvVuSnpEQv5cYIrO+AT6kw4QVfd5SDZoGIS7/5+fZFs=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190110200230-915654e7eabc h1:Yx9JGxI1SBhVLFjpAkWMaO1TF+xyqtHLjZpvQboJGiM=
golang.org/x/net v0.0.0-20190110200230-915654e7eabc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65 h1:+rhAzEzT3f4JtomfC371qB+0Ola2caSKcY69NUBZrRQ=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522 h1:Ve1ORMCxvRmSXBwJK+t3Oy+V2vRW2OetUQBq4rJIkZE=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
maunium.net/go/mautrix v0.1.0-alpha.3.0.20191110191816-178ce1f1561d h1:lfEHd6diaoKLdZvVNcmBF9kD667xWw+x7iXlvfpEd00=
maunium.net/go/mautrix v0.1.0-alpha.3.0.20191110191816-178ce1f1561d/go.mod h1:O+QWJP3H7BZEzIBSrECKpnpRnEKBwaoWVEu/yZwVwxg=
// mautrixfs - A Matrix client as a FUSE filesystem.
// Copyright (C) 2019 Tulir Asokan
// Copyright (C) 2020 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
......@@ -25,13 +25,13 @@ import (
"github.com/hanwen/go-fuse/v2/fuse"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/id"
)
const OK = 0
func main() {
mautrix.DisableFancyEventParsing = true
client, err := mautrix.NewClient(os.Args[2], os.Args[3], os.Args[4])
client, err := mautrix.NewClient(os.Args[2], id.UserID(os.Args[3]), os.Args[4])
if err != nil {
log.Fatalf("Failed to create client: %v\n", err)
}
......
// mautrixfs - A Matrix client as a FUSE filesystem.
// Copyright (C) 2019 Tulir Asokan
// Copyright (C) 2020 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
......@@ -27,6 +27,7 @@ import (
"github.com/hanwen/go-fuse/v2/fuse"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/id"
)
type RoomEventRoot struct {
......@@ -36,21 +37,21 @@ type RoomEventRoot struct {
client *mautrix.Client
}
var _ = (fs.NodeGetattrer)((*RoomEventRoot)(nil))
var _ = (fs.NodeLookuper)((*RoomEventRoot)(nil))
var _ = (fs.NodeUnlinker)((*RoomEventRoot)(nil))
var _ fs.NodeGetattrer = (*RoomEventRoot)(nil)
var _ fs.NodeLookuper = (*RoomEventRoot)(nil)
var _ fs.NodeUnlinker = (*RoomEventRoot)(nil)
func (events *RoomEventRoot) Getattr(ctx context.Context, fh fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
out.Mode = 0555
return OK
}
func (events *RoomEventRoot) mutateEventID(eventID string) string {
func (events *RoomEventRoot) mutateEventID(eventID string) id.EventID {
if events.room.Version == "3" {
eventID = strings.ReplaceAll(eventID, "-", "+")
eventID = strings.ReplaceAll(eventID, "_", "/")
}
return eventID
return id.EventID(eventID)
}
func (events *RoomEventRoot) Unlink(ctx context.Context, name string) syscall.Errno {
......
// mautrixfs - A Matrix client as a FUSE filesystem.
// Copyright (C) 2019 Tulir Asokan
// Copyright (C) 2020 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
......@@ -35,12 +35,20 @@ type RoomKeyedStateRoot struct {
client *mautrix.Client
}
var _ fs.NodeGetattrer = (*RoomKeyedStateRoot)(nil)
var _ fs.NodeLookuper = (*RoomKeyedStateRoot)(nil)
var _ fs.NodeUnlinker = (*RoomKeyedStateRoot)(nil)
func (keyedState *RoomKeyedStateRoot) Getattr(ctx context.Context, fh fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
out.Mode = 0555
return OK
}
func (keyedState *RoomKeyedStateRoot) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) {
resolved := keyedState.GetChild(name)
if resolved != nil {
return resolved, OK
}
fmt.Println("Keyed state lookup", name)
return keyedState.NewInode(ctx, &RoomKeyedStateEvent{
......@@ -50,6 +58,10 @@ func (keyedState *RoomKeyedStateRoot) Lookup(ctx context.Context, name string, o
}, fs.StableAttr{Mode: syscall.S_IFDIR}), OK
}
func (keyedState *RoomKeyedStateRoot) Unlink(ctx context.Context, name string) syscall.Errno {
return syscall.EROFS
}
type RoomKeyedStateEvent struct {
fs.Inode
......@@ -58,7 +70,20 @@ type RoomKeyedStateEvent struct {
client *mautrix.Client
}
var _ fs.NodeGetattrer = (*RoomKeyedStateEvent)(nil)
var _ fs.NodeLookuper = (*RoomKeyedStateEvent)(nil)
var _ fs.NodeUnlinker = (*RoomKeyedStateEvent)(nil)
func (keyedStateEvent *RoomKeyedStateEvent) Getattr(ctx context.Context, fh fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
out.Mode = 0555
return OK
}
func (keyedStateEvent *RoomKeyedStateEvent) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) {
resolved := keyedStateEvent.GetChild(name)
if resolved != nil {
return resolved, OK
}
fmt.Println("Keyed state lookup", keyedStateEvent.eventType, name)
url := keyedStateEvent.client.BuildURL("rooms", keyedStateEvent.room.ID, "state", keyedStateEvent.eventType, name)
......@@ -67,10 +92,15 @@ func (keyedStateEvent *RoomKeyedStateEvent) Lookup(ctx context.Context, name str
return nil, syscall.ENOENT
}
return keyedStateEvent.NewInode(ctx, &fs.MemRegularFile{
Data: data,
Attr: fuse.Attr{
Mode: 0444,
},
}, fs.StableAttr{ Mode: syscall.S_IFREG }), OK
return keyedStateEvent.NewInode(ctx, &StateEventNode{
client: keyedStateEvent.client,
room: keyedStateEvent.room,
eventType: keyedStateEvent.eventType,
stateKey: name,
data: data,
}, fs.StableAttr{Mode: syscall.S_IFREG}), OK
}
func (keyedStateEvent *RoomKeyedStateEvent) Unlink(ctx context.Context, name string) syscall.Errno {
return syscall.EROFS
}
// mautrixfs - A Matrix client as a FUSE filesystem.
// Copyright (C) 2019 Tulir Asokan
// Copyright (C) 2020 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
......
// mautrixfs - A Matrix client as a FUSE filesystem.
// Copyright (C) 2019 Tulir Asokan
// Copyright (C) 2020 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
......@@ -25,6 +25,8 @@ import (
"github.com/hanwen/go-fuse/v2/fuse"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
)
type RoomRoot struct {
......@@ -44,7 +46,8 @@ func (r *RoomRoot) Lookup(ctx context.Context, name string, out *fuse.EntryOut)
return child, OK
}
var content = make(map[string]interface{})
err := r.client.StateEvent(name, mautrix.StateCreate, "", &content)
roomID := id.RoomID(name)
err := r.client.StateEvent(roomID, event.StateCreate, "", &content)
if err != nil {
return nil, syscall.ENOENT
}
......@@ -55,8 +58,8 @@ func (r *RoomRoot) Lookup(ctx context.Context, name string, out *fuse.EntryOut)
roomNode := &RoomNode{
Room: mautrix.Room{
ID: name,
State: make(map[mautrix.EventType]map[string]*mautrix.Event),
ID: roomID,
State: make(map[event.Type]map[string]*event.Event),
},
Version: version,
client: r.client,
......@@ -67,7 +70,7 @@ func (r *RoomRoot) Lookup(ctx context.Context, name string, out *fuse.EntryOut)
type RoomListStream struct {
next int
data []string
data []id.RoomID
}
func (rls *RoomListStream) HasNext() bool {
......@@ -78,7 +81,7 @@ func (rls *RoomListStream) Next() (fuse.DirEntry, syscall.Errno) {
rls.next += 1
return fuse.DirEntry{
Mode: 0555,
Name: rls.data[rls.next - 1],
Name: string(rls.data[rls.next-1]),
}, OK
}
......@@ -91,5 +94,5 @@ func (r *RoomRoot) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
return nil, syscall.EIO
}
return &RoomListStream{ data: resp.JoinedRooms }, OK
return &RoomListStream{data: resp.JoinedRooms}, OK
}
// mautrixfs - A Matrix client as a FUSE filesystem.
// Copyright (C) 2019 Tulir Asokan
// Copyright (C) 2020 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
......@@ -31,27 +31,41 @@ import (
type RoomStateRoot struct {
fs.Inode
room *RoomNode
room *RoomNode
client *mautrix.Client
}
var _ fs.NodeGetattrer = (*RoomStateRoot)(nil)
var _ fs.NodeLookuper = (*RoomStateRoot)(nil)
var _ fs.NodeUnlinker = (*RoomStateRoot)(nil)
func (state *RoomStateRoot) Getattr(ctx context.Context, fh fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
out.Mode = 0555
return OK
}
func (state *RoomStateRoot) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) {
resolved := state.GetChild(name)
if resolved != nil {
return resolved, OK
}
fmt.Println("State lookup", name)
url := state.client.BuildURL("rooms", state.room.ID, "state", name)
data, err := state.client.MakeRequest(http.MethodGet, url, nil, nil)
if err != nil || data == nil {
return nil, syscall.ENOENT
}
return state.NewInode(ctx, &fs.MemRegularFile{
Data: data,
Attr: fuse.Attr{
Mode: 0444,
},
}, fs.StableAttr{ Mode: syscall.S_IFREG }), OK
return state.NewInode(ctx, &StateEventNode{
client: state.client,
room: state.room,
eventType: name,
stateKey: "",
data: data,
}, fs.StableAttr{Mode: syscall.S_IFREG}), OK
}
func (state *RoomStateRoot) Unlink(ctx context.Context, name string) syscall.Errno {
return syscall.EROFS
}
// mautrixfs - A Matrix client as a FUSE filesystem.
// Copyright (C) 2019 Tulir Asokan
// Copyright (C) 2020 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
......
// mautrixfs - A Matrix client as a FUSE filesystem.
// Copyright (C) 2019 Tulir Asokan
// Copyright (C) 2020 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
......@@ -18,29 +18,40 @@ package main
import (
"context"
"encoding/json"
"fmt"
"sync"
"syscall"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
)
type StateEventNode struct {
fs.Inode
room *RoomNode
id string
data []byte
room *RoomNode
eventType string
stateKey string
data []byte
writeMutex sync.Mutex
writeData []byte
client *mautrix.Client
}
var _ = (fs.NodeGetattrer)((*StateEventNode)(nil))
var _ = (fs.NodeOpener)((*StateEventNode)(nil))
var _ = (fs.NodeReader)((*StateEventNode)(nil))
var _ fs.NodeGetattrer = (*StateEventNode)(nil)
var _ fs.NodeOpener = (*StateEventNode)(nil)
var _ fs.NodeReader = (*StateEventNode)(nil)
var _ fs.NodeWriter = (*StateEventNode)(nil)
var _ fs.NodeFlusher = (*StateEventNode)(nil)
func (stateEvent *StateEventNode) Getattr(ctx context.Context, fh fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
out.Mode = 0444
out.Mode = 0644
out.Size = uint64(len(stateEvent.data))
return OK
}
......@@ -56,3 +67,47 @@ func (stateEvent *StateEventNode) Read(ctx context.Context, fh fs.FileHandle, de
}
return fuse.ReadResultData(stateEvent.data[off:end]), OK
}
func (stateEvent *StateEventNode) Write(ctx context.Context, fh fs.FileHandle, data []byte, off int64) (uint32, syscall.Errno) {
stateEvent.writeMutex.Lock()
defer stateEvent.writeMutex.Unlock()
end := int64(len(data)) + off
if int64(len(stateEvent.writeData)) < end {
n := make([]byte, end)
copy(n, stateEvent.writeData)
stateEvent.writeData = n
}
copy(stateEvent.writeData[off:off+int64(len(data))], data)
return uint32(len(data)), OK
}
func (stateEvent *StateEventNode) Setattr(ctx context.Context, fh fs.FileHandle, in *fuse.SetAttrIn, out *fuse.AttrOut) syscall.Errno {
stateEvent.writeMutex.Lock()
defer stateEvent.writeMutex.Unlock()
if sz, ok := in.GetSize(); ok {
stateEvent.writeData = stateEvent.writeData[:sz]
}
out.Mode = 0644
out.Size = uint64(len(stateEvent.writeData))
return OK
}
func (stateEvent *StateEventNode) Flush(ctx context.Context, fh fs.FileHandle) syscall.Errno {
if len(stateEvent.writeData) == 0 {
return OK
}
var data map[string]interface{}
err := json.Unmarshal(stateEvent.writeData, &data)
if err != nil {
fmt.Println(err)
return syscall.EBADMSG
}
_, err = stateEvent.client.SendStateEvent(stateEvent.room.ID,
event.Type{Type: stateEvent.eventType, Class: event.StateEventType}, stateEvent.stateKey, data)
if err == nil {
stateEvent.data, _ = json.Marshal(data)
}
return httpToErrno(err, false)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment