delete.go 696 Bytes
Newer Older
1
2
3
4
5
package directives

import (
	"errors"
	"fmt"
6
	"git.rockylinux.org/release-engineering/public/srpmproc/internal/data"
7
8
9
10
	srpmprocpb "git.rockylinux.org/release-engineering/public/srpmproc/pb"
	"github.com/go-git/go-git/v5"
)

11
func del(cfg *srpmprocpb.Cfg, _ *data.ProcessData, _ *data.ModeData, _ *git.Worktree, pushTree *git.Worktree) error {
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
	for _, del := range cfg.Delete {
		filePath := del.File
		_, err := pushTree.Filesystem.Stat(filePath)
		if err != nil {
			return errors.New(fmt.Sprintf("FILE_DOES_NOT_EXIST:%s", filePath))
		}

		err = pushTree.Filesystem.Remove(filePath)
		if err != nil {
			return errors.New(fmt.Sprintf("COULD_NOT_DELETE_FILE:%s", filePath))
		}
	}

	return nil
}