Avoid crash on invalid Move arguments

This chnage prevents a crash when moving from a non-existent directory that has
a file as a parent. To prevent this, we simply check that the node is a
directory and throws an error if it is not.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2015-04-01 18:45:13 -07:00
parent 9ee35877e3
commit 06acde06cb
2 changed files with 21 additions and 3 deletions

View file

@ -212,12 +212,17 @@ func (d *dir) move(src, dst string) error {
return errNotExists
}
s, ok := sp.(*dir).children[srcFilename]
spd, ok := sp.(*dir)
if !ok {
return errIsNotDir // paranoid.
}
s, ok := spd.children[srcFilename]
if !ok {
return errNotExists
}
delete(sp.(*dir).children, srcFilename)
delete(spd.children, srcFilename)
switch n := s.(type) {
case *dir: