Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testdata/**/*.proto text eol=lf
11 changes: 9 additions & 2 deletions internal/adapters/lock_file/lock_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lockfile

import (
"bufio"
"fmt"
"strings"

"github.com/easyp-tech/easyp/internal/core"
Expand All @@ -21,11 +22,13 @@ type LockFile struct {
cache map[string]fileInfo
}

func New(dirWalker core.DirWalker) *LockFile {
func New(dirWalker core.DirWalker) (*LockFile, error) {
cache := make(map[string]fileInfo)

fp, err := dirWalker.Open(lockFileName)
if err == nil {
defer func() { _ = fp.Close() }()

fscanner := bufio.NewScanner(fp)

for fscanner.Scan() {
Comment thread
yosakoo marked this conversation as resolved.
Expand All @@ -40,11 +43,15 @@ func New(dirWalker core.DirWalker) *LockFile {
}
cache[parts[0]] = fileInfo
}

if err := fscanner.Err(); err != nil {
return nil, fmt.Errorf("scan %s: %w", lockFileName, err)
}
}

lockFile := &LockFile{
dirWalker: dirWalker,
cache: cache,
}
return lockFile
return lockFile, nil
}
11 changes: 9 additions & 2 deletions internal/adapters/lock_file/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import (

func (l *LockFile) Write(
moduleName string, revisionVersion string, installedPackageHash models.ModuleHash,
) error {
) (err error) {
fp, err := l.dirWalker.Create(lockFileName)
if err != nil {
return fmt.Errorf("l.dirWalker.Create: %w", err)
}
defer func() {
if closeErr := fp.Close(); closeErr != nil && err == nil {
err = fmt.Errorf("fp.Close: %w", closeErr)
}
}()

fileInfo := fileInfo{
version: revisionVersion,
Expand All @@ -30,7 +35,9 @@ func (l *LockFile) Write(

for _, k := range keys {
r := fmt.Sprintf("%s %s %s\n", k, l.cache[k].version, l.cache[k].hash)
_, _ = fp.Write([]byte(r))
if _, err := fp.Write([]byte(r)); err != nil {
return fmt.Errorf("fp.Write: %w", err)
}
}

return nil
Expand Down
17 changes: 8 additions & 9 deletions internal/adapters/plugin/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ func (e *RemotePluginExecutor) Execute(ctx context.Context, plugin Info, request
if err != nil {
return nil, fmt.Errorf("failed to connect to gRPC server %s: %w", host, err)
}
defer conn.Close()
defer func() {
if err := conn.Close(); err != nil {
e.logger.Warn(ctx, "failed to close gRPC connection",
slog.String("plugin", plugin.Source),
slog.Any("error", err),
)
}
}()

// Создаем gRPC клиент
client := plugingeneratorv1.NewServiceAPIClient(conn)
Expand All @@ -93,14 +100,6 @@ func (e *RemotePluginExecutor) Execute(ctx context.Context, plugin Info, request
return nil, fmt.Errorf("gRPC call failed for plugin %s: %w", plugin.Source, err)
}

err = conn.Close()
if err != nil {
e.logger.Warn(ctx, "failed to close gRPC connection",
slog.String("plugin", plugin.Source),
slog.Any("error", err),
)
}

return resp.CodeGeneratorResponse, nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/adapters/storage/get_install_dir_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package storage

import (
"path"
"path/filepath"
)

func (s *storageSuite) Test_GetInstallDir() {
moduleName := getFakeModule().Name
version := getFakeRevision().Version

expectedResult := path.Join(s.rootDir, installedDir, moduleName, version)
expectedResult := filepath.Join(s.rootDir, installedDir, moduleName, version)

res := s.storage.GetInstallDir(moduleName, version)
s.Equal(expectedResult, res)
Expand Down
8 changes: 7 additions & 1 deletion internal/adapters/storage/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package storage
import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -183,9 +184,14 @@ func TestBuildInstallTree_AbsoluteSymlinkRejected(t *testing.T) {
Directories: []string{"proto"},
})

absTarget := "/etc/passwd"
if runtime.GOOS == "windows" {
absTarget = `C:\Windows\System32\drivers\etc\hosts`
}

require.NoError(t, os.MkdirAll(filepath.Join(srcDir, "proto"), 0755))
require.NoError(t, os.WriteFile(filepath.Join(srcDir, "proto", "file.proto"), []byte("data"), 0644))
require.NoError(t, os.Symlink("/etc/passwd", filepath.Join(srcDir, "proto", "bad.proto")))
require.NoError(t, os.Symlink(absTarget, filepath.Join(srcDir, "proto", "bad.proto")))

err := buildInstallTree(srcDir, dstDir, renamer)
require.Error(t, err)
Expand Down
6 changes: 5 additions & 1 deletion internal/api/temporaly_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ func buildCore(_ context.Context, log logger.Logger, cfg config.Config, dirWalke
return nil, fmt.Errorf("cfg.BuildLinterRules: %w", err)
}

lockFile := lockfile.New(dirWalker)
lockFile, err := lockfile.New(dirWalker)
if err != nil {
return nil, fmt.Errorf("lockfile.New: %w", err)
}

easypPath, err := getEasypPath(log)
if err != nil {
return nil, fmt.Errorf("getEasypPath: %w", err)
Expand Down
Loading