mirror of
https://github.com/octoleo/restic.git
synced 2025-02-02 11:58:26 +00:00
Use more restic-y idioms
This commit is contained in:
parent
3a82612244
commit
a6ce7d9845
@ -54,6 +54,7 @@ func (cmd CmdMount) Execute(args []string) error {
|
|||||||
mountpoint := args[0]
|
mountpoint := args[0]
|
||||||
if _, err := os.Stat(mountpoint); err != nil {
|
if _, err := os.Stat(mountpoint); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
|
cmd.global.Verbosef("Mountpoint [%s] doesn't exist, creating it\n", mountpoint)
|
||||||
err = os.Mkdir(mountpoint, os.ModeDir|0755)
|
err = os.Mkdir(mountpoint, os.ModeDir|0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -72,8 +73,8 @@ func (cmd CmdMount) Execute(args []string) error {
|
|||||||
root := fs.Tree{}
|
root := fs.Tree{}
|
||||||
root.Add("snapshots", &snapshots{repo})
|
root.Add("snapshots", &snapshots{repo})
|
||||||
|
|
||||||
fmt.Printf("Now serving %s under %s\n", repo.Backend().Location(), mountpoint)
|
cmd.global.Printf("Now serving %s under %s\n", repo.Backend().Location(), mountpoint)
|
||||||
fmt.Println("Don't forget to umount after quitting !")
|
cmd.global.Printf("Don't forget to umount after quitting !\n")
|
||||||
|
|
||||||
err = fs.Serve(c, &root)
|
err = fs.Serve(c, &root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -99,7 +100,7 @@ func (sn *snapshots) Attr(ctx context.Context, a *fuse.Attr) error {
|
|||||||
|
|
||||||
func (sn *snapshots) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
func (sn *snapshots) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
||||||
ret := make([]fuse.Dirent, 0)
|
ret := make([]fuse.Dirent, 0)
|
||||||
for id := range sn.repo.List(backend.Snapshot, make(chan struct{})) {
|
for id := range sn.repo.List(backend.Snapshot, ctx.Done()) {
|
||||||
snapshot, err := restic.LoadSnapshot(sn.repo, id)
|
snapshot, err := restic.LoadSnapshot(sn.repo, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -117,7 +118,7 @@ func (sn *snapshots) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
|||||||
func (sn *snapshots) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
func (sn *snapshots) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
||||||
// This is kind of lame: we reload each snapshot and check the name
|
// This is kind of lame: we reload each snapshot and check the name
|
||||||
// (which is the timestamp)
|
// (which is the timestamp)
|
||||||
for id := range sn.repo.List(backend.Snapshot, make(chan struct{})) {
|
for id := range sn.repo.List(backend.Snapshot, ctx.Done()) {
|
||||||
snapshot, err := restic.LoadSnapshot(sn.repo, id)
|
snapshot, err := restic.LoadSnapshot(sn.repo, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user