Skip to content

Commit

Permalink
Update v2 branch with code from the master branch (#282)
Browse files Browse the repository at this point in the history
* Merge remote-tracking branch 'origin/master' into client_umask
* move umask/mode calls in request.go
* Request.Mode => Request.GetMode && req.mode => req.Mode
* add req.CopyReader func for 3rd party pkgs
* fixup calls
* up go modules
* update cmd
  • Loading branch information
azr authored Oct 8, 2020
1 parent 2798df5 commit 3310219
Show file tree
Hide file tree
Showing 37 changed files with 359 additions and 367 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ are also supported. If the query parameters are present, these take priority.
* `aws_access_key_id` - AWS access key.
* `aws_access_key_secret` - AWS access key secret.
* `aws_access_token` - AWS access token if this is being used.
* `aws_profile` - Use this profile from local ~/.aws/ config. Takes priority over the other three.

#### Using IAM Instance Profiles with S3

Expand Down
8 changes: 4 additions & 4 deletions checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ func (c *Client) checksumFromFile(ctx context.Context, checksumURL string, check
defer os.Remove(tempfile)

req := &Request{
Pwd: pwd,
Mode: ModeFile,
Src: checksumURL,
Dst: tempfile,
Pwd: pwd,
GetMode: ModeFile,
Src: checksumURL,
Dst: tempfile,
// ProgressListener: c.ProgressListener, TODO(adrien): pass progress bar ?
}

Expand Down
28 changes: 14 additions & 14 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func (c *Client) Get(ctx context.Context, req *Request) (*GetResult, error) {
}

// Store this locally since there are cases we swap this
if req.Mode == ModeInvalid {
req.Mode = ModeAny
if req.GetMode == ModeInvalid {
req.GetMode = ModeAny
}

// If there is a subdir component, then we download the root separately
Expand Down Expand Up @@ -163,9 +163,9 @@ func (c *Client) get(ctx context.Context, req *Request, g Getter) (*GetResult, *
// Swap the download directory to be our temporary path and
// store the old values.
decompressDst = req.Dst
decompressDir = req.Mode != ModeFile
decompressDir = req.GetMode != ModeFile
req.Dst = filepath.Join(td, "archive")
req.Mode = ModeFile
req.GetMode = ModeFile
}

// Determine checksum if we have one
Expand All @@ -178,16 +178,16 @@ func (c *Client) get(ctx context.Context, req *Request, g Getter) (*GetResult, *
q.Del("checksum")
req.u.RawQuery = q.Encode()

if req.Mode == ModeAny {
if req.GetMode == ModeAny {
// Ask the getter which client mode to use
req.Mode, err = g.Mode(ctx, req.u)
req.GetMode, err = g.Mode(ctx, req.u)
if err != nil {
return nil, &getError{false, err}
}

// Destination is the base name of the URL path in "any" mode when
// a file source is detected.
if req.Mode == ModeFile {
if req.GetMode == ModeFile {
filename := filepath.Base(req.u.Path)

// Determine if we have a custom file name
Expand All @@ -205,7 +205,7 @@ func (c *Client) get(ctx context.Context, req *Request, g Getter) (*GetResult, *

// If we're not downloading a directory, then just download the file
// and return.
if req.Mode == ModeFile {
if req.GetMode == ModeFile {
getFile := true
if checksum != nil {
if err := checksum.Checksum(req.Dst); err == nil {
Expand All @@ -228,24 +228,24 @@ func (c *Client) get(ctx context.Context, req *Request, g Getter) (*GetResult, *
if decompressor != nil {
// We have a decompressor, so decompress the current destination
// into the final destination with the proper mode.
err := decompressor.Decompress(decompressDst, req.Dst, decompressDir)
err := decompressor.Decompress(decompressDst, req.Dst, decompressDir, req.umask())
if err != nil {
return nil, &getError{true, err}
}

// Swap the information back
req.Dst = decompressDst
if decompressDir {
req.Mode = ModeAny
req.GetMode = ModeAny
} else {
req.Mode = ModeFile
req.GetMode = ModeFile
}
}

// We check the dir value again because it can be switched back
// if we were unarchiving. If we're still only Get-ing a file, then
// we're done.
if req.Mode == ModeFile {
if req.GetMode == ModeFile {
return &GetResult{req.Dst}, nil
}
}
Expand Down Expand Up @@ -274,7 +274,7 @@ func (c *Client) get(ctx context.Context, req *Request, g Getter) (*GetResult, *
if err := os.RemoveAll(req.realDst); err != nil {
return nil, &getError{true, err}
}
if err := os.MkdirAll(req.realDst, 0755); err != nil {
if err := os.MkdirAll(req.realDst, req.Mode(0755)); err != nil {
return nil, &getError{true, err}
}

Expand All @@ -284,7 +284,7 @@ func (c *Client) get(ctx context.Context, req *Request, g Getter) (*GetResult, *
return nil, &getError{true, err}
}

err = copyDir(ctx, req.realDst, subDir, false)
err = copyDir(ctx, req.realDst, subDir, false, req.umask())
if err != nil {
return nil, &getError{false, err}
}
Expand Down
9 changes: 5 additions & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package getter

import (
"context"
testing_helper "github.com/hashicorp/go-getter/v2/helper/testing"
"os"
"path/filepath"
"testing"

testing_helper "github.com/hashicorp/go-getter/v2/helper/testing"
)

func TestSmb_ClientGet(t *testing.T) {
Expand Down Expand Up @@ -51,9 +52,9 @@ func TestSmb_ClientGet(t *testing.T) {
}

req := &Request{
Dst: dst,
Src: tt.rawURL,
Mode: tt.mode,
Dst: dst,
Src: tt.rawURL,
GetMode: tt.mode,
}

result, err := DefaultClient.Get(context.Background(), req)
Expand Down
2 changes: 1 addition & 1 deletion cmd/go-getter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/fatih/color v1.9.0 // indirect
github.com/hashicorp/go-getter/gcs/v2 v2.0.0-00010101000000-000000000000
github.com/hashicorp/go-getter/s3/v2 v2.0.0-00010101000000-000000000000
github.com/hashicorp/go-getter/v2 v2.0.0-20200511090339-3107ec4af37a
github.com/hashicorp/go-getter/v2 v2.0.0-20201001102414-74576d5f550a
github.com/mattn/go-runewidth v0.0.8 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.28 // indirect
)
17 changes: 4 additions & 13 deletions cmd/go-getter/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM=
github.com/aws/aws-sdk-go v1.30.8 h1:4BHbh8K3qKmcnAgToZ2LShldRF9inoqIBccpCLNCy3I=
github.com/aws/aws-sdk-go v1.30.8/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
github.com/cheggaaa/pb v1.0.28 h1:kWGpdAcSp3MxMU9CCHOwz/8V0kCHN4+9yQm2MzWuI98=
github.com/cheggaaa/pb v1.0.28/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
Expand All @@ -44,10 +42,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
Expand Down Expand Up @@ -88,10 +84,11 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-getter v1.4.1/go.mod h1:7qxyCd8rBfcShwsvxgIguu4KbS3l8bUCwg2Umn7RjeY=
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo=
github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I=
Expand All @@ -101,7 +98,6 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc=
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
Expand All @@ -113,14 +109,11 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.8 h1:3tS41NlGYSmhhe/8fhGRzc+z3AYCw1Fe1WAyLuujKs0=
github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0=
Expand All @@ -133,12 +126,11 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/ulikunitz/xz v0.5.5 h1:pFrO0lVpTBXLpYw+pnLj6TbvHuyjXMfjGeCwSqCVwok=
github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/ulikunitz/xz v0.5.8 h1:ERv8V6GKqVi23rgu5cj9pVfVzJbOqAY2Ntl88O6c2nQ=
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0 h1:C9hSCOW830chIVkdja34wa6Ky+IzWllkUinR+BtRZd4=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
Expand Down Expand Up @@ -325,7 +317,6 @@ google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/cheggaaa/pb.v1 v1.0.28 h1:n1tBJnnK2r7g9OW2btFH91V92STTUevLXYFb8gy9EMk=
gopkg.in/cheggaaa/pb.v1 v1.0.28/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
Expand Down
8 changes: 4 additions & 4 deletions cmd/go-getter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ func main() {
ctx, cancel := context.WithCancel(context.Background())
// Build the client
req := &getter.Request{
Src: args[0],
Dst: args[1],
Pwd: pwd,
Mode: mode,
Src: args[0],
Dst: args[1],
Pwd: pwd,
GetMode: mode,
}
if *progress {
req.ProgressListener = defaultProgressBar
Expand Down
24 changes: 4 additions & 20 deletions copy_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// should already exist.
//
// If ignoreDot is set to true, then dot-prefixed files/folders are ignored.
func copyDir(ctx context.Context, dst string, src string, ignoreDot bool) error {
func copyDir(ctx context.Context, dst string, src string, ignoreDot bool, umask os.FileMode) error {
src, err := filepath.EvalSymlinks(src)
if err != nil {
return err
Expand Down Expand Up @@ -46,32 +46,16 @@ func copyDir(ctx context.Context, dst string, src string, ignoreDot bool) error
return nil
}

if err := os.MkdirAll(dstPath, 0755); err != nil {
if err := os.MkdirAll(dstPath, mode(0755, umask)); err != nil {
return err
}

return nil
}

// If we have a file, copy the contents.
srcF, err := os.Open(path)
if err != nil {
return err
}
defer srcF.Close()

dstF, err := os.Create(dstPath)
if err != nil {
return err
}
defer dstF.Close()

if _, err := Copy(ctx, dstF, srcF); err != nil {
return err
}

// Chmod it
return os.Chmod(dstPath, info.Mode())
_, err = copyFile(ctx, dstPath, path, info.Mode(), umask)
return err
}

return filepath.Walk(src, walkFn)
Expand Down
3 changes: 2 additions & 1 deletion decompress.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package getter

import (
"os"
"strings"
)

Expand All @@ -14,7 +15,7 @@ type Decompressor interface {
// Decompress should decompress src to dst. dir specifies whether dst
// is a directory or single file. src is guaranteed to be a single file
// that exists. dst is not guaranteed to exist already.
Decompress(dst, src string, dir bool) error
Decompress(dst, src string, dir bool, umask os.FileMode) error
}

// Decompressors is the mapping of extension to the Decompressor implementation
Expand Down
14 changes: 3 additions & 11 deletions decompress_bzip2.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package getter
import (
"compress/bzip2"
"fmt"
"io"
"os"
"path/filepath"
)
Expand All @@ -12,14 +11,14 @@ import (
// decompress bz2 files.
type Bzip2Decompressor struct{}

func (d *Bzip2Decompressor) Decompress(dst, src string, dir bool) error {
func (d *Bzip2Decompressor) Decompress(dst, src string, dir bool, umask os.FileMode) error {
// Directory isn't supported at all
if dir {
return fmt.Errorf("bzip2-compressed files can only unarchive to a single file")
}

// If we're going into a directory we should make that first
if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
if err := os.MkdirAll(filepath.Dir(dst), mode(0755, umask)); err != nil {
return err
}

Expand All @@ -34,12 +33,5 @@ func (d *Bzip2Decompressor) Decompress(dst, src string, dir bool) error {
bzipR := bzip2.NewReader(f)

// Copy it out
dstF, err := os.Create(dst)
if err != nil {
return err
}
defer dstF.Close()

_, err = io.Copy(dstF, bzipR)
return err
return copyReader(dst, bzipR, 0622, umask)
}
14 changes: 3 additions & 11 deletions decompress_gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package getter
import (
"compress/gzip"
"fmt"
"io"
"os"
"path/filepath"
)
Expand All @@ -12,14 +11,14 @@ import (
// decompress gzip files.
type GzipDecompressor struct{}

func (d *GzipDecompressor) Decompress(dst, src string, dir bool) error {
func (d *GzipDecompressor) Decompress(dst, src string, dir bool, umask os.FileMode) error {
// Directory isn't supported at all
if dir {
return fmt.Errorf("gzip-compressed files can only unarchive to a single file")
}

// If we're going into a directory we should make that first
if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
if err := os.MkdirAll(filepath.Dir(dst), mode(0755, umask)); err != nil {
return err
}

Expand All @@ -38,12 +37,5 @@ func (d *GzipDecompressor) Decompress(dst, src string, dir bool) error {
defer gzipR.Close()

// Copy it out
dstF, err := os.Create(dst)
if err != nil {
return err
}
defer dstF.Close()

_, err = io.Copy(dstF, gzipR)
return err
return copyReader(dst, gzipR, 0622, umask)
}
Loading

0 comments on commit 3310219

Please sign in to comment.