Skip to content

Commit

Permalink
back off changes till fiexed
Browse files Browse the repository at this point in the history
  • Loading branch information
taylormonacelli committed Jul 25, 2024
1 parent 4348d06 commit a38a7d6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 110 deletions.
45 changes: 29 additions & 16 deletions core/file.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !windows
// +build !windows

package core

import (
Expand All @@ -10,25 +7,41 @@ import (
"fmt"
"io"
"os"
"runtime"
"syscall"

"github.com/go-logr/logr"
)

func lockFile(f *os.File) error {
err := syscall.Flock(int(f.Fd()), syscall.LOCK_EX)
if err != nil {
return fmt.Errorf("failed to lock file: %w", err)
}
return nil
}
var (
lockFile func(*os.File) error
unlockFile func(*os.File) error
)

func unlockFile(f *os.File) error {
err := syscall.Flock(int(f.Fd()), syscall.LOCK_UN)
if err != nil {
return fmt.Errorf("failed to unlock file: %w", err)
func init() {
if runtime.GOOS == "windows" {
lockFile = func(f *os.File) error {
return nil
}
unlockFile = func(f *os.File) error {
return nil
}
} else {
lockFile = func(f *os.File) error {
err := syscall.Flock(int(f.Fd()), syscall.LOCK_EX)

Check failure on line 31 in core/file.go

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

undefined: syscall.Flock

Check failure on line 31 in core/file.go

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

undefined: syscall.LOCK_EX
if err != nil {
return fmt.Errorf("failed to lock file: %w", err)
}
return nil
}
unlockFile = func(f *os.File) error {
err := syscall.Flock(int(f.Fd()), syscall.LOCK_UN)

Check failure on line 38 in core/file.go

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

undefined: syscall.Flock

Check failure on line 38 in core/file.go

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

undefined: syscall.LOCK_UN
if err != nil {
return fmt.Errorf("failed to unlock file: %w", err)
}
return nil
}
}
return nil
}

func ProcessFile(ctx context.Context, path string, transform func(io.Reader, io.Writer) error) error {
Expand Down Expand Up @@ -75,7 +88,7 @@ func ProcessFile(ctx context.Context, path string, transform func(io.Reader, io.

err = originalFile.Sync()
if err != nil {
return fmt.Errorf("failed to sync file: %w", err)
return fmt.Errorf("failed to s.V(1)ync file: %w", err)
}

logger.V(1).Info("Successfully processed and updated file")
Expand Down
94 changes: 0 additions & 94 deletions core/file_windows.go

This file was deleted.

0 comments on commit a38a7d6

Please sign in to comment.