Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions kcontext/kcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,9 @@ type KContext struct {
Stdout io.Writer `msgpack:"-"`
Stderr io.Writer `msgpack:"-"`

Username string
Hostname string
CommandLine string
MachineID string
KeyFromFile string
CacheDir string

OperatingSystem string
Architecture string
ProcessID int

Client string

CWD string
MaxConcurrency int

Expand Down
181 changes: 0 additions & 181 deletions kcontext/kcontext_test.go

This file was deleted.

51 changes: 31 additions & 20 deletions snapshot/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@ type Builder struct {
Header *header.Header
}

func Create(repo *repository.Repository, packingStrategy repository.RepositoryType) (*Builder, error) {
type BuilderOptions struct {
Username string
Hostname string
CommandLine string
MachineID string
OperatingSystem string
Architecture string
Client string
ProcessID int
}

func Create(repo *repository.Repository, packingStrategy repository.RepositoryType, opts *BuilderOptions) (*Builder, error) {
identifier := objects.RandomMAC()
scanCache, err := repo.AppContext().GetCache().Scan(identifier)
if err != nil {
Expand All @@ -49,22 +60,22 @@ func Create(repo *repository.Repository, packingStrategy repository.RepositoryTy
snap.Header.Identity.Identifier = snap.AppContext().Identity
snap.Header.Identity.PublicKey = snap.AppContext().Keypair.PublicKey
}
snap.Header.SetContext("Hostname", snap.AppContext().Hostname)
snap.Header.SetContext("Username", snap.AppContext().Username)
snap.Header.SetContext("OperatingSystem", snap.AppContext().OperatingSystem)
snap.Header.SetContext("MachineID", snap.AppContext().MachineID)
snap.Header.SetContext("CommandLine", snap.AppContext().CommandLine)
snap.Header.SetContext("ProcessID", fmt.Sprintf("%d", snap.AppContext().ProcessID))
snap.Header.SetContext("Architecture", snap.AppContext().Architecture)
snap.Header.SetContext("Hostname", opts.Hostname)
snap.Header.SetContext("Username", opts.Username)
snap.Header.SetContext("OperatingSystem", opts.OperatingSystem)
snap.Header.SetContext("MachineID", opts.MachineID)
snap.Header.SetContext("CommandLine", opts.CommandLine)
snap.Header.SetContext("ProcessID", fmt.Sprintf("%d", opts.ProcessID))
snap.Header.SetContext("Architecture", opts.Architecture)
snap.Header.SetContext("NumCPU", fmt.Sprintf("%d", runtime.NumCPU()))
snap.Header.SetContext("MaxProcs", fmt.Sprintf("%d", runtime.GOMAXPROCS(0)))
snap.Header.SetContext("Client", snap.AppContext().Client)
snap.Header.SetContext("Client", opts.Client)

repo.Logger().Trace("snapshot", "%x: Create()", snap.Header.GetIndexShortID())
return snap, nil
}

func CreateWithRepositoryWriter(repo *repository.RepositoryWriter) (*Builder, error) {
func CreateWithRepositoryWriter(repo *repository.RepositoryWriter, opts *BuilderOptions) (*Builder, error) {
identifier := objects.RandomMAC()
scanCache, err := repo.AppContext().GetCache().Scan(identifier)
if err != nil {
Expand All @@ -84,16 +95,16 @@ func CreateWithRepositoryWriter(repo *repository.RepositoryWriter) (*Builder, er
snap.Header.Identity.PublicKey = snap.AppContext().Keypair.PublicKey
}

snap.Header.SetContext("Hostname", snap.AppContext().Hostname)
snap.Header.SetContext("Username", snap.AppContext().Username)
snap.Header.SetContext("OperatingSystem", snap.AppContext().OperatingSystem)
snap.Header.SetContext("MachineID", snap.AppContext().MachineID)
snap.Header.SetContext("CommandLine", snap.AppContext().CommandLine)
snap.Header.SetContext("ProcessID", fmt.Sprintf("%d", snap.AppContext().ProcessID))
snap.Header.SetContext("Architecture", snap.AppContext().Architecture)
snap.Header.SetContext("Hostname", opts.Hostname)
snap.Header.SetContext("Username", opts.Username)
snap.Header.SetContext("OperatingSystem", opts.OperatingSystem)
snap.Header.SetContext("MachineID", opts.MachineID)
snap.Header.SetContext("CommandLine", opts.CommandLine)
snap.Header.SetContext("ProcessID", fmt.Sprintf("%d", opts.ProcessID))
snap.Header.SetContext("Architecture", opts.Architecture)
snap.Header.SetContext("NumCPU", fmt.Sprintf("%d", runtime.NumCPU()))
snap.Header.SetContext("MaxProcs", fmt.Sprintf("%d", runtime.GOMAXPROCS(0)))
snap.Header.SetContext("Client", snap.AppContext().Client)
snap.Header.SetContext("Client", opts.Client)

repo.Logger().Trace("snapshot", "%x: Create()", snap.Header.GetIndexShortID())
return snap, nil
Expand Down Expand Up @@ -132,7 +143,7 @@ func (snap *Builder) Lock() (chan bool, error) {
return lockDone, nil
}

lock := repository.NewSharedLock(snap.AppContext().Hostname)
lock := repository.NewSharedLock(snap.Header.GetContext("Hostname"))

buffer := &bytes.Buffer{}
err := lock.SerializeToStream(buffer)
Expand Down Expand Up @@ -195,7 +206,7 @@ func (snap *Builder) Lock() (chan bool, error) {
snap.repository.DeleteLock(snap.Header.Identifier)
return
case <-time.After(repository.LOCK_REFRESH_RATE):
lock := repository.NewSharedLock(snap.AppContext().Hostname)
lock := repository.NewSharedLock(snap.Header.GetContext("Hostname"))

buffer := &bytes.Buffer{}

Expand Down
2 changes: 0 additions & 2 deletions testing/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ func GenerateContext(t *testing.T, bufout *bytes.Buffer, buferr *bytes.Buffer) *

ctx := kcontext.NewKContext()

ctx.Client = "plakar-test/1.0.0"

// create a repository
ctx.MaxConcurrency = 1
if bufout != nil && buferr != nil {
Expand Down
3 changes: 0 additions & 3 deletions testing/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ func GenerateRepository(t *testing.T, bufout *bytes.Buffer, buferr *bytes.Buffer

ctx := kcontext.NewKContext()

ctx.Client = "plakar-test/1.0.0"

// create a storage

r, err := storage.New(ctx, map[string]string{"location": "mock://" + tmpRepoDir})
require.NotNil(t, r)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion testing/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func GenerateSnapshot(t *testing.T, repo *repository.Repository, files []MockFil
}

// create a snapshot
builder, err := snapshot.Create(repo, repository.DefaultType)
builder, err := snapshot.Create(repo, repository.DefaultType, &snapshot.BuilderOptions{})
require.NoError(t, err)
require.NotNil(t, builder)

Expand Down
Loading