Commit 33e5a9c0 authored by Tulir Asokan's avatar Tulir Asokan

Initial commit

parents
This diff is collapsed.
# mautrixfs
A Matrix client as a FUSE filesystem.
module maunium.net/go/mautrixfs
go 1.13
require (
github.com/hanwen/go-fuse/v2 v2.0.2
maunium.net/go/mautrix v0.1.0-alpha.3.0.20191110191816-178ce1f1561d
)
replace gopkg.in/russross/blackfriday.v2 => github.com/russross/blackfriday/v2 v2.0.1
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/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
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=
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/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=
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
//
// 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
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package main
import (
"log"
"os"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
"maunium.net/go/mautrix"
)
const OK = 0
func main() {
mautrix.DisableFancyEventParsing = true
client, err := mautrix.NewClient(os.Args[2], os.Args[3], os.Args[4])
if err != nil {
log.Fatalf("Failed to create client: %v\n", err)
}
opts := &fs.Options{MountOptions: fuse.MountOptions{Debug: true}}
server, err := fs.Mount(os.Args[1], &MatrixRoot{
client: client,
}, opts)
if err != nil {
log.Fatalf("Mount fail: %v\n", err)
}
server.Wait()
}
// mautrixfs - A Matrix client as a FUSE filesystem.
// Copyright (C) 2019 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
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package main
import (
"context"
"net/http"
"strings"
"syscall"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
"maunium.net/go/mautrix"
)
type RoomEventRoot struct {
fs.Inode
room *RoomNode
client *mautrix.Client
}
func (events *RoomEventRoot) Getattr(ctx context.Context, fh fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
out.Mode = 0555
return OK
}
func (events *RoomEventRoot) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) {
if events.room.Version == "3" {
name = strings.ReplaceAll(name,"-", "+")
name = strings.ReplaceAll(name,"_", "/")
}
url := events.client.BuildURL("rooms", events.room.ID, "event", name)
data, err := events.client.MakeRequest(http.MethodGet, url, nil, nil)
if err != nil || data == nil {
return nil, syscall.ENOENT
}
return events.NewInode(ctx, &fs.MemRegularFile{
Data: data,
Attr: fuse.Attr{
Mode: 0444,
},
}, fs.StableAttr{ Mode: syscall.S_IFREG }), OK
}
// mautrixfs - A Matrix client as a FUSE filesystem.
// Copyright (C) 2019 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
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package main
import (
"context"
"syscall"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
"maunium.net/go/mautrix"
)
type RoomNode struct {
fs.Inode
mautrix.Room
Version string
client *mautrix.Client
}
func (room *RoomNode) OnAdd(ctx context.Context) {
version := room.NewPersistentInode(ctx, &fs.MemRegularFile{
Data: []byte(room.Version),
Attr: fuse.Attr{Mode: 0444},
}, fs.StableAttr{Mode: syscall.S_IFREG})
room.AddChild("version", version, false)
eventsInode := room.NewPersistentInode(ctx, &RoomEventRoot{room: room, client: room.client}, fs.StableAttr{Mode: syscall.S_IFDIR})
room.AddChild("event", eventsInode, false)
}
func (room *RoomNode) Getattr(ctx context.Context, fh fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
out.Mode = 0555
return OK
}
// mautrixfs - A Matrix client as a FUSE filesystem.
// Copyright (C) 2019 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
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package main
import (
"context"
"syscall"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
"maunium.net/go/mautrix"
)
type RoomRoot struct {
fs.Inode
client *mautrix.Client
rooms map[string]*RoomNode
}
func (r *RoomRoot) Getattr(ctx context.Context, fh fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
out.Mode = 0555
return OK
}
func (r *RoomRoot) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) {
if child := r.GetChild(name); child != nil {
return child, OK
}
var content = make(map[string]interface{})
err := r.client.StateEvent(name, mautrix.StateCreate, "", &content)
if err != nil {
return nil, syscall.ENOENT
}
version, ok := content["room_version"].(string)
if !ok {
version = "1"
}
roomNode := &RoomNode{
Room: mautrix.Room{
ID: name,
State: make(map[mautrix.EventType]map[string]*mautrix.Event),
},
Version: version,
client: r.client,
}
inode := r.NewInode(ctx, roomNode, fs.StableAttr{Mode: syscall.S_IFDIR})
return inode, OK
}
// mautrixfs - A Matrix client as a FUSE filesystem.
// Copyright (C) 2019 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
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package main
import (
"context"
"syscall"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
"maunium.net/go/mautrix"
)
type MatrixRoot struct {
fs.Inode
client *mautrix.Client
rooms *RoomRoot
}
func (r *MatrixRoot) OnAdd(ctx context.Context) {
version := r.NewPersistentInode(ctx, &fs.MemRegularFile{
Data: []byte("0.1.0"),
Attr: fuse.Attr{Mode: 0444},
}, fs.StableAttr{Mode: syscall.S_IFREG})
r.AddChild("version", version, false)
r.rooms = &RoomRoot{client: r.client}
r.AddChild("room", r.NewPersistentInode(ctx, r.rooms, fs.StableAttr{Mode: syscall.S_IFDIR}), false)
}
func (r *MatrixRoot) Getattr(ctx context.Context, fh fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
out.Mode = 0555
return OK
}
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