Skip to content

Commit

Permalink
fix some small issues (#17)
Browse files Browse the repository at this point in the history
* update workflow

* fix segfault in guest subcommand

* create all neccessary directories

* trivial
  • Loading branch information
yuyang0 committed May 25, 2023
1 parent a41bdd4 commit 61c2886
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ jobs:
context: .
push: true
tags: |
projecteru2/yavirt:latest
projecteru2/yavirt:${{ github.ref_name }}
${{ github.repository }}:latest
${{ github.repository }}:${{ github.ref_name }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ cscope.*
vendor/
dist/
yavirt

.vscode
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ setup:
go install github.com/vektra/mockery/v2@latest

lint: format
PATH=${HOME}/go/bin:${PATH} golangci-lint run --skip-dirs-use-default --skip-dirs=thirdparty
golangci-lint run --skip-dirs-use-default --skip-dirs=thirdparty

format: vet
gofmt -s -w $$(find . -iname '*.go' | grep -v -P '\./third_party|\./vendor/')
Expand Down
3 changes: 3 additions & 0 deletions cmd/guest/guest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import (
"github.com/urfave/cli/v2"

"github.com/projecteru2/yavirt/cmd/run"
"github.com/projecteru2/yavirt/internal/models"
)

// Command .
func Command() *cli.Command {
models.Setup()

return &cli.Command{
Name: "guest",
Subcommands: []*cli.Command{
Expand Down
15 changes: 13 additions & 2 deletions configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package configs

import (
"crypto/tls"
"os"
"path/filepath"
"time"

Expand Down Expand Up @@ -181,15 +182,25 @@ func (c *Config) load(file string) error {
return errors.Trace(err)
}

c.loadVirtDirs()
if err := c.loadVirtDirs(); err != nil {

Check warning on line 185 in configs/config.go

View workflow job for this annotation

GitHub Actions / lint

if-return: redundant if ...; err != nil check, just return error instead. (revive)
return err
}

return nil
}

func (c *Config) loadVirtDirs() {
func (c *Config) loadVirtDirs() error {
c.VirtFlockDir = filepath.Join(c.VirtDir, "flock")
c.VirtTmplDir = filepath.Join(c.VirtDir, "template")
c.VirtSockDir = filepath.Join(c.VirtDir, "sock")
// ensure directories
for _, d := range []string{c.VirtFlockDir, c.VirtTmplDir, c.VirtSockDir} {
err := os.MkdirAll(d, 0755)
if err != nil && !os.IsExist(err) {
return err
}
}
return nil
}

// NewEtcdConfig .
Expand Down
6 changes: 0 additions & 6 deletions internal/virt/virt.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import (

// Cleanup cleans flocks up.
func Cleanup() error {
// ensure flock dir
err := os.Mkdir(configs.Conf.VirtFlockDir, 0755)
if err != nil && !os.IsExist(err) {
return err
}

files, err := os.ReadDir(configs.Conf.VirtFlockDir)
if err != nil {
return errors.Trace(err)
Expand Down
10 changes: 8 additions & 2 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package log
import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/getsentry/sentry-go"
Expand Down Expand Up @@ -46,8 +47,13 @@ func setupOutput(file string) error {
if len(file) < 1 {
return nil
}

var f, err = os.OpenFile(file, os.O_APPEND|os.O_CREATE|os.O_RDWR, os.ModePerm)
// make dir if necessary
err := os.MkdirAll(filepath.Dir(file), 0755)
if err != nil && !os.IsExist(err) {
return err
}
// open file for logger
f, err := os.OpenFile(file, os.O_APPEND|os.O_CREATE|os.O_RDWR, os.ModePerm)
if err != nil {
return errors.Trace(err)
}
Expand Down

0 comments on commit 61c2886

Please sign in to comment.