Skip to content

Commit 7698cfd

Browse files
authored
chore: remove unnecessary extraction library (coder#12847)
This was allocating ~256KB on init.
1 parent b5b5c37 commit 7698cfd

File tree

5 files changed

+9
-24
lines changed

5 files changed

+9
-24
lines changed

cli/templatepull.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import (
77
"path/filepath"
88
"sort"
99

10-
"github.com/codeclysm/extract/v3"
1110
"golang.org/x/xerrors"
1211

1312
"github.com/coder/coder/v2/cli/cliui"
1413
"github.com/coder/coder/v2/codersdk"
14+
"github.com/coder/coder/v2/provisionersdk"
1515
"github.com/coder/serpent"
1616
)
1717

@@ -161,7 +161,7 @@ func (r *RootCmd) templatePull() *serpent.Command {
161161
}
162162

163163
_, _ = fmt.Fprintf(inv.Stderr, "Extracting template to %q\n", dest)
164-
err = extract.Tar(ctx, bytes.NewReader(raw), dest, nil)
164+
err = provisionersdk.Untar(dest, bytes.NewReader(raw))
165165
return err
166166
},
167167
}

cli/templatepull_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ package cli_test
33
import (
44
"archive/tar"
55
"bytes"
6-
"context"
76
"crypto/sha256"
87
"encoding/hex"
98
"os"
109
"path/filepath"
1110
"strings"
1211
"testing"
1312

14-
"github.com/codeclysm/extract/v3"
1513
"github.com/google/uuid"
1614
"github.com/stretchr/testify/require"
1715

@@ -20,6 +18,7 @@ import (
2018
"github.com/coder/coder/v2/coderd/coderdtest"
2119
"github.com/coder/coder/v2/coderd/rbac"
2220
"github.com/coder/coder/v2/provisioner/echo"
21+
"github.com/coder/coder/v2/provisionersdk"
2322
"github.com/coder/coder/v2/provisionersdk/proto"
2423
"github.com/coder/coder/v2/pty/ptytest"
2524
)
@@ -310,9 +309,7 @@ func TestTemplatePull_ToDir(t *testing.T) {
310309
_ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, updatedVersion.ID)
311310
coderdtest.UpdateActiveTemplateVersion(t, client, template.ID, updatedVersion.ID)
312311

313-
ctx := context.Background()
314-
315-
err = extract.Tar(ctx, bytes.NewReader(expected), expectedDest, nil)
312+
err = provisionersdk.Untar(expectedDest, bytes.NewReader(expected))
316313
require.NoError(t, err)
317314

318315
ents, _ := os.ReadDir(actualDest)
@@ -387,9 +384,7 @@ func TestTemplatePull_FolderConflict(t *testing.T) {
387384
)
388385
require.NoError(t, err)
389386

390-
ctx := context.Background()
391-
392-
err = extract.Tar(ctx, bytes.NewReader(expected), expectedDest, nil)
387+
err = provisionersdk.Untar(expectedDest, bytes.NewReader(expected))
393388
require.NoError(t, err)
394389

395390
inv, root := clitest.New(t, "templates", "pull", template.Name, conflictDest)

go.mod

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ require (
101101
github.com/chromedp/cdproto v0.0.0-20230802225258-3cf4e6d46a89
102102
github.com/chromedp/chromedp v0.9.2
103103
github.com/cli/safeexec v1.0.1
104-
github.com/codeclysm/extract/v3 v3.1.1
105104
github.com/coder/flog v1.1.0
106105
github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0
107106
github.com/coder/retry v1.5.1
@@ -328,7 +327,6 @@ require (
328327
github.com/gorilla/css v1.0.0 // indirect
329328
github.com/gorilla/mux v1.8.1 // indirect
330329
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
331-
github.com/h2non/filetype v1.1.3 // indirect
332330
github.com/hashicorp/errwrap v1.1.0 // indirect
333331
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
334332
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
@@ -349,7 +347,6 @@ require (
349347
github.com/josharian/intern v1.0.0 // indirect
350348
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 // indirect
351349
github.com/jsimonetti/rtnetlink v1.3.5 // indirect
352-
github.com/juju/errors v1.0.0 // indirect
353350
github.com/kortschak/wol v0.0.0-20200729010619-da482cc4850a // indirect
354351
github.com/kr/fs v0.1.0 // indirect
355352
github.com/leodido/go-urn v1.4.0 // indirect
@@ -406,7 +403,6 @@ require (
406403
github.com/tidwall/pretty v1.2.1 // indirect
407404
github.com/tinylib/msgp v1.1.8 // indirect
408405
github.com/u-root/uio v0.0.0-20240209044354-b3d14b93376a // indirect
409-
github.com/ulikunitz/xz v0.5.11 // indirect
410406
github.com/vishvananda/netlink v1.2.1-beta.2 // indirect
411407
github.com/vishvananda/netns v0.0.4 // indirect
412408
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect

go.sum

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew
8484
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
8585
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q=
8686
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
87-
github.com/arduino/go-paths-helper v1.2.0 h1:qDW93PR5IZUN/jzO4rCtexiwF8P4OIcOmcSgAYLZfY4=
88-
github.com/arduino/go-paths-helper v1.2.0/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
8987
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2 h1:7Ip0wMmLHLRJdrloDxZfhMm0xrLXZS8+COSu2bXmEQs=
9088
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
9189
github.com/armon/go-radix v1.0.1-0.20221118154546-54df44f2176c h1:651/eoCRnQ7YtSjAnSzRucrJz+3iGEFt+ysraELS81M=
@@ -199,8 +197,6 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
199197
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
200198
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
201199
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
202-
github.com/codeclysm/extract/v3 v3.1.1 h1:iHZtdEAwSTqPrd+1n4jfhr1qBhUWtHlMTjT90+fJVXg=
203-
github.com/codeclysm/extract/v3 v3.1.1/go.mod h1:ZJi80UG2JtfHqJI+lgJSCACttZi++dHxfWuPaMhlOfQ=
204200
github.com/coder/flog v1.1.0 h1:kbAes1ai8fIS5OeV+QAnKBQE22ty1jRF/mcAwHpLBa4=
205201
github.com/coder/flog v1.1.0/go.mod h1:UQlQvrkJBvnRGo69Le8E24Tcl5SJleAAR7gYEHzAmdQ=
206202
github.com/coder/glog v1.0.1-0.20220322161911-7365fe7f2cd1 h1:UqBrPWSYvRI2s5RtOul20JukUEpu4ip9u7biBL+ntgk=
@@ -502,8 +498,6 @@ github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/
502498
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
503499
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk=
504500
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0/go.mod h1:TzP6duP4Py2pHLVPPQp42aoYI92+PCrVotyR5e8Vqlk=
505-
github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg=
506-
github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
507501
github.com/hairyhenderson/go-codeowners v0.4.0 h1:Wx/tRXb07sCyHeC8mXfio710Iu35uAy5KYiBdLHdv4Q=
508502
github.com/hairyhenderson/go-codeowners v0.4.0/go.mod h1:iJgZeCt+W/GzXo5uchFCqvVHZY2T4TAIpvuVlKVkLxc=
509503
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
@@ -597,8 +591,6 @@ github.com/jsimonetti/rtnetlink v1.3.5/go.mod h1:0LFedyiTkebnd43tE4YAkWGIq9jQpho
597591
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
598592
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
599593
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
600-
github.com/juju/errors v1.0.0 h1:yiq7kjCLll1BiaRuNY53MGI0+EQ3rF6GB+wvboZDefM=
601-
github.com/juju/errors v1.0.0/go.mod h1:B5x9thDqx0wIMH3+aLIMP9HjItInYWObRovoCFM5Qe8=
602594
github.com/justinas/nosurf v1.1.1 h1:92Aw44hjSK4MxJeMSyDa7jwuI9GR2J/JCQiaKvXXSlk=
603595
github.com/justinas/nosurf v1.1.1/go.mod h1:ALpWdSbuNGy2lZWtyXdjkYv4edL23oSEgfBT1gPJ5BQ=
604596
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
@@ -904,8 +896,6 @@ github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVM
904896
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
905897
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
906898
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
907-
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
908-
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
909899
github.com/unrolled/secure v1.14.0 h1:u9vJTU/pR4Bny0ntLUMxdfLtmIRGvQf2sEFuA0TG9AE=
910900
github.com/unrolled/secure v1.14.0/go.mod h1:BmF5hyM6tXczk3MpQkFf1hpKSRqCyhqcbiQtiAF7+40=
911901
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=

provisionersdk/archive.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ func Untar(directory string, r io.Reader) error {
171171
}
172172
}
173173
case tar.TypeReg:
174+
err := os.MkdirAll(filepath.Dir(target), os.FileMode(header.Mode)|os.ModeDir|100)
175+
if err != nil {
176+
return err
177+
}
174178
file, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))
175179
if err != nil {
176180
return err

0 commit comments

Comments
 (0)