Exemple #1
0
func handleExport(d *Server, ctx context.Context, cmd *wire.Command) (*wire.Response, error) {
	who := cmd.GetExportCommand().Who

	// Figure out the correct store:
	var st *store.Store
	if who == "" {
		st = d.Repo.OwnStore
	} else {
		whoID, err := id.Cast(who)
		if err != nil {
			return nil, err
		}

		st, err = d.Repo.Store(whoID)
		if err != nil {
			return nil, err
		}
	}

	pbStore, err := st.Export()
	if err != nil {
		return nil, err
	}

	data, err := proto.Marshal(pbStore)
	if err != nil {
		return nil, err
	}

	return &wire.Response{
		ExportResp: &wire.Response_ExportResp{
			Data: data,
		},
	}, nil
}
Exemple #2
0
func (acl *APIClient) Fetch(s *store.Store) error {
	req := &wire.Request{
		ReqType: wire.RequestType_FETCH,
	}

	resp, err := acl.send(req)
	if err != nil {
		return err
	}

	log.Info("Got response: %v", resp.ReqType)
	protoStore := resp.GetFetchResp().GetStore()
	return s.Import(protoStore)
}
Exemple #3
0
func createDummySetup(t *testing.T, st *store.Store, data []byte) error {
	if err := st.StageFromReader("/dummy", bytes.NewReader(data), compress.AlgoNone); err != nil {
		t.Errorf("Could not add dummy file for move: %v", err)
		return err
	}

	if _, err := st.Mkdir("/dir"); err != nil {
		t.Errorf("Mkdir(/dir) failed: %v", err)
		return err
	}

	if err := st.Touch("/dir/a"); err != nil {
		t.Errorf("Touch(/dir/a) failed: %v", err)
		return err
	}

	if err := st.Touch("/dir/b"); err != nil {
		t.Errorf("Touch(/dir/b) failed: %v", err)
		return err
	}

	return nil
}