Initial release of bdrclone

This commit is contained in:
2026-08-13 23:02:25 +08:00
commit d6d1956050
23 changed files with 3042 additions and 0 deletions

37
internal/mount/mount.go Normal file
View File

@@ -0,0 +1,37 @@
//go:build linux
package mount
import (
"context"
"fmt"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"gitea.dddbg.com/youbin/bdrclone/internal/baidu"
)
func Mount(ctx context.Context, client *baidu.Client, mountpoint string, options Options) error {
if options.Name == "" {
options.Name = "bdrclone"
}
mountOptions := []fuse.MountOption{fuse.FSName(options.Name), fuse.Subtype("bdrclone")}
if options.ReadOnly {
mountOptions = append(mountOptions, fuse.ReadOnly())
}
conn, err := fuse.Mount(mountpoint, mountOptions...)
if err != nil {
return fmt.Errorf("mount %s: %w", mountpoint, err)
}
defer conn.Close()
server := fs.New(conn, &fs.Config{})
serveErr := make(chan error, 1)
go func() { serveErr <- server.Serve(New(client, options.ReadOnly)) }()
select {
case err := <-serveErr:
return err
case <-ctx.Done():
_ = fuse.Unmount(mountpoint)
return <-serveErr
}
}