(inpath string)
| 734 | } |
| 735 | |
| 736 | func unpackZip(inpath string) error { |
| 737 | exists, err := FileExists(inpath) |
| 738 | |
| 739 | if err != nil { |
| 740 | return err |
| 741 | } |
| 742 | |
| 743 | if !exists { |
| 744 | errMsg := wski18n.T("File '{{.name}}' is not a valid file or it does not exist", |
| 745 | map[string]interface{}{ |
| 746 | "name": inpath, |
| 747 | }) |
| 748 | whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXIT_CODE_ERR_USAGE, |
| 749 | whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE) |
| 750 | |
| 751 | return whiskErr |
| 752 | } |
| 753 | zipFileReader, err := zip.OpenReader(inpath) |
| 754 | if err != nil { |
| 755 | whisk.Debug(whisk.DbgError, "zip.OpenReader(%s) failed: %s\n", inpath, err) |
| 756 | errStr := wski18n.T("Unable to opens '{{.name}}' for unzipping: {{.err}}", |
| 757 | map[string]interface{}{"name": inpath, "err": err}) |
| 758 | werr := whisk.MakeWskError(errors.New(errStr), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE) |
| 759 | return werr |
| 760 | } |
| 761 | defer zipFileReader.Close() |
| 762 | |
| 763 | // Loop through the files in the zipfile |
| 764 | for _, item := range zipFileReader.File { |
| 765 | itemName := item.Name |
| 766 | itemType := item.Mode() |
| 767 | |
| 768 | whisk.Debug(whisk.DbgInfo, "file item - %#v\n", item) |
| 769 | |
| 770 | if itemType.IsDir() { |
| 771 | if err := os.MkdirAll(item.Name, item.Mode()); err != nil { |
| 772 | whisk.Debug(whisk.DbgError, "os.MkdirAll(%s, %d) failed: %s\n", item.Name, item.Mode(), err) |
| 773 | errStr := wski18n.T("Unable to create directory '{{.dir}}' while unzipping '{{.name}}': {{.err}}", |
| 774 | map[string]interface{}{"dir": item.Name, "name": inpath, "err": err}) |
| 775 | werr := whisk.MakeWskError(errors.New(errStr), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE) |
| 776 | return werr |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | if itemType.IsRegular() { |
| 781 | unzipFile, err := item.Open() |
| 782 | defer unzipFile.Close() |
| 783 | if err != nil { |
| 784 | whisk.Debug(whisk.DbgError, "'%s' Open() failed: %s\n", item.Name, err) |
| 785 | errStr := wski18n.T("Unable to open zipped file '{{.file}}' while unzipping '{{.name}}': {{.err}}", |
| 786 | map[string]interface{}{"file": item.Name, "name": inpath, "err": err}) |
| 787 | werr := whisk.MakeWskError(errors.New(errStr), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE) |
| 788 | return werr |
| 789 | } |
| 790 | targetFile, err := os.Create(itemName) |
| 791 | if err != nil { |
| 792 | whisk.Debug(whisk.DbgError, "os.Create(%s) failed: %s\n", itemName, err) |
| 793 | errStr := wski18n.T("Unable to create file '{{.file}}' while unzipping '{{.name}}': {{.err}}", |
nothing calls this directly
no test coverage detected