@@ -20,19 +20,18 @@ package main
2020import (
2121 "encoding/json"
2222 "fmt"
23- "log"
2423 "mime"
2524 "path/filepath"
2625 "strings"
2726
27+ "github.com/ethereum/go-ethereum/cmd/utils"
2828 "gopkg.in/urfave/cli.v1"
2929)
3030
3131func add (ctx * cli.Context ) {
32-
3332 args := ctx .Args ()
3433 if len (args ) < 3 {
35- log . Fatal ( "need atleast three arguments <MHASH> <path> <HASH> [<content-type>]" )
34+ utils . Fatalf ( "Need atleast three arguments <MHASH> <path> <HASH> [<content-type>]" )
3635 }
3736
3837 var (
@@ -66,7 +65,7 @@ func update(ctx *cli.Context) {
6665
6766 args := ctx .Args ()
6867 if len (args ) < 3 {
69- log . Fatal ( "need atleast three arguments <MHASH> <path> <HASH>" )
68+ utils . Fatalf ( "Need atleast three arguments <MHASH> <path> <HASH>" )
7069 }
7170
7271 var (
@@ -98,7 +97,7 @@ func update(ctx *cli.Context) {
9897func remove (ctx * cli.Context ) {
9998 args := ctx .Args ()
10099 if len (args ) < 2 {
101- log . Fatal ( "need atleast two arguments <MHASH> <path>" )
100+ utils . Fatalf ( "Need atleast two arguments <MHASH> <path>" )
102101 }
103102
104103 var (
@@ -134,19 +133,19 @@ func addEntryToManifest(ctx *cli.Context, mhash, path, hash, ctype string) strin
134133
135134 mroot , err := client .downloadManifest (mhash )
136135 if err != nil {
137- log . Fatalln ( "manifest download failed:" , err )
136+ utils . Fatalf ( "Manifest download failed: %v " , err )
138137 }
139138
140139 //TODO: check if the "hash" to add is valid and present in swarm
141140 _ , err = client .downloadManifest (hash )
142141 if err != nil {
143- log . Fatalln ( "hash to add is not present:" , err )
142+ utils . Fatalf ( "Hash to add is not present: %v " , err )
144143 }
145144
146145 // See if we path is in this Manifest or do we have to dig deeper
147146 for _ , entry := range mroot .Entries {
148147 if path == entry .Path {
149- log . Fatal ( path , "Already present, not adding anything" )
148+ utils . Fatalf ( "Path %s already present, not adding anything", path )
150149 } else {
151150 if entry .ContentType == "application/bzz-manifest+json" {
152151 prfxlen := strings .HasPrefix (path , entry .Path )
@@ -183,7 +182,7 @@ func addEntryToManifest(ctx *cli.Context, mhash, path, hash, ctype string) strin
183182
184183 newManifestHash , err := client .uploadManifest (mroot )
185184 if err != nil {
186- log . Fatalln ( "manifest upload failed:" , err )
185+ utils . Fatalf ( "Manifest upload failed: %v " , err )
187186 }
188187 return newManifestHash
189188
@@ -208,7 +207,7 @@ func updateEntryInManifest(ctx *cli.Context, mhash, path, hash, ctype string) st
208207
209208 mroot , err := client .downloadManifest (mhash )
210209 if err != nil {
211- log . Fatalln ( "manifest download failed:" , err )
210+ utils . Fatalf ( "Manifest download failed: %v " , err )
212211 }
213212
214213 //TODO: check if the "hash" with which to update is valid and present in swarm
@@ -228,7 +227,7 @@ func updateEntryInManifest(ctx *cli.Context, mhash, path, hash, ctype string) st
228227 }
229228
230229 if longestPathEntry .Path == "" && newEntry .Path == "" {
231- log . Fatal ( path , " Path not present in the Manifest, not setting anything" )
230+ utils . Fatalf ( " Path %s not present in the Manifest, not setting anything", path )
232231 }
233232
234233 if longestPathEntry .Path != "" {
@@ -268,7 +267,7 @@ func updateEntryInManifest(ctx *cli.Context, mhash, path, hash, ctype string) st
268267
269268 newManifestHash , err := client .uploadManifest (mroot )
270269 if err != nil {
271- log . Fatalln ( "manifest upload failed:" , err )
270+ utils . Fatalf ( "Manifest upload failed: %v " , err )
272271 }
273272 return newManifestHash
274273}
@@ -292,7 +291,7 @@ func removeEntryFromManifest(ctx *cli.Context, mhash, path string) string {
292291
293292 mroot , err := client .downloadManifest (mhash )
294293 if err != nil {
295- log . Fatalln ( "manifest download failed:" , err )
294+ utils . Fatalf ( "Manifest download failed: %v " , err )
296295 }
297296
298297 // See if we path is in this Manifest or do we have to dig deeper
@@ -310,7 +309,7 @@ func removeEntryFromManifest(ctx *cli.Context, mhash, path string) string {
310309 }
311310
312311 if longestPathEntry .Path == "" && entryToRemove .Path == "" {
313- log . Fatal ( path , "Path not present in the Manifest, not removing anything" )
312+ utils . Fatalf ( "Path %s not present in the Manifest, not removing anything" , path )
314313 }
315314
316315 if longestPathEntry .Path != "" {
@@ -342,8 +341,7 @@ func removeEntryFromManifest(ctx *cli.Context, mhash, path string) string {
342341
343342 newManifestHash , err := client .uploadManifest (mroot )
344343 if err != nil {
345- log . Fatalln ( "manifest upload failed:" , err )
344+ utils . Fatalf ( "Manifest upload failed: %v " , err )
346345 }
347346 return newManifestHash
348-
349347}
0 commit comments