Skip to content

Commit

Permalink
Don't create files in /etc/iproute2 out of thin air
Browse files Browse the repository at this point in the history
  • Loading branch information
Infinoid committed May 21, 2024
1 parent 1f3a281 commit 7cd1773
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions pkg/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"syscall"

"cunicu.li/gont/v2/internal/execvpe"
"cunicu.li/gont/v2/internal/utils"
"golang.org/x/sys/unix"
)

Expand Down Expand Up @@ -122,30 +121,14 @@ func setupBindMounts(basePath string) error {
src := filepath.Join(filesRootPath, path)
tgt := filepath.Join("/", path)

srcInfo, err := os.Stat(src)
_, err := os.Stat(src)

Check warning on line 124 in pkg/exec.go

View check run for this annotation

Codecov / codecov/patch

pkg/exec.go#L124

Added line #L124 was not covered by tests
if err != nil {
return fmt.Errorf("failed to stat source: %s: %w", src, err)
}

// Create non-existing targets
// If target doesn't exist, there's nothing to mount
if _, err := os.Stat(tgt); errors.Is(err, os.ErrNotExist) { //nolint:nestif

Check failure on line 130 in pkg/exec.go

View workflow job for this annotation

GitHub Actions / lint

directive `//nolint:nestif` is unused for linter "nestif" (nolintlint)
var tgtDir string
if srcInfo.IsDir() {
tgtDir = tgt
} else {
tgtDir = filepath.Dir(tgt)
}

// Create target if it does not exist yet
if srcInfo.IsDir() {
if err := os.MkdirAll(tgtDir, 0o755); err != nil {
return fmt.Errorf("failed to create directory: %s: %w", path, err)
}
} else {
if err := utils.Touch(tgt); err != nil {
return fmt.Errorf("failed to create empty file: %s: %w", tgt, err)
}
}
continue

Check warning on line 131 in pkg/exec.go

View check run for this annotation

Codecov / codecov/patch

pkg/exec.go#L131

Added line #L131 was not covered by tests
}

if err := syscall.Mount(src, tgt, "", syscall.MS_BIND, ""); err != nil {
Expand Down

0 comments on commit 7cd1773

Please sign in to comment.