Beispiel #1
0
func createSnapshot(ctx *tool.Context, snapshotDir, snapshotFile, label string) error {
	// Create a snapshot that encodes the current state of master
	// branches for all local projects.
	if err := project.CreateSnapshot(ctx, snapshotFile); err != nil {
		return err
	}

	// Update the symlink for this snapshot label to point to the
	// latest snapshot.
	symlink := filepath.Join(snapshotDir, label)
	newSymlink := symlink + ".new"
	if err := ctx.Run().RemoveAll(newSymlink); err != nil {
		return err
	}
	relativeSnapshotPath := strings.TrimPrefix(snapshotFile, snapshotDir+string(os.PathSeparator))
	if err := ctx.Run().Symlink(relativeSnapshotPath, newSymlink); err != nil {
		return err
	}
	if err := ctx.Run().Rename(newSymlink, symlink); err != nil {
		return err
	}

	// Revision the changes.
	if err := revisionChanges(ctx, snapshotDir, snapshotFile, label); err != nil {
		return err
	}
	return nil
}
Beispiel #2
0
func createSnapshot(jirix *jiri.X, snapshotDir, snapshotFile, label string) error {
	// Create a snapshot that encodes the current state of master
	// branches for all local projects.
	if err := project.CreateSnapshot(jirix, snapshotFile, ""); err != nil {
		return err
	}

	s := jirix.NewSeq()
	// Update the symlink for this snapshot label to point to the
	// latest snapshot.
	symlink := filepath.Join(snapshotDir, label)
	newSymlink := symlink + ".new"
	relativeSnapshotPath := strings.TrimPrefix(snapshotFile, snapshotDir+string(os.PathSeparator))
	return s.RemoveAll(newSymlink).
		Symlink(relativeSnapshotPath, newSymlink).
		Rename(newSymlink, symlink).Done()
}
Beispiel #3
0
func runUpdate(env *cmdline.Env, _ []string) error {
	ctx := tool.NewContextFromEnv(env)

	// Create a snapshot of the current state of all projects and
	// write it to the $JIRI_ROOT/.update_history folder.
	root, err := project.JiriRoot()
	if err != nil {
		return err
	}
	snapshotFile := filepath.Join(root, ".update_history", time.Now().Format(time.RFC3339))
	if err := project.CreateSnapshot(ctx, snapshotFile); err != nil {
		return err
	}

	// Update all projects to their latest version.
	// Attempt <attemptsFlag> times before failing.
	updateFn := func() error {
		return project.UpdateUniverse(ctx, gcFlag)
	}
	return retry.Function(ctx, updateFn, retry.AttemptsOpt(attemptsFlag))
}