@cryptotaxi247 / kubo / commits / 6588bbc98

More thorough error checking.

License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io>

Stephen Whitmore committed Apr 8, 2016 at 14:33 UTC 6588bbc98887da1d0a87e3f13a276b3ce09da5b5
2 files changed +11 -3
core/coreunix/add.go
+10 -2
@@ -186,7 +186,12 @@ func (adder *Adder) Finalize(write bool) (*dag.Node, error) {
186 if !adder.Wrap {
187 name = rootNode.Links[0].Name
188
189 - root, err = adder.mr.GetValue().(*mfs.Directory).Child(name)
189 + dir, ok := adder.mr.GetValue().(*mfs.Directory)
190 + if !ok {
191 + return nil, fmt.Errorf("root is not a directory")
192 + }
193 +
194 + root, err = dir.Child(name)
195 if err != nil {
196 return nil, err
197 }
@@ -221,7 +226,10 @@ func (adder *Adder) outputDirs(path string, fs mfs.FSNode) error {
226 return nil
227 }
228
224 - dir := fs.(*mfs.Directory)
229 + dir, ok := fs.(*mfs.Directory)
230 + if !ok {
231 + return fmt.Errorf("received FSNode of type TDir that was not a Directory")
232 + }
233
234 for _, name := range dir.ListNames() {
235 child, err := dir.Child(name)
mfs/ops.go
+1 -1
@@ -102,7 +102,7 @@ func PutNode(r *Root, path string, nd *dag.Node) error {
102 // intermediary directories as needed if 'mkparents' is set to true
103 func Mkdir(r *Root, pth string, mkparents bool, flush bool) (*Directory, error) {
104 if pth == "" {
105 - return nil, nil
105 + return nil, fmt.Errorf("no path given to Mkdir")
106 }
107 parts := path.SplitList(pth)
108 if parts[0] == "" {