[pm] newrepo produces a fully ready repository
newrepo was only preparing staged repository data, which meant that after a
newrepo invocation the repository was not in a "servable" state. Newrepo now
commits the empty target set, to ensure that a newly formed repository is
entirely servable.
This change also updates the flags somewhat to unify between `pm newrepo` and
`pm publish`, but retains support for the old flags. In the case where a user
supplies both the `-repo` and the `-r` flag to publish, the last flag in argv
wins.
Bug: DX-972 #done
Change-Id: Ib15ae26d5a5cb3480e24d8e7fecdd2966189b9cd
diff --git a/garnet/go/src/pm/cmd/pm/newrepo/newrepo.go b/garnet/go/src/pm/cmd/pm/newrepo/newrepo.go
index b72c1e7..49c776d 100644
--- a/garnet/go/src/pm/cmd/pm/newrepo/newrepo.go
+++ b/garnet/go/src/pm/cmd/pm/newrepo/newrepo.go
@@ -6,6 +6,7 @@
package newrepo
import (
+ "encoding/json"
"flag"
"fmt"
"os"
@@ -46,5 +47,17 @@
return err
}
- return r.GenKeys()
+ if err := r.GenKeys(); err != nil {
+ return err
+ }
+
+ if err := r.Repo.AddTargets([]string{}, json.RawMessage{}); err != nil {
+ return err
+ }
+
+ if err := r.CommitUpdates(config.TimeVersioned); err != nil {
+ return err
+ }
+
+ return nil
}
diff --git a/garnet/go/src/pm/cmd/pm/publish/publish.go b/garnet/go/src/pm/cmd/pm/publish/publish.go
index 414f3c1..332e687 100644
--- a/garnet/go/src/pm/cmd/pm/publish/publish.go
+++ b/garnet/go/src/pm/cmd/pm/publish/publish.go
@@ -22,7 +22,7 @@
)
const (
- usage = `Usage: %s publish (-a|-bs|-ps) -C -f file [-r <repo_path>]
+ usage = `Usage: %s publish (-a|-bs|-ps) -C -f file [-repo <repository directory>]
Pass any one of the mode flags (-a|-bs|-ps), and at least one file to pubish.
`
serverBase = "amber-files"
@@ -53,12 +53,10 @@
blobSetMode := fs.Bool("bs", false, "(mode) Publish a set of blobs from a manifest.")
modeFlags := []*bool{archiveMode, packageSetMode, blobSetMode}
- // TODO(raggi): cleanup args...
config := &repo.Config{}
- //config.Vars(fs)
- fs.StringVar(&config.RepoDir, "r", "", "Path to the TUF repository directory.")
+ config.Vars(fs)
+ fs.StringVar(&config.RepoDir, "r", "", "(deprecated, alias for -repo).")
verbose := fs.Bool("v", false, "Print out more informational messages.")
- verTime := fs.Bool("vt", false, "Set repo versioning based on time rather than a monotonic increment")
filePaths := RepeatedArg{}
fs.Var(&filePaths, "f", "Path(s) of the file(s) to publish")
@@ -199,7 +197,7 @@
return err
}
}
- if err := repo.CommitUpdates(*verTime); err != nil {
+ if err := repo.CommitUpdates(config.TimeVersioned); err != nil {
log.Fatalf("error committing repository updates: %s", err)
}
@@ -222,7 +220,7 @@
return err
}
- if err := repo.CommitUpdates(*verTime); err != nil {
+ if err := repo.CommitUpdates(config.TimeVersioned); err != nil {
log.Fatalf("error committing repository updates: %s", err)
}
diff --git a/garnet/go/src/pm/repo/config.go b/garnet/go/src/pm/repo/config.go
index 90c66819..181312c 100644
--- a/garnet/go/src/pm/repo/config.go
+++ b/garnet/go/src/pm/repo/config.go
@@ -31,11 +31,13 @@
// Config contains a common runtime configuration for repository manipulations.
type Config struct {
- RepoDir string
+ RepoDir string
+ TimeVersioned bool
}
func (c *Config) Vars(fs *flag.FlagSet) {
fs.StringVar(&c.RepoDir, "repo", "", "path to repostory directory")
+ fs.BoolVar(&c.TimeVersioned, "vt", false, "Set repo versioning based on time rather than a monotonic increment")
}
func (c *Config) ApplyDefaults() {
diff --git a/garnet/go/src/pm/repo/repo.go b/garnet/go/src/pm/repo/repo.go
index 1706222..5d8d180 100644
--- a/garnet/go/src/pm/repo/repo.go
+++ b/garnet/go/src/pm/repo/repo.go
@@ -76,7 +76,11 @@
}
// Fuchsia repositories always use consistent snapshots.
- return r.Repo.Init(true)
+ if err := r.Repo.Init(true); err != nil {
+ return err
+ }
+
+ return nil
}
// GenKeys will generate a full suite of the necessary keys for signing a