Skip to content

Commit

Permalink
Merge pull request #1016 from wakatime/bugfix/win-no-lock
Browse files Browse the repository at this point in the history
Use custom os.Open fork to prevent locking on Windows
  • Loading branch information
alanhamlett authored Jan 18, 2024
2 parents 9154f1f + 7e6761e commit f108814
Show file tree
Hide file tree
Showing 27 changed files with 392 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ run:
- integration
skip-dirs:
- "testdata"
skip-files:
- pkg/file/file_windows.go
linters:
enable:
- bodyclose
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/c.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package deps
import (
"fmt"
"io"
"os"
"regexp"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/log"

Expand Down Expand Up @@ -35,7 +35,7 @@ type ParserC struct {

// Parse parses dependencies from C file content using the C lexer.
func (p *ParserC) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/cpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package deps
import (
"fmt"
"io"
"os"
"regexp"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/log"

Expand Down Expand Up @@ -35,7 +35,7 @@ type ParserCPP struct {

// Parse parses dependencies from C++ file content using the C lexer.
func (p *ParserCPP) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/csharp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package deps
import (
"fmt"
"io"
"os"
"regexp"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/log"

Expand Down Expand Up @@ -36,7 +36,7 @@ type ParserCSharp struct {

// Parse parses dependencies from C# file content using the chroma C# lexer.
func (p *ParserCSharp) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/elm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package deps
import (
"fmt"
"io"
"os"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/log"

Expand All @@ -32,7 +32,7 @@ type ParserElm struct {

// Parse parses dependencies from Elm file content using the chroma Elm lexer.
func (p *ParserElm) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package deps
import (
"fmt"
"io"
"os"
"regexp"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/log"

"github.com/alecthomas/chroma/v2"
Expand Down Expand Up @@ -35,7 +35,7 @@ type ParserGo struct {

// Parse parses dependencies from Golang file content using the chroma Golang lexer.
func (p *ParserGo) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/haskell.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package deps
import (
"fmt"
"io"
"os"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/log"

Expand All @@ -32,7 +32,7 @@ type ParserHaskell struct {

// Parse parses dependencies from Haskell file content using the chroma Haskell lexer.
func (p *ParserHaskell) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/haxe.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package deps
import (
"fmt"
"io"
"os"
"regexp"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/log"

"github.com/alecthomas/chroma/v2"
Expand Down Expand Up @@ -34,7 +34,7 @@ type ParserHaxe struct {

// Parse parses dependencies from Haxe file content using the chroma Haxe lexer.
func (p *ParserHaxe) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package deps
import (
"fmt"
"io"
"os"
"regexp"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/log"

"github.com/alecthomas/chroma/v2"
Expand Down Expand Up @@ -36,7 +36,7 @@ type ParserHTML struct {

// Parse parses dependencies from HTML file content via ReadCloser using the chroma HTML lexer.
func (p *ParserHTML) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package deps
import (
"fmt"
"io"
"os"
"regexp"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/log"

Expand Down Expand Up @@ -38,7 +38,7 @@ type ParserJava struct {

// Parse parses dependencies from Java file content using the chroma Java lexer.
func (p *ParserJava) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package deps
import (
"fmt"
"io"
"os"
"regexp"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/log"

Expand Down Expand Up @@ -35,7 +35,7 @@ type ParserJavaScript struct {

// Parse parses dependencies from JavaScript file content using the chroma JavaScript lexer.
func (p *ParserJavaScript) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package deps
import (
"fmt"
"io"
"os"
"path/filepath"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/log"

Expand Down Expand Up @@ -44,7 +44,7 @@ type ParserJSON struct {

// Parse parses dependencies from JSON file content using the chroma JSON lexer.
func (p *ParserJSON) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/kotlin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package deps
import (
"fmt"
"io"
"os"
"regexp"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/log"

Expand Down Expand Up @@ -35,7 +35,7 @@ type ParserKotlin struct {

// Parse parses dependencies from Kotlin file content using the chroma Kotlin lexer.
func (p *ParserKotlin) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/objectivec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package deps
import (
"fmt"
"io"
"os"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/log"

Expand All @@ -32,7 +32,7 @@ type ParserObjectiveC struct {

// Parse parses dependencies from Objective-C file content using the chroma Objective-C lexer.
func (p *ParserObjectiveC) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/php.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package deps
import (
"fmt"
"io"
"os"
"regexp"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/log"

Expand Down Expand Up @@ -41,7 +41,7 @@ type ParserPHP struct {

// Parse parses dependencies from PHP file content using the chroma PHP lexer.
func (p *ParserPHP) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package deps
import (
"fmt"
"io"
"os"
"regexp"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/log"

Expand Down Expand Up @@ -38,7 +38,7 @@ type ParserPython struct {

// Parse parses dependencies from Python file content using the chroma Python lexer.
func (p *ParserPython) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package deps
import (
"fmt"
"io"
"os"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/log"

Expand Down Expand Up @@ -34,7 +34,7 @@ type ParserRust struct {

// Parse parses dependencies from Rust file content using the chroma Rust lexer.
func (p *ParserRust) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/scala.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package deps
import (
"fmt"
"io"
"os"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/log"

Expand All @@ -32,7 +32,7 @@ type ParserScala struct {

// Parse parses dependencies from Scala file content using the chroma Scala lexer.
func (p *ParserScala) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deps/swift.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package deps
import (
"fmt"
"io"
"os"
"regexp"
"strings"

"github.com/wakatime/wakatime-cli/pkg/file"
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
"github.com/wakatime/wakatime-cli/pkg/log"

Expand Down Expand Up @@ -35,7 +35,7 @@ type ParserSwift struct {

// Parse parses dependencies from Swift file content using the chroma Swift lexer.
func (p *ParserSwift) Parse(filepath string) ([]string, error) {
reader, err := os.Open(filepath) // nolint:gosec
reader, err := file.OpenNoLock(filepath) // nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to open file %q: %s", filepath, err)
}
Expand Down
Loading

0 comments on commit f108814

Please sign in to comment.