Skip to content

Commit

Permalink
roblox/bootstrapper: seperate package manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
apprehensions committed Nov 3, 2023
1 parent 08452aa commit 1bde390
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
24 changes: 12 additions & 12 deletions cmd/vinegar/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (b *Binary) Install() error {
return err
}

manifest, err := bootstrapper.FetchManifest(&b.Version)
manifest, err := bootstrapper.FetchPackageManifest(&b.Version)
if err != nil {
return err
}
Expand Down Expand Up @@ -302,7 +302,7 @@ func (b *Binary) Install() error {
return err
}

if err := state.SaveManifest(&manifest); err != nil {
if err := state.SavePackageManifest(&manifest); err != nil {
return err
}

Expand All @@ -313,11 +313,11 @@ func (b *Binary) Install() error {
return state.CleanVersions()
}

func (b *Binary) PerformPackages(m *bootstrapper.Manifest, fn func(bootstrapper.Package) error) error {
func (b *Binary) PerformPackages(pm *bootstrapper.PackageManifest, fn func(bootstrapper.Package) error) error {
donePkgs := 0
pkgsLen := len(m.Packages)
pkgsLen := len(pm.Packages)

return m.Packages.Perform(func(pkg bootstrapper.Package) error {
return pm.Packages.Perform(func(pkg bootstrapper.Package) error {
err := fn(pkg)
if err != nil {
return err
Expand All @@ -330,19 +330,19 @@ func (b *Binary) PerformPackages(m *bootstrapper.Manifest, fn func(bootstrapper.
})
}

func (b *Binary) DownloadPackages(m *bootstrapper.Manifest) error {
log.Printf("Downloading %d Packages for %s", len(m.Packages), m.Version.GUID)
func (b *Binary) DownloadPackages(pm *bootstrapper.PackageManifest) error {
log.Printf("Downloading %d Packages for %s", len(pm.Packages), pm.Version.GUID)

return b.PerformPackages(m, func(pkg bootstrapper.Package) error {
return pkg.Fetch(filepath.Join(dirs.Downloads, pkg.Checksum), m.DeployURL)
return b.PerformPackages(pm, func(pkg bootstrapper.Package) error {
return pkg.Fetch(filepath.Join(dirs.Downloads, pkg.Checksum), pm.DeployURL)
})
}

func (b *Binary) ExtractPackages(m *bootstrapper.Manifest) error {
log.Printf("Extracting %d Packages for %s", len(m.Packages), m.Version.GUID)
func (b *Binary) ExtractPackages(pm *bootstrapper.PackageManifest) error {
log.Printf("Extracting %d Packages for %s", len(pm.Packages), pm.Version.GUID)
pkgDirs := bootstrapper.BinaryDirectories(b.Type)

return b.PerformPackages(m, func(pkg bootstrapper.Package) error {
return b.PerformPackages(pm, func(pkg bootstrapper.Package) error {
dest, ok := pkgDirs[pkg.Name]

if !ok {
Expand Down
8 changes: 4 additions & 4 deletions internal/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func Load() (State, error) {
return state, nil
}

func SaveManifest(manif *bootstrapper.Manifest) error {
name := manif.Version.Type.BinaryName()
func SavePackageManifest(pm *bootstrapper.PackageManifest) error {
name := pm.Version.Type.BinaryName()

log.Printf("Saving Manifest State for %s", name)

Expand All @@ -73,9 +73,9 @@ func SaveManifest(manif *bootstrapper.Manifest) error {
}

app := ApplicationState{
Version: manif.Version.GUID,
Version: pm.Version.GUID,
}
for _, pkg := range manif.Packages {
for _, pkg := range pm.Packages {
app.Packages = append(app.Packages, pkg.Checksum)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (
"golang.org/x/sync/errgroup"
)

type Manifest struct {
type PackageManifest struct {
*version.Version
DeployURL string
Packages
}

var (
ErrInvalidManifest = errors.New("invalid package manifest given")
ErrUnhandledManifestVersion = errors.New("unhandled package manifest version")
ErrInvalidPkgManifest = errors.New("invalid package manifest given")
ErrUnhandledPkgManifestVer = errors.New("unhandled package manifest version")
)

type Package struct {
Expand All @@ -44,10 +44,10 @@ func channelPath(channel string) string {
return "/channel/" + channel + "/"
}

func FetchManifest(ver *version.Version) (Manifest, error) {
func FetchPackageManifest(ver *version.Version) (PackageManifest, error) {
cdn, err := CDN()
if err != nil {
return Manifest{}, err
return PackageManifest{}, err
}
durl := cdn + channelPath(ver.Channel) + ver.GUID
url := durl + "-rbxPkgManifest.txt"
Expand All @@ -56,7 +56,7 @@ func FetchManifest(ver *version.Version) (Manifest, error) {

smanif, err := util.Body(url)
if err != nil {
return Manifest{}, fmt.Errorf("fetch %s manifest: %w", ver.GUID, err)
return PackageManifest{}, fmt.Errorf("fetch %s package manifest: %w", ver.GUID, err)
}

// Because the manifest ends with also a newline, it has to be removed.
Expand All @@ -67,10 +67,10 @@ func FetchManifest(ver *version.Version) (Manifest, error) {

pkgs, err := ParsePackages(manif)
if err != nil {
return Manifest{}, err
return PackageManifest{}, err
}

return Manifest{
return PackageManifest{
Version: ver,
DeployURL: durl,
Packages: pkgs,
Expand All @@ -81,11 +81,11 @@ func ParsePackages(manifest []string) (Packages, error) {
pkgs := make(Packages, 0)

if (len(manifest)-1)%4 != 0 {
return pkgs, ErrInvalidManifest
return pkgs, ErrInvalidPkgManifest
}

if manifest[0] != "v0" {
return pkgs, fmt.Errorf("%w: %s", ErrUnhandledManifestVersion, manifest[0])
return pkgs, fmt.Errorf("%w: %s", ErrUnhandledPkgManifestVer, manifest[0])
}

for i := 1; i <= len(manifest)-4; i += 4 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestParsePackages(t *testing.T) {
}
}

func TestInvalidPackageManifest(t *testing.T) {
func TestInvalidPackagePackageManifest(t *testing.T) {
manifest := []string{
"v0",
"foo.zip",
Expand All @@ -58,7 +58,7 @@ func TestInvalidPackageManifest(t *testing.T) {
}

_, err := ParsePackages(manifest)
if !errors.Is(err, ErrInvalidManifest) {
if !errors.Is(err, ErrInvalidPkgManifest) {
t.Fail()
}

Expand All @@ -70,7 +70,7 @@ func TestInvalidPackageManifest(t *testing.T) {
}
}

func TestUnhandledPackageManifest(t *testing.T) {
func TestUnhandledPackagePackageManifest(t *testing.T) {
manifest := []string{
"v1",
"foo.zip",
Expand All @@ -80,7 +80,7 @@ func TestUnhandledPackageManifest(t *testing.T) {
}

_, err := ParsePackages(manifest)
if !errors.Is(err, ErrUnhandledManifestVersion) {
if !errors.Is(err, ErrUnhandledPkgManifestVer) {
t.Fail()
}
}
Expand Down

0 comments on commit 1bde390

Please sign in to comment.