Skip to content

Commit

Permalink
change stat size behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
TripleDogDare committed Nov 23, 2022
1 parent dd7a38d commit 22925f3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Some behavior of testmark and io/fs is incompatible. Known issues include handling of
// relative paths and overlapping regular files with directories.
//
// This package isn't part of testmark's core.
// This package isn't part of testmark's core and breaking changes may be frequent.
package fs

import (
Expand Down Expand Up @@ -64,6 +64,7 @@ func (f *File) Type() fs.FileMode {
// Read reads up to len(b) bytes from the File and stores them in b. It returns
// the number of bytes read and any error encountered. At end of file, Read
// returns 0, io.EOF.
// May return fs.ErrClosed
func (f *File) Read(b []byte) (int, error) {
if f.buffer == nil {
return 0, fs.ErrClosed
Expand Down Expand Up @@ -143,6 +144,7 @@ func (s fileStat) Name() string {
}

// Size returns the size of the underlying hunk when the file was opened
// If no hunk exists for the file path then size will be the number of children for the directory.
func (s fileStat) Size() int64 {
return s.size
}
Expand Down Expand Up @@ -187,7 +189,7 @@ func (f *fsimpl) Open(name string) (fs.File, error) {

// file returns the File representation of a DirEnt.
func file(d *testmark.DirEnt) *File {
size := int64(0)
size := int64(len(d.Children))
buf := bytes.NewBuffer([]byte{})
if d.Hunk != nil {
buf = bytes.NewBuffer(d.Hunk.Body)
Expand All @@ -211,8 +213,7 @@ func file(d *testmark.DirEnt) *File {
mode: mode,
sys: d,
// size is generally the number of directory entires or the length of the file in bytes.
// We have to choose one or the other because files and directories can overlap
// In my opinion it's best to go with file length, so directories will always have a size of zero.
// We have both, you're on your own.
size: size,
},
}
Expand Down

0 comments on commit 22925f3

Please sign in to comment.