createArchive creates a gzipped tar archive for the directory provided by recursively traversing in the directory. The final tar is placed in the same directory with the name same to the archived directory.
(debugDir string)
| 84 | // The final tar is placed in the same directory with the name same to the |
| 85 | // archived directory. |
| 86 | func createArchive(debugDir string) (string, error) { |
| 87 | archivePath := fmt.Sprintf("%s.tar", filepath.Base(debugDir)) |
| 88 | file, err := os.Create(archivePath) |
| 89 | if err != nil { |
| 90 | return "", err |
| 91 | } |
| 92 | defer func() { |
| 93 | if err := file.Close(); err != nil { |
| 94 | glog.Warningf("error closing file: %v", err) |
| 95 | } |
| 96 | }() |
| 97 | |
| 98 | writer := tar.NewWriter(file) |
| 99 | defer func() { |
| 100 | if err := writer.Close(); err != nil { |
| 101 | glog.Warningf("error closing writer: %v", err) |
| 102 | } |
| 103 | }() |
| 104 | |
| 105 | var baseDir string |
| 106 | if info, err := os.Stat(debugDir); os.IsNotExist(err) { |
| 107 | return "", err |
| 108 | } else if err == nil && info.IsDir() { |
| 109 | baseDir = filepath.Base(debugDir) |
| 110 | } |
| 111 | |
| 112 | w := &walker{ |
| 113 | baseDir: baseDir, |
| 114 | debugDir: debugDir, |
| 115 | output: writer, |
| 116 | } |
| 117 | return archivePath, filepath.Walk(debugDir, w.walkPath) |
| 118 | } |
| 119 | |
| 120 | // Creates a Gzipped tar archive of the directory provided as parameter. |
| 121 | func createGzipArchive(debugDir string) (string, error) { |
no test coverage detected