Skip to content

Commit

Permalink
Add update checking, performance improvements (#418)
Browse files Browse the repository at this point in the history
* Add update checking, performance improvements

* f
  • Loading branch information
marccampbell authored Oct 9, 2024
1 parent f189d92 commit 87ed9ce
Show file tree
Hide file tree
Showing 12 changed files with 775 additions and 170 deletions.
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
github.com/tj/go-spin v1.1.0
github.com/usrbinapp/usrbin-go v0.0.6
golang.org/x/crypto v0.23.0
golang.org/x/term v0.22.0
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -289,8 +288,5 @@ require (
sigs.k8s.io/yaml v1.4.0 // indirect
)

// useful when debugging local usrbin-go changes
// replace github.com/usrbinapp/usrbin-go => ../../usrbinapp/usrbin-go

// patches CVE-2024-6257
replace github.com/hashicorp/go-getter => github.com/hashicorp/go-getter v1.7.5
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1064,8 +1064,6 @@ github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oW
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/usrbinapp/usrbin-go v0.0.6 h1:B+LpBK1AT3SI6oH8BjR0z+rnYpVhpml2ZbN5wsXs7Gk=
github.com/usrbinapp/usrbin-go v0.0.6/go.mod h1:gDtvVf9mVkeVfWj4Oa4Ur4uZQOv9TXPfoKgwnLUbbic=
github.com/vbatts/tar-split v0.11.5 h1:3bHCTIheBm1qFTcgh9oPu+nNBtX+XJIupG/vacinCts=
github.com/vbatts/tar-split v0.11.5/go.mod h1:yZbwRsSeGjusneWgA781EKej9HF8vme8okylkAeNKLk=
github.com/vmware-tanzu/velero v1.13.2 h1:72Rw+11HJB6XUYfH9/M/jle6duSLyGhMisMMYFr/1qs=
Expand Down
120 changes: 0 additions & 120 deletions pkg/replicatedfile/cache.go

This file was deleted.

79 changes: 79 additions & 0 deletions pkg/version/archive/tgz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package archive

import (
"archive/tar"
"compress/gzip"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/pkg/errors"
)

// CreateTGZFileFromDir will archive the contents of dir into
// a tgz file, and the caller must delete
func CreateTGZFileFromDir(dir string) (string, error) {
tmpFile, err := ioutil.TempFile("", "replicated-update")
if err != nil {
return "", errors.Wrap(err, "create temp file")
}

file, err := os.Create(tmpFile.Name())
if err != nil {
return "", errors.Wrap(err, "create file")
}
defer file.Close()

gw := gzip.NewWriter(file)
defer gw.Close()

tw := tar.NewWriter(gw)
defer tw.Close()

// walk path
if err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

if info.IsDir() {
return nil
}

if info.Mode()&os.ModeSymlink != 0 {
return nil
}

header, err := tar.FileInfoHeader(info, "")
if err != nil {
return err
}

header.Name = strings.TrimLeft(strings.TrimPrefix(path, dir), string(filepath.Separator))
header.Size = info.Size()
header.Mode = int64(info.Mode())
header.ModTime = info.ModTime()

singleFile, err := os.Open(path)
if err != nil {
return err
}
defer singleFile.Close()

if err := tw.WriteHeader(header); err != nil {
return err
}

if _, err := io.Copy(tw, singleFile); err != nil {
return err
}

return nil
}); err != nil {
return "", err
}

return tmpFile.Name(), nil
}
Loading

0 comments on commit 87ed9ce

Please sign in to comment.