Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: go/src/infra/tools/cipd/client.go

Issue 1194803002: Add a package listing API to cipd. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « go/src/infra/tools/cipd/apps/cipd/main.go ('k') | go/src/infra/tools/cipd/client_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/tools/cipd/client.go
diff --git a/go/src/infra/tools/cipd/client.go b/go/src/infra/tools/cipd/client.go
index b254d35cca51a6179df93e2caa2ca306348710fd..a2cd30b1c7b1d794e594c2925d8feac2dd3f0f6a 100644
--- a/go/src/infra/tools/cipd/client.go
+++ b/go/src/infra/tools/cipd/client.go
@@ -41,6 +41,7 @@ import (
"io"
"net/http"
"os"
+ "sort"
"strings"
"time"
@@ -175,6 +176,9 @@ type Client interface {
// the site root. It doesn't check whether the instance is already deployed.
FetchAndDeployInstance(pin common.Pin) error
+ // ListPackages returns a list of strings of package names.
+ ListPackages(path string, recursive bool) ([]string, error)
+
// ProcessEnsureFile parses text file that describes what should be installed
// by EnsurePackages function. It is a text file where each line has a form:
// <package name> <desired version>. Whitespaces are ignored. Lines that start
@@ -286,6 +290,22 @@ func (client *clientImpl) ModifyACL(packagePath string, changes []PackageACLChan
return client.remote.modifyACL(packagePath, changes)
}
+func (client *clientImpl) ListPackages(path string, recursive bool) ([]string, error) {
+ pkgs, dirs, err := client.remote.listPackages(path, recursive)
+ if err != nil {
+ return nil, err
+ }
+
+ // Add trailing slash to directories.
+ for k, d := range dirs {
+ dirs[k] = d + "/"
+ }
+ // Merge and sort packages and directories.
+ allPkgs := append(pkgs, dirs...)
+ sort.Strings(allPkgs)
+ return allPkgs, nil
+}
+
func (client *clientImpl) UploadToCAS(sha1 string, data io.ReadSeeker, session *UploadSession) error {
// Open new upload session if an existing is not provided.
var err error
@@ -631,6 +651,8 @@ type remote interface {
setRef(ref string, pin common.Pin) error
attachTags(pin common.Pin, tags []string) error
fetchInstance(pin common.Pin) (*fetchInstanceResponse, error)
+
+ listPackages(path string, recursive bool) ([]string, []string, error)
}
type storage interface {
« no previous file with comments | « go/src/infra/tools/cipd/apps/cipd/main.go ('k') | go/src/infra/tools/cipd/client_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698