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

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
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 e6e0c8906082fe1047ef43e2245f4b5598e4e87d..cf3015ea05ad1bbcaeddf148c35999b4f0915a91 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"
@@ -167,6 +168,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
@@ -278,6 +282,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 {
Vadim Sh. 2015/06/23 00:08:35 IIUC, that's the only place where dir vs pkg matte
estaab 2015/06/23 02:26:13 Sounds fine, we show both now.
+ dirs[k] = d + "/"
+ }
+ // Merge and sort packages and directories.
+ allPkgs := append(pkgs, dirs...)
+ sort.Sort(sort.StringSlice(allPkgs))
Vadim Sh. 2015/06/23 00:08:35 sort.Strings(allPkgs)
estaab 2015/06/23 02:26:14 Done.
+ 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
@@ -596,6 +616,8 @@ type remote interface {
attachTags(pin common.Pin, tags []string) error
fetchInstance(pin common.Pin) (*fetchInstanceResponse, error)
+
+ listPackages(path string, recursive bool) ([]string, []string, error)
}
type storage interface {

Powered by Google App Engine
This is Rietveld 408576698