// Attr returns the attributes of a given node. func (s *Node) Attr() fuse.Attr { if s.cached == nil { err := s.loadData() if err != nil { log.Errorf("Error loading PBData for file: '%s'", s.name) } } switch s.cached.GetType() { case ftpb.Data_Directory: return fuse.Attr{Mode: os.ModeDir | 0555} case ftpb.Data_File, ftpb.Data_Raw: size, err := ft.DataSize(s.Nd.Data) if err != nil { log.Errorf("Error getting size of file: %s", err) size = 0 } if size == 0 { size = s.dagMod.Size() } return fuse.Attr{ Mode: 0666, Size: size, Blocks: uint64(len(s.Nd.Links)), } default: log.Error("Invalid data type.") return fuse.Attr{} } }
func TestDagModifierBasic(t *testing.T) { logging.SetLevel(logging.CRITICAL, "blockservice") logging.SetLevel(logging.CRITICAL, "merkledag") dserv := getMockDagServ(t) b, n := getNode(t, dserv, 50000) dagmod, err := NewDagModifier(n, dserv, &chunk.SizeSplitter{Size: 512}) if err != nil { t.Fatal(err) } // Within zero block beg := uint64(15) length := uint64(60) t.Log("Testing mod within zero block") b = testModWrite(t, beg, length, b, dagmod) // Within bounds of existing file beg = 1000 length = 4000 t.Log("Testing mod within bounds of existing file.") b = testModWrite(t, beg, length, b, dagmod) // Extend bounds beg = 49500 length = 4000 t.Log("Testing mod that extends file.") b = testModWrite(t, beg, length, b, dagmod) // "Append" beg = uint64(len(b)) length = 3000 b = testModWrite(t, beg, length, b, dagmod) // Verify reported length node, err := dagmod.GetNode() if err != nil { t.Fatal(err) } size, err := ft.DataSize(node.Data) if err != nil { t.Fatal(err) } expected := uint64(50000 + 3500 + 3000) if size != expected { t.Fatalf("Final reported size is incorrect [%d != %d]", size, expected) } }