func (c *UpCmd) Run(args ...string) (err error) { var mod *model.Model if mod, err = model.New(c.WD, c.UseGit, c.ChunkSize, c.PoolSize); err != nil { return } feed := lists.NewFileList(args...).ListDir(c.WD) isDirty, dirty, err := mod.Check(feed...) if err != nil { return } if isDirty { err = fmt.Errorf("dirty files in working tree %s", dirty) return } if c.UseGit { // filter by attrs feed, err = mod.Git.FilterByAttr("bar", feed...) } blobs, err := mod.FeedManifests(true, false, true, feed...) if err != nil { return } logx.Debugf("collected blobs %s", blobs.IDMap()) trans := transport.NewTransport(mod, "", c.Endpoint, c.PoolSize) err = trans.Upload(blobs) if err != nil { return } if c.Squash { if err = mod.SquashBlobs(blobs); err != nil { return } if c.UseGit { err = mod.Git.UpdateIndex(blobs.Names()...) } } return }
func (c *SpecExportCmd) Run(args ...string) (err error) { var mod *model.Model if mod, err = model.New(c.WD, c.UseGit, c.ChunkSize, c.PoolSize); err != nil { return } feed := lists.NewFileList(args...).ListDir(c.WD) isDirty, dirty, err := mod.Check(feed...) if err != nil { return } if isDirty { err = fmt.Errorf("dirty files in working tree %s", dirty) return } if c.UseGit { // filter by attrs feed, err = mod.Git.FilterByAttr("bar", feed...) } blobs, err := mod.FeedManifests(true, true, true, feed...) if err != nil { return } // make specmap nameMap := map[string]proto.ID{} for name, m := range blobs { nameMap[name] = m.ID } spec, err := proto.NewSpec(time.Now().UnixNano(), nameMap, []string{}) if err != nil { return } if c.DoCC { ccName := fmt.Sprintf("bar-spec-%d-%s.json", time.Now().UnixNano(), spec.ID) logx.Infof("storing carbon copy to %s", ccName) ccf, err := os.Create(lists.OSFromSlash(lists.OSJoin(c.WD, ccName))) if err != nil { return err } defer ccf.Close() if err = json.NewEncoder(ccf).Encode(&spec); err != nil { return err } } if !c.Upload { err = json.NewEncoder(c.Stdout).Encode(&spec) return } trans := transport.NewTransport(mod, "", c.Endpoint, c.PoolSize) if err = trans.UploadSpec(spec); err != nil { return } fmt.Fprint(c.Stdout, spec.ID) return }