Skip to content

Commit

Permalink
convert/gem/ruby: Don't overwrite existing melange files
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Vreeland committed Dec 11, 2024
1 parent b5d4d74 commit 5deed14
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 9 additions & 1 deletion pkg/convert/gem/gem.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -169,7 +171,13 @@ func (c *GemContext) findDependencies(ctx context.Context) error {
return err
}
log.Infof("[%s] Add to generate list", c.ToCheck[0])
c.ToGenerate[c.ToCheck[0]] = g
// This should be ruby3 once the files are multi-versioned
_, err = os.Stat(filepath.Join(c.OutDir, "ruby"+DefaultRubyVersion+"-"+g.Name+".yaml"))
if err == nil {
log.Infof("[%s] Package already exists, skipping", g.Name)
} else {
c.ToGenerate[c.ToCheck[0]] = g
}
c.ToCheck = c.ToCheck[1:]

log.Infof("[%s] Check for dependencies", g.Name)
Expand Down
12 changes: 11 additions & 1 deletion pkg/convert/gem/gem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,28 @@ func TestFindDependencies(t *testing.T) {
gemctx := testGemContext(server.URL + "/%s.json")
gemctx.ToCheck = []string{"async"}

// Verify that if the file exists the dependecy isn't created
_, _ = os.OpenFile("ruby"+DefaultRubyVersion+"-timers.yaml", os.O_RDONLY|os.O_CREATE, 0666)

// Build list of dependencies
err = gemctx.findDependencies(slogtest.Context(t))
assert.NoError(t, err)

for _, gem := range gems {
gemName := strings.TrimSuffix(gem.Name(), ".json")
_, ok := gemctx.ToGenerate[gemName]
assert.True(t, ok)

if gemName == "timers" {
assert.False(t, ok)
} else {
assert.True(t, ok)
}

// Remove dependency from the list
delete(gemctx.ToGenerate, gemName)
}
os.Remove("ruby" + DefaultRubyVersion + "-timers.yaml")

// The dependency list should be empty
assert.Empty(t, gemctx.ToGenerate)
}
Expand Down

0 comments on commit 5deed14

Please sign in to comment.