mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
swarm/api: fix build/tests on unsupported platforms
Skip FUSE tests if FUSE is unavailable and change build constraints so the 'lesser' platforms aren't mentioned explicitly. The test are compiled on all platforms to prevent regressions in _fallback.go Also gofmt -w -s because why not.
This commit is contained in:
parent
1018bf6a00
commit
40818ab287
5 changed files with 48 additions and 69 deletions
|
|
@ -29,9 +29,6 @@ import (
|
|||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
// Data structures used for Fuse filesystem, serving directories and serving files to Fuse driver
|
||||
type FS struct {
|
||||
root *Dir
|
||||
|
|
@ -55,7 +52,6 @@ type File struct {
|
|||
reader storage.LazySectionReader
|
||||
}
|
||||
|
||||
|
||||
// Functions which satisfy the Fuse File System requests
|
||||
func (filesystem *FS) Root() (fs.Node, error) {
|
||||
return filesystem.root, nil
|
||||
|
|
@ -104,14 +100,12 @@ func (d *Dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
|||
}
|
||||
|
||||
func (file *File) Attr(ctx context.Context, a *fuse.Attr) error {
|
||||
|
||||
a.Inode = file.inode
|
||||
//TODO: need to get permission as argument
|
||||
a.Mode = 0500
|
||||
a.Uid = uint32(os.Getuid())
|
||||
a.Gid = uint32(os.Getegid())
|
||||
|
||||
|
||||
reader := file.swarmApi.Retrieve(file.key)
|
||||
quitC := make(chan bool)
|
||||
size, err := reader.Size(quitC)
|
||||
|
|
@ -135,5 +129,4 @@ func (file *File) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.Re
|
|||
}
|
||||
resp.Data = buf[:n]
|
||||
return err
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"time"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -27,15 +27,12 @@ const (
|
|||
maxFuseMounts = 5
|
||||
)
|
||||
|
||||
|
||||
type SwarmFS struct {
|
||||
swarmApi *Api
|
||||
activeMounts map[string]*MountInfo
|
||||
activeLock *sync.RWMutex
|
||||
}
|
||||
|
||||
|
||||
|
||||
func NewSwarmFS(api *Api) *SwarmFS {
|
||||
swarmfs := &SwarmFS{
|
||||
swarmApi: api,
|
||||
|
|
@ -44,5 +41,3 @@ func NewSwarmFS(api *Api) *SwarmFS {
|
|||
}
|
||||
return swarmfs
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,35 +14,35 @@
|
|||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// +build windows
|
||||
// +build !linux,!darwin,!freebsd
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Dummy struct and functions to satsfy windows build
|
||||
type MountInfo struct {
|
||||
var errNoFUSE = errors.New("FUSE is not supported on this platform")
|
||||
|
||||
func isFUSEUnsupportedError(err error) bool {
|
||||
return err == errNoFUSE
|
||||
}
|
||||
|
||||
// Dummy struct and functions to satsfy windows build
|
||||
type MountInfo struct{}
|
||||
|
||||
func (self *SwarmFS) Mount(mhash, mountpoint string) error {
|
||||
log.Info("Platform not supported")
|
||||
return nil
|
||||
return errNoFUSE
|
||||
}
|
||||
|
||||
func (self *SwarmFS) Unmount(mountpoint string) error {
|
||||
log.Info("Platform not supported")
|
||||
return nil
|
||||
return errNoFUSE
|
||||
}
|
||||
|
||||
func (self *SwarmFS) Listmounts() (string, error) {
|
||||
log.Info("Platform not supported")
|
||||
return "",nil
|
||||
return "", errNoFUSE
|
||||
}
|
||||
|
||||
func (self *SwarmFS) Stop() error {
|
||||
log.Info("Platform not supported")
|
||||
return nil
|
||||
}
|
||||
|
|
@ -14,8 +14,6 @@
|
|||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// +build linux darwin
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
|
|
@ -35,7 +33,6 @@ func testFuseFileSystem(t *testing.T, f func(*FileSystem)) {
|
|||
}
|
||||
|
||||
func createTestFiles(t *testing.T, files []string) {
|
||||
|
||||
os.RemoveAll(testUploadDir)
|
||||
os.RemoveAll(testMountDir)
|
||||
defer os.MkdirAll(testMountDir, 0777)
|
||||
|
|
@ -58,9 +55,7 @@ func createTestFiles(t *testing.T, files []string) {
|
|||
}
|
||||
|
||||
func compareFiles(t *testing.T, files []string) {
|
||||
|
||||
for f := range files {
|
||||
|
||||
sourceFile := filepath.Join(testUploadDir, files[f])
|
||||
destinationFile := filepath.Join(testMountDir, files[f])
|
||||
|
||||
|
|
@ -81,12 +76,10 @@ func compareFiles(t *testing.T, files []string) {
|
|||
if dfinfo.Mode().Perm().String() != "-r-x------" {
|
||||
t.Fatalf("Permission is not 0500for file: %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func doHashTest(fs *FileSystem, t *testing.T, ensName string, files ...string) {
|
||||
|
||||
createTestFiles(t, files)
|
||||
bzzhash, err := fs.Upload(testUploadDir, "")
|
||||
if err != nil {
|
||||
|
|
@ -94,29 +87,29 @@ func doHashTest(fs *FileSystem, t *testing.T, ensName string, files ...string) {
|
|||
}
|
||||
|
||||
swarmfs := NewSwarmFS(fs.api)
|
||||
_ ,err1 := swarmfs.Mount(bzzhash, testMountDir)
|
||||
if err1 != nil {
|
||||
defer swarmfs.Stop()
|
||||
|
||||
_, err = swarmfs.Mount(bzzhash, testMountDir)
|
||||
if isFUSEUnsupportedError(err) {
|
||||
t.Skip("FUSE not supported:", err)
|
||||
} else if err != nil {
|
||||
t.Fatalf("Error mounting hash %v: %v", bzzhash, err)
|
||||
}
|
||||
|
||||
compareFiles(t, files)
|
||||
_, err2 := swarmfs.Unmount(testMountDir)
|
||||
if err2 != nil {
|
||||
|
||||
if _, err := swarmfs.Unmount(testMountDir); err != nil {
|
||||
t.Fatalf("Error unmounting path %v: %v", testMountDir, err)
|
||||
}
|
||||
swarmfs.Stop()
|
||||
|
||||
}
|
||||
|
||||
// mounting with manifest Hash
|
||||
func TestFuseMountingScenarios(t *testing.T) {
|
||||
testFuseFileSystem(t, func(fs *FileSystem) {
|
||||
|
||||
//doHashTest(fs,t, "test","1.txt")
|
||||
doHashTest(fs, t, "", "1.txt")
|
||||
doHashTest(fs, t, "", "1.txt", "11.txt", "111.txt", "two/2.txt", "two/two/2.txt", "three/3.txt")
|
||||
doHashTest(fs, t, "", "1/2/3/4/5/6/7/8/9/10/11/12/1.txt")
|
||||
doHashTest(fs, t, "", "one/one.txt", "one.txt", "once/one.txt", "one/one/one.txt")
|
||||
|
||||
})
|
||||
}
|
||||
|
|
@ -14,29 +14,37 @@
|
|||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// +build linux darwin
|
||||
// +build linux darwin freebsd
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
"github.com/ethereum/go-ethereum/swarm/storage"
|
||||
"bazil.org/fuse"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"bazil.org/fuse/fs"
|
||||
"sync"
|
||||
)
|
||||
"time"
|
||||
|
||||
"bazil.org/fuse"
|
||||
"bazil.org/fuse/fs"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/swarm/storage"
|
||||
)
|
||||
|
||||
var (
|
||||
inode uint64 = 1
|
||||
inodeLock sync.RWMutex
|
||||
)
|
||||
|
||||
func isFUSEUnsupportedError(err error) bool {
|
||||
if perr, ok := err.(*os.PathError); ok {
|
||||
return perr.Op == "open" && perr.Path == "/dev/fuse"
|
||||
}
|
||||
return err == fuse.ErrOSXFUSENotFound
|
||||
}
|
||||
|
||||
// information about every active mount
|
||||
type MountInfo struct {
|
||||
mountPoint string
|
||||
|
|
@ -54,10 +62,7 @@ func NewInode() uint64 {
|
|||
return inode
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (self *SwarmFS) Mount(mhash, mountpoint string) (string, error) {
|
||||
|
||||
self.activeLock.Lock()
|
||||
defer self.activeLock.Unlock()
|
||||
|
||||
|
|
@ -110,7 +115,6 @@ func (self *SwarmFS) Mount(mhash, mountpoint string) (string, error) {
|
|||
dirTree["root"] = rootDir
|
||||
|
||||
err = trie.listWithPrefix(path, quitC, func(entry *manifestTrieEntry, suffix string) {
|
||||
|
||||
key = common.Hex2Bytes(entry.Hash)
|
||||
fullpath := "/" + suffix
|
||||
basepath := filepath.Dir(fullpath)
|
||||
|
|
@ -185,8 +189,6 @@ func (self *SwarmFS) Mount(mhash, mountpoint string) (string, error) {
|
|||
log.Debug(fmt.Sprintf("Mounting connection succeeded for : %v", cleanedMountPoint))
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Assemble and Store the mount information for future use
|
||||
mountInformation := &MountInfo{
|
||||
mountPoint: cleanedMountPoint,
|
||||
|
|
@ -204,7 +206,6 @@ func (self *SwarmFS) Mount(mhash, mountpoint string) (string, error) {
|
|||
}
|
||||
|
||||
func (self *SwarmFS) Unmount(mountpoint string) (string, error) {
|
||||
|
||||
self.activeLock.Lock()
|
||||
defer self.activeLock.Unlock()
|
||||
|
||||
|
|
@ -216,7 +217,6 @@ func (self *SwarmFS) Unmount(mountpoint string) (string, error) {
|
|||
// Get the mount information based on the mountpoint argument
|
||||
mountInfo := self.activeMounts[cleanedMountPoint]
|
||||
|
||||
|
||||
if mountInfo == nil || mountInfo.mountPoint != cleanedMountPoint {
|
||||
err := fmt.Errorf("Could not find mount information for %s ", cleanedMountPoint)
|
||||
log.Warn(err.Error())
|
||||
|
|
@ -242,7 +242,6 @@ func (self *SwarmFS) Unmount(mountpoint string) (string, error) {
|
|||
}
|
||||
|
||||
func (self *SwarmFS) Listmounts() (string, error) {
|
||||
|
||||
self.activeLock.RLock()
|
||||
defer self.activeLock.RUnlock()
|
||||
|
||||
|
|
@ -256,7 +255,6 @@ func (self *SwarmFS) Listmounts() (string, error) {
|
|||
}
|
||||
|
||||
func (self *SwarmFS) Stop() bool {
|
||||
|
||||
for mp := range self.activeMounts {
|
||||
mountInfo := self.activeMounts[mp]
|
||||
self.Unmount(mountInfo.mountPoint)
|
||||
|
|
|
|||
Loading…
Reference in a new issue