(inpath string, outpath string)
| 659 | } |
| 660 | |
| 661 | func unpackGzip(inpath string, outpath string) error { |
| 662 | var exists bool |
| 663 | var err error |
| 664 | |
| 665 | exists, err = FileExists(outpath) |
| 666 | |
| 667 | if err != nil { |
| 668 | return err |
| 669 | } |
| 670 | |
| 671 | if exists { |
| 672 | errStr := wski18n.T("The file '{{.name}}' already exists. Delete it and retry.", |
| 673 | map[string]interface{}{"name": outpath}) |
| 674 | werr := whisk.MakeWskError(errors.New(errStr), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE) |
| 675 | return werr |
| 676 | } |
| 677 | |
| 678 | exists, err = FileExists(inpath) |
| 679 | |
| 680 | if err != nil { |
| 681 | return err |
| 682 | } |
| 683 | |
| 684 | if !exists { |
| 685 | errMsg := wski18n.T("File '{{.name}}' is not a valid file or it does not exist", |
| 686 | map[string]interface{}{ |
| 687 | "name": inpath, |
| 688 | }) |
| 689 | whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXIT_CODE_ERR_USAGE, |
| 690 | whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE) |
| 691 | |
| 692 | return whiskErr |
| 693 | } |
| 694 | |
| 695 | unGzFile, err := os.Create(outpath) |
| 696 | if err != nil { |
| 697 | whisk.Debug(whisk.DbgError, "os.Create(%s) failed: %s\n", outpath, err) |
| 698 | errStr := wski18n.T("Error creating unGzip file '{{.name}}': {{.err}}", |
| 699 | map[string]interface{}{"name": outpath, "err": err}) |
| 700 | werr := whisk.MakeWskError(errors.New(errStr), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE) |
| 701 | return werr |
| 702 | } |
| 703 | defer unGzFile.Close() |
| 704 | |
| 705 | gzFile, err := os.Open(inpath) |
| 706 | if err != nil { |
| 707 | whisk.Debug(whisk.DbgError, "os.Open(%s) failed: %s\n", inpath, err) |
| 708 | errStr := wski18n.T("Error opening Gzip file '{{.name}}': {{.err}}", |
| 709 | map[string]interface{}{"name": inpath, "err": err}) |
| 710 | werr := whisk.MakeWskError(errors.New(errStr), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE) |
| 711 | return werr |
| 712 | } |
| 713 | defer gzFile.Close() |
| 714 | |
| 715 | gzReader, err := gzip.NewReader(gzFile) |
| 716 | if err != nil { |
| 717 | whisk.Debug(whisk.DbgError, "gzip.NewReader() failed: %s\n", err) |
| 718 | errStr := wski18n.T("Unable to unzip file '{{.name}}': {{.err}}", |
no test coverage detected