4c321a089d
- serve sparse index and config.json for local cargo repos from a cargo_index table - add Web API publish, yank and unyank under the local repo api root - drop index lines when the crate file is deleted
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
package database
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"git.unkin.net/unkin/artifactapi/internal/provider"
|
|
)
|
|
|
|
func (db *DB) InsertCargoIndexEntry(ctx context.Context, e *provider.CargoIndexEntry) error {
|
|
_, err := db.Pool.Exec(ctx, `
|
|
INSERT INTO cargo_index (repo_name, file_path, name, version, line, yanked)
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
`, e.RepoName, e.FilePath, e.Name, e.Version, e.Line, e.Yanked)
|
|
return err
|
|
}
|
|
|
|
func (db *DB) ListCargoIndexEntries(ctx context.Context, repoName, name string) ([]provider.CargoIndexEntry, error) {
|
|
rows, err := db.Pool.Query(ctx, `
|
|
SELECT repo_name, file_path, name, version, line, yanked
|
|
FROM cargo_index
|
|
WHERE repo_name = $1 AND lower(name) = $2
|
|
ORDER BY id
|
|
`, repoName, strings.ToLower(name))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
|
|
var result []provider.CargoIndexEntry
|
|
for rows.Next() {
|
|
var e provider.CargoIndexEntry
|
|
if err := rows.Scan(&e.RepoName, &e.FilePath, &e.Name, &e.Version, &e.Line, &e.Yanked); err != nil {
|
|
return nil, err
|
|
}
|
|
result = append(result, e)
|
|
}
|
|
return result, rows.Err()
|
|
}
|
|
|
|
// SetCargoYanked reports false when no such crate version exists.
|
|
func (db *DB) SetCargoYanked(ctx context.Context, repoName, name, version string, yanked bool) (bool, error) {
|
|
tag, err := db.Pool.Exec(ctx, `
|
|
UPDATE cargo_index SET yanked = $4
|
|
WHERE repo_name = $1 AND lower(name) = $2 AND version = $3
|
|
`, repoName, strings.ToLower(name), version, yanked)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return tag.RowsAffected() > 0, nil
|
|
}
|
|
|
|
func (db *DB) DeleteCargoIndexEntry(ctx context.Context, repoName, filePath string) error {
|
|
_, err := db.Pool.Exec(ctx, `DELETE FROM cargo_index WHERE repo_name = $1 AND file_path = $2`, repoName, filePath)
|
|
return err
|
|
}
|