MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / createArchive

Function createArchive

dgraph/cmd/debuginfo/archive.go:86–118  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

84// The final tar is placed in the same directory with the name same to the
85// archived directory.
86func 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.
121func createGzipArchive(debugDir string) (string, error) {

Callers 1

createGzipArchiveFunction · 0.85

Calls 3

WarningfMethod · 0.80
CreateMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected