|
|
@ -5,6 +5,7 @@ import( |
|
|
|
"fmt" |
|
|
|
"log" |
|
|
|
"os" |
|
|
|
"io" |
|
|
|
"io/ioutil" |
|
|
|
"encoding/json" |
|
|
|
"syscall" |
|
|
@ -54,6 +55,10 @@ type FileNode struct { |
|
|
|
Ent *DirEnt |
|
|
|
Elem FileElem |
|
|
|
AbsolutePath string |
|
|
|
|
|
|
|
ReadBytes uint64 |
|
|
|
CurrentBlock *os.File |
|
|
|
RemainingBlocks []string |
|
|
|
} |
|
|
|
|
|
|
|
func (fe* FileElem) String() string { |
|
|
@ -163,6 +168,35 @@ func (fn* FileNode) Parse() { |
|
|
|
jdec := json.NewDecoder(zfile) |
|
|
|
err = jdec.Decode(&fn.Elem) |
|
|
|
if err != nil { log.Fatal(err) } |
|
|
|
|
|
|
|
fn.RemainingBlocks = fn.Elem.BlkIds |
|
|
|
} |
|
|
|
|
|
|
|
func (fn* FileNode) Read(p []byte) (n int, err error) { |
|
|
|
if fn.CurrentBlock == nil && len(fn.RemainingBlocks) == 0 { |
|
|
|
return 0, io.EOF |
|
|
|
} |
|
|
|
|
|
|
|
if fn.CurrentBlock == nil { |
|
|
|
blockId := fn.RemainingBlocks[0] |
|
|
|
fn.RemainingBlocks = fn.RemainingBlocks[1:] |
|
|
|
path := filepath.Join(fn.Config.Storage, "blocks", fn.Config.RepoId, blockId[:2], blockId[2:]) |
|
|
|
fn.CurrentBlock, err = os.Open(path) |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
n, err = fn.CurrentBlock.Read(p) |
|
|
|
fn.ReadBytes += uint64(n) |
|
|
|
|
|
|
|
if err == io.EOF { |
|
|
|
err = nil |
|
|
|
fn.CurrentBlock.Close() |
|
|
|
fn.CurrentBlock = nil |
|
|
|
} |
|
|
|
|
|
|
|
return n, err |
|
|
|
} |
|
|
|
|
|
|
|
func (dn* DirNode) Children() ([]*DirNode, []*FileNode) { |
|
|
|