Skip to content

Commit

Permalink
Corrected the name of the version field when reading ..latest.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Oct 28, 2024
1 parent 4c905de commit 950aba9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
11 changes: 7 additions & 4 deletions ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import (
)

type latestPayload struct {
Latest string `json:"latest"`
Version string `json:"version"`
}

func readLatestFile(lat_path string) (latestPayload, error) {
output := latestPayload{}

handle, err := os.Open(lat_path)
if _, err := os.Stat(lat_path); errors.Is(err, os.ErrNotExist) {
return output, nil
}

handle, err := os.Open(lat_path)
if err != nil {
return output, fmt.Errorf("failed to open %q; %w", lat_path, err)
}
defer handle.Close()

dec := json.NewDecoder(handle)
Expand Down Expand Up @@ -55,7 +58,7 @@ func ignoreNonLatest(registry, project, asset string) (bool, error) {
ipath := filepath.Join(asset_dir, v, ".SewerRatignore")
_, err := os.Stat(ipath)

if v == payload.Latest {
if v == payload.Version {
if !errors.Is(err, os.ErrNotExist) {
changed = true
err := os.Remove(ipath)
Expand Down
10 changes: 5 additions & 5 deletions ignore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ func TestReadLatestFile(t *testing.T) {
if err != nil {
t.Fatalf("failed to read the ..latest file; %v", err)
}
if latest.Latest != "" {
if latest.Version != "" {
t.Fatalf("..latest file should be absent; %v", err)
}

err = os.WriteFile(lat_path, []byte("{ \"latest\": \"foobar\" }"), 0644)
err = os.WriteFile(lat_path, []byte("{ \"version\": \"foobar\" }"), 0644)
if err != nil {
t.Fatalf("failed to write to the ..latest file; %v", err)
}
Expand All @@ -31,7 +31,7 @@ func TestReadLatestFile(t *testing.T) {
if err != nil {
t.Fatalf("failed to read the ..latest file; %v", err)
}
if latest.Latest != "foobar" {
if latest.Version != "foobar" {
t.Fatalf("unexpected latest version %q", latest)
}
}
Expand All @@ -57,7 +57,7 @@ func TestIgnoreNonLatest(t *testing.T) {
}

lat_path := filepath.Join(asset_dir, "..latest")
err = os.WriteFile(lat_path, []byte("{ \"latest\": \"3\" }"), 0644)
err = os.WriteFile(lat_path, []byte("{ \"version\": \"3\" }"), 0644)
if err != nil {
t.Fatalf("failed to write to the ..latest file; %v", err)
}
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestIgnoreNonLatest(t *testing.T) {
}
})

err = os.WriteFile(lat_path, []byte("{ \"latest\": \"1\" }"), 0644)
err = os.WriteFile(lat_path, []byte("{ \"version\": \"1\" }"), 0644)
if err != nil {
t.Fatalf("failed to update the ..latest file; %v", err)
}
Expand Down

0 comments on commit 950aba9

Please sign in to comment.