From fe6f1c01f356399c1d6d5d57dcf36b9b9adc294d Mon Sep 17 00:00:00 2001 From: Matthieu Rakotojaona Date: Sun, 19 Jul 2015 16:39:17 +0200 Subject: [PATCH] Make inodeFromBackendId more explicit --- cmd/restic/fuse/dir.go | 3 +-- cmd/restic/fuse/fuse.go | 14 ++++++++++++++ cmd/restic/fuse/snapshot.go | 3 +-- 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 cmd/restic/fuse/fuse.go diff --git a/cmd/restic/fuse/dir.go b/cmd/restic/fuse/dir.go index ef9ad9a73..c8114bbca 100644 --- a/cmd/restic/fuse/dir.go +++ b/cmd/restic/fuse/dir.go @@ -1,7 +1,6 @@ package fuse import ( - "encoding/binary" "os" "bazil.org/fuse" @@ -52,7 +51,7 @@ func newDirFromSnapshot(repo *repository.Repository, snapshot SnapshotWithId) (* return &dir{ repo: repo, children: children, - inode: binary.BigEndian.Uint64(snapshot.ID), + inode: inodeFromBackendId(snapshot.ID), }, nil } diff --git a/cmd/restic/fuse/fuse.go b/cmd/restic/fuse/fuse.go new file mode 100644 index 000000000..487d23f10 --- /dev/null +++ b/cmd/restic/fuse/fuse.go @@ -0,0 +1,14 @@ +package fuse + +import ( + "encoding/binary" + + "github.com/restic/restic/backend" +) + +// inodeFromBackendId returns a unique uint64 from a backend id. +// Endianness has no specific meaning, it is just the simplest way to +// transform a []byte to an uint64 +func inodeFromBackendId(id backend.ID) uint64 { + return binary.BigEndian.Uint64(id[:8]) +} diff --git a/cmd/restic/fuse/snapshot.go b/cmd/restic/fuse/snapshot.go index f341073a4..f288615d1 100644 --- a/cmd/restic/fuse/snapshot.go +++ b/cmd/restic/fuse/snapshot.go @@ -1,7 +1,6 @@ package fuse import ( - "encoding/binary" "os" "sync" "time" @@ -80,7 +79,7 @@ func (sn *SnapshotsDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { ret := make([]fuse.Dirent, 0) for _, snapshot := range sn.knownSnapshots { ret = append(ret, fuse.Dirent{ - Inode: binary.BigEndian.Uint64(snapshot.ID[:8]), + Inode: inodeFromBackendId(snapshot.ID), Type: fuse.DT_Dir, Name: snapshot.Time.Format(time.RFC3339), })