@@ -69,9 +69,12 @@ func (a *API) NewManifest(ctx context.Context, toEncrypt bool) (storage.Address,
6969 if err != nil {
7070 return nil , err
7171 }
72- key , wait , err := a .Store (ctx , bytes .NewReader (data ), int64 (len (data )), toEncrypt )
73- wait (ctx )
74- return key , err
72+ addr , wait , err := a .Store (ctx , bytes .NewReader (data ), int64 (len (data )), toEncrypt )
73+ if err != nil {
74+ return nil , err
75+ }
76+ err = wait (ctx )
77+ return addr , err
7578}
7679
7780// Manifest hack for supporting Mutable Resource Updates from the bzz: scheme
@@ -87,8 +90,12 @@ func (a *API) NewResourceManifest(ctx context.Context, resourceAddr string) (sto
8790 if err != nil {
8891 return nil , err
8992 }
90- key , _ , err := a .Store (ctx , bytes .NewReader (data ), int64 (len (data )), false )
91- return key , err
93+ addr , wait , err := a .Store (ctx , bytes .NewReader (data ), int64 (len (data )), false )
94+ if err != nil {
95+ return nil , err
96+ }
97+ err = wait (ctx )
98+ return addr , err
9299}
93100
94101// ManifestWriter is used to add and remove entries from an underlying manifest
@@ -106,21 +113,26 @@ func (a *API) NewManifestWriter(ctx context.Context, addr storage.Address, quitC
106113 return & ManifestWriter {a , trie , quitC }, nil
107114}
108115
109- // AddEntry stores the given data and adds the resulting key to the manifest
110- func (m * ManifestWriter ) AddEntry (ctx context.Context , data io.Reader , e * ManifestEntry ) (key storage.Address , err error ) {
116+ // AddEntry stores the given data and adds the resulting address to the manifest
117+ func (m * ManifestWriter ) AddEntry (ctx context.Context , data io.Reader , e * ManifestEntry ) (addr storage.Address , err error ) {
111118 entry := newManifestTrieEntry (e , nil )
112119 if data != nil {
113- key , _ , err = m .api .Store (ctx , data , e .Size , m .trie .encrypted )
120+ var wait func (context.Context ) error
121+ addr , wait , err = m .api .Store (ctx , data , e .Size , m .trie .encrypted )
122+ if err != nil {
123+ return nil , err
124+ }
125+ err = wait (ctx )
114126 if err != nil {
115127 return nil , err
116128 }
117- entry .Hash = key .Hex ()
129+ entry .Hash = addr .Hex ()
118130 }
119131 if entry .Hash == "" {
120- return key , errors .New ("missing entry hash" )
132+ return addr , errors .New ("missing entry hash" )
121133 }
122134 m .trie .addEntry (entry , m .quitC )
123- return key , nil
135+ return addr , nil
124136}
125137
126138// RemoveEntry removes the given path from the manifest
@@ -129,7 +141,7 @@ func (m *ManifestWriter) RemoveEntry(path string) error {
129141 return nil
130142}
131143
132- // Store stores the manifest, returning the resulting storage key
144+ // Store stores the manifest, returning the resulting storage address
133145func (m * ManifestWriter ) Store () (storage.Address , error ) {
134146 return m .trie .ref , m .trie .recalcAndStore ()
135147}
@@ -211,51 +223,51 @@ type manifestTrieEntry struct {
211223 subtrie * manifestTrie
212224}
213225
214- func loadManifest (ctx context.Context , fileStore * storage.FileStore , hash storage.Address , quitC chan bool , decrypt DecryptFunc ) (trie * manifestTrie , err error ) { // non-recursive, subtrees are downloaded on-demand
215- log .Trace ("manifest lookup" , "key " , hash )
226+ func loadManifest (ctx context.Context , fileStore * storage.FileStore , addr storage.Address , quitC chan bool , decrypt DecryptFunc ) (trie * manifestTrie , err error ) { // non-recursive, subtrees are downloaded on-demand
227+ log .Trace ("manifest lookup" , "addr " , addr )
216228 // retrieve manifest via FileStore
217- manifestReader , isEncrypted := fileStore .Retrieve (ctx , hash )
218- log .Trace ("reader retrieved" , "key " , hash )
219- return readManifest (manifestReader , hash , fileStore , isEncrypted , quitC , decrypt )
229+ manifestReader , isEncrypted := fileStore .Retrieve (ctx , addr )
230+ log .Trace ("reader retrieved" , "addr " , addr )
231+ return readManifest (manifestReader , addr , fileStore , isEncrypted , quitC , decrypt )
220232}
221233
222- func readManifest (mr storage.LazySectionReader , hash storage.Address , fileStore * storage.FileStore , isEncrypted bool , quitC chan bool , decrypt DecryptFunc ) (trie * manifestTrie , err error ) { // non-recursive, subtrees are downloaded on-demand
234+ func readManifest (mr storage.LazySectionReader , addr storage.Address , fileStore * storage.FileStore , isEncrypted bool , quitC chan bool , decrypt DecryptFunc ) (trie * manifestTrie , err error ) { // non-recursive, subtrees are downloaded on-demand
223235
224236 // TODO check size for oversized manifests
225237 size , err := mr .Size (mr .Context (), quitC )
226238 if err != nil { // size == 0
227239 // can't determine size means we don't have the root chunk
228- log .Trace ("manifest not found" , "key " , hash )
240+ log .Trace ("manifest not found" , "addr " , addr )
229241 err = fmt .Errorf ("Manifest not Found" )
230242 return
231243 }
232244 if size > manifestSizeLimit {
233- log .Warn ("manifest exceeds size limit" , "key " , hash , "size" , size , "limit" , manifestSizeLimit )
245+ log .Warn ("manifest exceeds size limit" , "addr " , addr , "size" , size , "limit" , manifestSizeLimit )
234246 err = fmt .Errorf ("Manifest size of %v bytes exceeds the %v byte limit" , size , manifestSizeLimit )
235247 return
236248 }
237249 manifestData := make ([]byte , size )
238250 read , err := mr .Read (manifestData )
239251 if int64 (read ) < size {
240- log .Trace ("manifest not found" , "key " , hash )
252+ log .Trace ("manifest not found" , "addr " , addr )
241253 if err == nil {
242254 err = fmt .Errorf ("Manifest retrieval cut short: read %v, expect %v" , read , size )
243255 }
244256 return
245257 }
246258
247- log .Debug ("manifest retrieved" , "key " , hash )
259+ log .Debug ("manifest retrieved" , "addr " , addr )
248260 var man struct {
249261 Entries []* manifestTrieEntry `json:"entries"`
250262 }
251263 err = json .Unmarshal (manifestData , & man )
252264 if err != nil {
253- err = fmt .Errorf ("Manifest %v is malformed: %v" , hash .Log (), err )
254- log .Trace ("malformed manifest" , "key " , hash )
265+ err = fmt .Errorf ("Manifest %v is malformed: %v" , addr .Log (), err )
266+ log .Trace ("malformed manifest" , "addr " , addr )
255267 return
256268 }
257269
258- log .Trace ("manifest entries" , "key " , hash , "len" , len (man .Entries ))
270+ log .Trace ("manifest entries" , "addr " , addr , "len" , len (man .Entries ))
259271
260272 trie = & manifestTrie {
261273 fileStore : fileStore ,
@@ -406,12 +418,12 @@ func (mt *manifestTrie) recalcAndStore() error {
406418
407419 sr := bytes .NewReader (manifest )
408420 ctx := context .TODO ()
409- key , wait , err2 := mt .fileStore .Store (ctx , sr , int64 (len (manifest )), mt .encrypted )
421+ addr , wait , err2 := mt .fileStore .Store (ctx , sr , int64 (len (manifest )), mt .encrypted )
410422 if err2 != nil {
411423 return err2
412424 }
413425 err2 = wait (ctx )
414- mt .ref = key
426+ mt .ref = addr
415427 return err2
416428}
417429
0 commit comments