MCPcopy Index your code
hub / github.com/coder/coder / CreateTar

Function CreateTar

testutil/archive.go:17–51  ·  view source on GitHub ↗

Creates an in-memory tar of the files provided. Files in the archive are written with nobody owner/group, and -rw-rw-rw- permissions.

(t testing.TB, files map[string]string)

Source from the content-addressed store, hash-verified

15// Files in the archive are written with nobody
16// owner/group, and -rw-rw-rw- permissions.
17func CreateTar(t testing.TB, files map[string]string) []byte {
18 var buffer bytes.Buffer
19 writer := tar.NewWriter(&buffer)
20 // Keep track of directories previously added.
21 addedDirs := make(map[string]bool)
22 for path, content := range files {
23 // Add parent directories if they don't exist
24 dir := filepath.Dir(path)
25 if dir != "." && !addedDirs[dir] {
26 err := writer.WriteHeader(&tar.Header{
27 Name: dir + "/", // Directory names must end with /
28 Mode: 0o755,
29 Typeflag: tar.TypeDir,
30 })
31 require.NoError(t, err)
32 addedDirs[dir] = true
33 }
34
35 err := writer.WriteHeader(&tar.Header{
36 Name: path,
37 Size: int64(len(content)),
38 Uid: 65534, // nobody
39 Gid: 65534, // nogroup
40 Mode: 0o666, // -rw-rw-rw-
41 })
42 require.NoError(t, err)
43
44 _, err = writer.Write([]byte(content))
45 require.NoError(t, err)
46 }
47
48 err := writer.Flush()
49 require.NoError(t, err)
50 return buffer.Bytes()
51}
52
53// Creates an in-memory zip of the files provided.
54// Uses archive.CreateZipFromTar under the hood.

Callers 15

TestProvisionerdFunction · 0.92
TestTemplatePushFunction · 0.92
workspaceTagsTerraformFunction · 0.92
TestParseFunction · 0.92
TestProvision_CancelFunction · 0.92
TestProvisionFunction · 0.92

Calls 4

WriteMethod · 0.65
FlushMethod · 0.65
WriteHeaderMethod · 0.45
BytesMethod · 0.45

Tested by 15

TestProvisionerdFunction · 0.74
TestTemplatePushFunction · 0.74
workspaceTagsTerraformFunction · 0.74
TestParseFunction · 0.74
TestProvision_CancelFunction · 0.74
TestProvisionFunction · 0.74