Skip to content

Commit

Permalink
Add clamd address as input for clamdexecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
filariow committed Aug 9, 2022
1 parent 8e6a9d1 commit 4d18e94
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func main() {
log.Fatal(err)
}

c := execute.NewClamdExecutor(f, e.Visited(), 1)
c := execute.NewClamdExecutor("unix:///var/run/clamav/clamd.ctl", f, e.Visited(), 8)
c.Execute()

b := progressbar.NewOptions64(
Expand Down
46 changes: 33 additions & 13 deletions pkg/execute/clamd_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import (
"log"
"os"
"path"
"strings"
"sync"
"sync/atomic"

"github.com/baruwa-enterprise/clamd"
)

var ErrInvalidClamdAddress = fmt.Errorf("Invalid clamd address")

type clamdExecutor struct {
folder string
source <-chan string
Expand All @@ -21,27 +24,44 @@ type clamdExecutor struct {
done chan struct{}
concurrency int

workers chan struct{}
found chan string
clamdClient *clamd.Client
workers chan struct{}
found chan string

clamdAddress string
clamdClient *clamd.Client
}

func NewClamdExecutor(folder string, source <-chan string, t int) Executor {
func NewClamdExecutor(address string, folder string, source <-chan string, t int) Executor {
e := &clamdExecutor{
folder: folder,
source: source,
started: 0,
terminated: 0,
done: make(chan struct{}),
concurrency: t,
workers: make(chan struct{}, t),
found: make(chan string),
folder: folder,
source: source,
started: 0,
terminated: 0,
done: make(chan struct{}),
concurrency: t,
workers: make(chan struct{}, t),
found: make(chan string),
clamdAddress: address,
}
return e
}

func (l *clamdExecutor) parseAddress() (string, string, error) {
ss := strings.Split(l.clamdAddress, "://")
if len(ss) != 2 {
return "", "", ErrInvalidClamdAddress
}

return ss[0], ss[1], nil
}

func (l *clamdExecutor) Execute() error {
c, err := clamd.NewClient("unix", "/var/run/clamav/clamd.ctl")
h, a, err := l.parseAddress()
if err != nil {
return fmt.Errorf("error parsing address '%v': %w", l.clamdAddress, err)
}

c, err := clamd.NewClient(h, a)
if err != nil {
return err
}
Expand Down

0 comments on commit 4d18e94

Please sign in to comment.