package lib import ( "archive/zip" "errors" "fmt" "io" "os" "path" "path/filepath" "strings" "time" ) const ( CMD_ZIP = "zip" CMD_PACK = "pack" ) func RecursiveZip(i int, pathToZip, destinationPath string) error { Log(i, "mk:zip", "O", "Starting Zip") destinationFile, err := os.Create(destinationPath) if err != nil { return err } myZip := zip.NewWriter(destinationFile) err = filepath.Walk(pathToZip, func(filePath string, info os.FileInfo, err error) error { Log(i, "mk:zip", "O", fmt.Sprintf("Adding file: %s", filePath)) if info.IsDir() { return nil } if err != nil { return err } relPath := strings.TrimPrefix(filePath, filepath.Dir(pathToZip)) zipFile, err := myZip.Create(relPath) if err != nil { return err } fsFile, err := os.Open(filePath) if err != nil { return err } _, err = io.Copy(zipFile, fsFile) if err != nil { return err } return nil }) if err != nil { return err } err = myZip.Close() if err != nil { return err } Log(i, "mk:zip", "O", fmt.Sprintf("Zip finished: %s", destinationPath)) return nil } func RunMkCmd(i int, line string) error { parts := strings.Split(line, " ") switch parts[0] { case CMD_ZIP: if len(parts) < 3 { return errors.New(fmt.Sprintf("Not enought params: must be zip