Fix copy directory resource leak

This commit is contained in:
Liang Ding 2015-10-26 14:19:46 +08:00
parent 42093ebfc1
commit 1dd79cf684
1 changed files with 10 additions and 1 deletions

View File

@ -123,8 +123,17 @@ func (*myfile) CopyDir(source string, dest string) (err error) {
return err return err
} }
directory, _ := os.Open(source) directory, err := os.Open(source)
if err != nil {
return err
}
defer directory.Close()
objects, err := directory.Readdir(-1) objects, err := directory.Readdir(-1)
if err != nil {
return err
}
for _, obj := range objects { for _, obj := range objects {
srcFilePath := filepath.Join(source, obj.Name()) srcFilePath := filepath.Join(source, obj.Name())