MCPcopy Index your code
hub / github.com/koding/kite / extractTar

Function extractTar

kitectl/command/install.go:189–238  ·  view source on GitHub ↗

extractTar reads from the io.Reader and writes the files into the directory.

(r io.Reader, dir string)

Source from the content-addressed store, hash-verified

187
188// extractTar reads from the io.Reader and writes the files into the directory.
189func extractTar(r io.Reader, dir string) error {
190 first := true // true if we are on the first entry of tarball
191 tr := tar.NewReader(r)
192 for {
193 hdr, err := tr.Next()
194 if err == io.EOF {
195 // end of tar archive
196 break
197 }
198 if err != nil {
199 return err
200 }
201
202 // Check if the same kite version is installed before
203 if first {
204 first = false
205 kiteName := strings.TrimSuffix(hdr.Name, ".kite/")
206
207 installed, err := isInstalled(kiteName)
208 if err != nil {
209 return err
210 }
211
212 if installed {
213 return fmt.Errorf("Already installed: %s", kiteName)
214 }
215 }
216
217 path := filepath.Join(dir, hdr.Name)
218
219 if hdr.FileInfo().IsDir() {
220 os.MkdirAll(path, 0700)
221 } else {
222 mode := 0600
223 if isBinaryFile(hdr.Name) {
224 mode = 0700
225 }
226
227 f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.FileMode(mode))
228 if err != nil {
229 return err
230 }
231
232 if _, err := io.Copy(f, tr); err != nil {
233 return err
234 }
235 }
236 }
237 return nil
238}
239
240// validatePackage does some checks on kite bundle and returns the bundle path.
241func validatePackage(tempKitePath, repoName string) (bundlePath string, err error) {

Callers 1

RunMethod · 0.85

Calls 3

isInstalledFunction · 0.85
isBinaryFileFunction · 0.85
CopyMethod · 0.80

Tested by

no test coverage detected