Skip to content

Commit

Permalink
fix: fix directory detection when path is symlinked
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Jun 16, 2024
1 parent 464b2c2 commit 6fff879
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions extension/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/FriendsOfShopware/shopware-cli/shop"
"os"
"path"
"path/filepath"
"regexp"
"strings"

"github.com/FriendsOfShopware/shopware-cli/shop"

"github.com/FriendsOfShopware/shopware-cli/internal/asset"
"github.com/FriendsOfShopware/shopware-cli/logging"
"github.com/FriendsOfShopware/shopware-cli/version"
Expand Down Expand Up @@ -58,7 +59,6 @@ func GetShopwareProjectConstraint(project string) (*version.Constraints, error)
for _, pkg := range lock.Packages {
if pkg.Name == "shopware/core" {
v, err := version.NewConstraint(pkg.Version)

if err != nil {
return getProjectConstraintFromKernel(project)
}
Expand All @@ -80,7 +80,6 @@ func getProjectConstraintFromKernel(project string) (*version.Constraints, error
kernelPath := PlatformPath(project, "Core", "Kernel.php")

kernel, err := os.ReadFile(kernelPath)

if err != nil {
return nil, fmt.Errorf("could not determine shopware version")
}
Expand All @@ -92,7 +91,6 @@ func getProjectConstraintFromKernel(project string) (*version.Constraints, error
}

v, err := version.NewConstraint(fmt.Sprintf("~%s.0", string(matches[1])))

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -127,7 +125,6 @@ func FindAssetSourcesOfProject(ctx context.Context, project string, shopCfg *sho
logging.FromContext(ctx).Infof("Found bundle in project: %s (path: %s)", name, bundlePath)

bundleConfig, err := readExtensionConfig(bundlePath)

if err != nil {
logging.FromContext(ctx).Errorf("Cannot read bundle config: %s", err.Error())
continue
Expand Down Expand Up @@ -257,9 +254,27 @@ func addExtensionsByWildcard(extensionDir string) []Extension {
}

for _, file := range extensions {
if file.IsDir() {
ext, err := GetExtensionByFolder(path.Join(extensionDir, file.Name()))
extensionPath := path.Join(extensionDir, file.Name())
evaluatedPath, err := filepath.EvalSymlinks(extensionPath)
if err != nil {
continue
}

isDir := file.IsDir()

if evaluatedPath != extensionPath {
evaluatedStat, err := os.Stat(evaluatedPath)
if err != nil {
continue
}

isDir = evaluatedStat.IsDir()
}

if isDir {
ext, err := GetExtensionByFolder(evaluatedPath)
if err != nil {
fmt.Println(err)

Check failure on line 277 in extension/project.go

View workflow job for this annotation

GitHub Actions / lint

use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
continue
}

Expand Down

0 comments on commit 6fff879

Please sign in to comment.