MCPcopy Index your code
hub / github.com/devspace-sh/devspace / writeTar

Function writeTar

pkg/devspace/kubectl/copy.go:54–88  ·  view source on GitHub ↗
(writer io.Writer, localPath string, exclude []string)

Source from the content-addressed store, hash-verified

52}
53
54func writeTar(writer io.Writer, localPath string, exclude []string) error {
55 absolute, err := filepath.Abs(localPath)
56 if err != nil {
57 return errors.Wrap(err, "absolute")
58 }
59
60 // Check if target is there
61 stat, err := os.Stat(absolute)
62 if err != nil {
63 return errors.Wrap(err, "stat")
64 }
65
66 // Compile ignore paths
67 ignoreMatcher, err := ignoreparser.CompilePaths(exclude, log.Discard)
68 if err != nil {
69 return errors.Wrap(err, "compile exclude paths")
70 }
71
72 // Use compression
73 gw := gzip.NewWriter(writer)
74 defer gw.Close()
75
76 // Create tar writer
77 tarWriter := tar.NewWriter(gw)
78 defer tarWriter.Close()
79
80 // When its a file we copy the file to the toplevel of the tar
81 if !stat.IsDir() {
82 return sync.NewArchiver(filepath.Dir(absolute), tarWriter, ignoreMatcher).AddToArchive(filepath.Base(absolute))
83 }
84
85 // When its a folder we copy the contents and not the folder itself to the
86 // toplevel of the tar
87 return sync.NewArchiver(absolute, tarWriter, ignoreMatcher).AddToArchive("")
88}

Callers 1

CopyMethod · 0.85

Calls 5

CompilePathsFunction · 0.92
NewArchiverFunction · 0.92
AddToArchiveMethod · 0.80
CloseMethod · 0.65
IsDirMethod · 0.45

Tested by

no test coverage detected