Skip to content

Commit

Permalink
readd usage of takID and secure deleetion
Browse files Browse the repository at this point in the history
  • Loading branch information
Equanox committed Apr 1, 2023
1 parent c170e2f commit 20c5319
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions bob/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (b *B) Build(ctx context.Context, taskName string) (err error) {
return nil
}

// AggregateWithNixDeps does aggregation together with evaluation nix dependecies which
// are altering a tasks input hash.
// AggregateWithNixDeps does aggregation together with evaluating nix dependecies.
// Nic dependencies are altering a tasks input hash.
// Use this function for building `bob inspect` cmds.
func (b *B) AggregateWithNixDeps(taskName string) (aggregate *bobfile.Bobfile, err error) {
defer errz.Recover(&err)
Expand Down
2 changes: 1 addition & 1 deletion bob/playbook/build_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (p *Playbook) build(ctx context.Context, task *bobtask.Task) (pt *processed
}
}()

rebuild, err := p.TaskNeedsRebuild(task.Name())
rebuild, err := p.TaskNeedsRebuild(task.TaskID)
errz.Fatal(err)
boblog.Log.V(2).Info(fmt.Sprintf("TaskNeedsRebuild [rebuildRequired: %t] [cause:%s]", rebuild.IsRequired, rebuild.Cause))

Expand Down
16 changes: 5 additions & 11 deletions bob/playbook/rebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import (

"github.com/benchkram/bob/bobtask"
"github.com/benchkram/bob/bobtask/target"
"github.com/benchkram/bob/pkg/boberror"
"github.com/benchkram/bob/pkg/boblog"
"github.com/benchkram/bob/pkg/usererror"
"github.com/benchkram/errz"
)

Expand All @@ -24,12 +22,8 @@ type RebuildInfo struct {

// TaskNeedsRebuild check if a tasks need a rebuild by looking at its hash value
// and its child tasks.
func (p *Playbook) TaskNeedsRebuild(taskName string) (rebuildInfo RebuildInfo, err error) {
ts, ok := p.Tasks[taskName]
if !ok {
return RebuildInfo{}, usererror.Wrap(boberror.ErrTaskDoesNotExistF(taskName))
}
task := ts.Task
func (p *Playbook) TaskNeedsRebuild(taskID int) (rebuildInfo RebuildInfo, err error) {
task := p.TasksOptimized[taskID]
coloredName := task.ColoredName()

// Rebuild strategy set to `always`
Expand All @@ -39,7 +33,7 @@ func (p *Playbook) TaskNeedsRebuild(taskName string) (rebuildInfo RebuildInfo, e
// For a forced rebuild all task targets are marked as invalid
invalidFiles := make(map[string][]target.Reason)
if task.TargetExists() {
t, err := ts.Target()
t, err := task.Target()
errz.Fatal(err)
invalidFiles = t.AsInvalidFiles(target.ReasonForcedByNoCache)
}
Expand All @@ -60,7 +54,7 @@ func (p *Playbook) TaskNeedsRebuild(taskName string) (rebuildInfo RebuildInfo, e
// I'm unsure about the reason for it.
verifyResult := target.NewVerifyResult()
if task.TargetExists() {
tt, err := ts.Target()
tt, err := task.Target()
errz.Fatal(err)
verifyResult = tt.VerifyShallow()
if !verifyResult.TargetIsValid {
Expand All @@ -81,7 +75,7 @@ func (p *Playbook) TaskNeedsRebuild(taskName string) (rebuildInfo RebuildInfo, e

invalidFiles := make(map[string][]target.Reason)
if task.TargetExists() {
t, err := ts.Target()
t, err := task.Target()
errz.Fatal(err)
invalidFiles = t.AsInvalidFiles(target.ReasonMissing)
}
Expand Down
9 changes: 8 additions & 1 deletion bobtask/artifact_extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
func (t *Task) ArtifactExtract(artifactName hash.In, invalidFiles map[string][]target.Reason) (success bool, err error) {
defer errz.Recover(&err)

homeDir, err := os.UserHomeDir()
errz.Fatal(err)

artifact, _, err := t.local.GetArtifact(context.TODO(), artifactName.String())
if err != nil {
_, ok := err.(*fs.PathError)
Expand Down Expand Up @@ -70,7 +73,11 @@ func (t *Task) ArtifactExtract(artifactName hash.In, invalidFiles map[string][]t

// symlink
if archiveFile.FileInfo.Mode()&os.ModeSymlink == os.ModeSymlink {
os.RemoveAll(dst)
if dst == "/" || dst == homeDir {
return false, fmt.Errorf("Cleanup of %s is not allowed", dst)
}
err = os.RemoveAll(dst)
errz.Fatal(err)
err = os.Symlink(header.Linkname, dst)
errz.Fatal(err)
continue
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var _ = Describe("Test bob build", func() {
Expect(err).NotTo(HaveOccurred())

task := pb.Tasks[targetTask]
rebuild, err := pb.TaskNeedsRebuild(task.Name())
rebuild, err := pb.TaskNeedsRebuild(task.TaskID)
Expect(err).NotTo(HaveOccurred())

Expect(rebuild.IsRequired).To(BeTrue())
Expand Down

0 comments on commit 20c5319

Please sign in to comment.