Skip to content

Commit

Permalink
Clean up code to pass report.
Browse files Browse the repository at this point in the history
  • Loading branch information
sb10 committed May 11, 2017
1 parent 05c806d commit 2ba6457
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
2 changes: 1 addition & 1 deletion file.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (f *CachedFile) makeLoopback() {
f.File = nodefs.NewLoopbackFile(localFile)
}

// InnerFile() returns the loopbackFile that deals with local files on disk.
// InnerFile returns the loopbackFile that deals with local files on disk.
func (f *CachedFile) InnerFile() nodefs.File {
return f.File
}
Expand Down
38 changes: 19 additions & 19 deletions filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ import (
"time"
)

const (
blockSize = uint64(4096)
totalBlocks = uint64(274877906944) // 1PB / blockSize
inodes = uint64(1000000000)
ioSize = uint32(1048576) // 1MB
)

// fileDetails checks the file is known and returns its attributes and the
// remote the file came from. If not known, returns ENOENT (which should never
// happen).
Expand All @@ -57,21 +64,16 @@ func (fs *MuxFys) fileDetails(name string, shouldBeWritable bool) (attr *fuse.At
return
}

// StatFS returns a constant (faked) set of details describing a very large
// StatFs returns a constant (faked) set of details describing a very large
// file system.
func (fs *MuxFys) StatFs(name string) *fuse.StatfsOut {
const BLOCK_SIZE = uint64(4096)
const TOTAL_SPACE = uint64(1 * 1024 * 1024 * 1024 * 1024 * 1024) // 1PB
const TOTAL_BLOCKS = uint64(TOTAL_SPACE / BLOCK_SIZE)
const INODES = uint64(1 * 1000 * 1000 * 1000) // 1 billion
const IOSIZE = uint32(1 * 1024 * 1024) // 1MB
return &fuse.StatfsOut{
Blocks: BLOCK_SIZE,
Bfree: TOTAL_BLOCKS,
Bavail: TOTAL_BLOCKS,
Files: INODES,
Ffree: INODES,
Bsize: IOSIZE,
Blocks: blockSize,
Bfree: totalBlocks,
Bavail: totalBlocks,
Files: inodes,
Ffree: inodes,
Bsize: ioSize,
// NameLen uint32
// Frsize uint32
// Padding uint32
Expand Down Expand Up @@ -297,13 +299,11 @@ func (fs *MuxFys) openCached(r *remote, name string, flags uint32, context *fuse
os.Remove(localPath)
fmutex.Unlock()
return nil, fuse.ToStatus(err)
} else {
if localStats.Size() != int64(attr.Size) {
os.Remove(localPath)
r.Error("Downloaded size is wrong", "path", remotePath, "localSize", localStats.Size(), "remoteSize", attr.Size)
fmutex.Unlock()
return nil, fuse.EIO
}
} else if localStats.Size() != int64(attr.Size) {
os.Remove(localPath)
r.Error("Downloaded size is wrong", "path", remotePath, "localSize", localStats.Size(), "remoteSize", attr.Size)
fmutex.Unlock()
return nil, fuse.EIO
}
r.CacheOverride(localPath, NewInterval(0, int64(attr.Size)))
} else {
Expand Down
10 changes: 5 additions & 5 deletions muxfys.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func (t *Target) ReadEnvironment(profile, path string) error {
return nil
}

// createRemote uses the configured details of the Target to create a *remote,
// CreateRemote uses the configured details of the Target to create a *remote,
// used internally by MuxFys.New().
func (t *Target) CreateRemote(cacheBase string, maxAttempts int, logger log15.Logger) (r *remote, err error) {
// parse the target to get secure, host, bucket and basePath
Expand Down Expand Up @@ -460,10 +460,10 @@ type MuxFys struct {
log15.Logger
}

// New, given a configuration, returns a MuxFys that you'll use to Mount() your
// S3 bucket(s), ensure you un-mount if killed by calling UnmountOnDeath(), then
// Unmount() when you're done. You might check Logs() afterwards. The other
// methods of MuxFys can be ignored in most cases.
// New returns a MuxFys that you'll use to Mount() your S3 bucket(s), ensure you
// un-mount if killed by calling UnmountOnDeath(), then Unmount() when you're
// done. You might check Logs() afterwards. The other methods of MuxFys can be
// ignored in most cases.
func New(config *Config) (fs *MuxFys, err error) {
if len(config.Targets) == 0 {
return nil, fmt.Errorf("no targets provided")
Expand Down
8 changes: 7 additions & 1 deletion muxfys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,7 @@ func TestMuxFys(t *testing.T) {
err = cmd.Run()
So(err, ShouldBeNil)
info2, err := os.Stat(path)
So(err, ShouldBeNil)
So(info.ModTime().Unix(), ShouldNotAlmostEqual, info2.ModTime().Unix(), 62)
So(info2.ModTime().String(), ShouldStartWith, "2006-01-02 15:04:05 +0000")
})
Expand All @@ -1293,6 +1294,7 @@ func TestMuxFys(t *testing.T) {
So(details, ShouldResemble, subEntries)

info, err := os.Stat(path)
So(err, ShouldBeNil)
So(info.ModTime().String(), ShouldStartWith, "2006-01-02 15:04:05 +0000")
})

Expand All @@ -1305,13 +1307,15 @@ func TestMuxFys(t *testing.T) {
err = cmd.Run()
So(err, ShouldBeNil)
info2, err := os.Stat(path)
So(err, ShouldBeNil)
So(info.ModTime().Unix(), ShouldNotAlmostEqual, info2.ModTime().Unix(), 62)
So(info2.ModTime().String(), ShouldStartWith, "2006-01-02 15:04:05 +0000")

cmd = exec.Command("touch", "-d", "2007-01-02 15:04:05", path)
err = cmd.Run()
So(err, ShouldBeNil)
info3, err := os.Stat(path)
So(err, ShouldBeNil)
So(info2.ModTime().Unix(), ShouldNotAlmostEqual, info3.ModTime().Unix(), 62)
So(info3.ModTime().String(), ShouldStartWith, "2007-01-02 15:04:05 +0000")
})
Expand All @@ -1325,6 +1329,7 @@ func TestMuxFys(t *testing.T) {
err = os.Chtimes(path, t, t)
So(err, ShouldBeNil)
info2, err := os.Stat(path)
So(err, ShouldBeNil)
So(info.ModTime().Unix(), ShouldNotAlmostEqual, info2.ModTime().Unix(), 62)
So(info2.ModTime().Unix(), ShouldAlmostEqual, t.Unix(), 2)
})
Expand All @@ -1335,6 +1340,7 @@ func TestMuxFys(t *testing.T) {
err = os.Chtimes(path, t, t)
So(err, ShouldBeNil)
info2, err := os.Stat(path)
So(err, ShouldBeNil)
So(info.ModTime().Unix(), ShouldAlmostEqual, info2.ModTime().Unix(), 62)
So(info2.ModTime().Unix(), ShouldNotAlmostEqual, t.Unix(), 2)
})
Expand Down Expand Up @@ -2052,7 +2058,7 @@ func TestMuxFys(t *testing.T) {
So(len(details), ShouldEqual, 0)
})

Convey("Trying to list a non-existant subdir fails as expected", func() {
Convey("Trying to list a non-existent subdir fails as expected", func() {
entries, err := ioutil.ReadDir(mountPoint + "/emptyDi")
So(err, ShouldNotBeNil)
So(os.IsNotExist(err), ShouldBeTrue)
Expand Down

0 comments on commit 2ba6457

Please sign in to comment.