mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-25 18:00:30 +00:00
36e42914fa
Renamed `procs` to `steps` in code for the issue #1288 Co-authored-by: Harikesh Prajapati <harikesh.prajapati@druva.com> Co-authored-by: qwerty287 <ndev@web.de> Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
// Copyright 2021 Woodpecker Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package datastore
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
|
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
|
)
|
|
|
|
func (s storage) LogFind(step *model.Step) (io.ReadCloser, error) {
|
|
logs := &model.Logs{
|
|
StepID: step.ID,
|
|
}
|
|
if err := wrapGet(s.engine.Get(logs)); err != nil {
|
|
return nil, err
|
|
}
|
|
buf := bytes.NewBuffer(logs.Data)
|
|
return io.NopCloser(buf), nil
|
|
}
|
|
|
|
func (s storage) LogSave(step *model.Step, reader io.Reader) error {
|
|
data, _ := io.ReadAll(reader)
|
|
|
|
sess := s.engine.NewSession()
|
|
defer sess.Close()
|
|
if err := sess.Begin(); err != nil {
|
|
return err
|
|
}
|
|
|
|
logs := new(model.Logs)
|
|
exist, err := sess.Where("log_step_id = ?", step.ID).Get(logs)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if exist {
|
|
if _, err := sess.ID(logs.ID).Cols("log_data").Update(&model.Logs{Data: data}); err != nil {
|
|
return err
|
|
}
|
|
} else {
|
|
if _, err := sess.Insert(&model.Logs{
|
|
StepID: step.ID,
|
|
Data: data,
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return sess.Commit()
|
|
}
|