소스 검색

fix: kill process unexpected

Yeuoly 8 달 전
부모
커밋
7a24210817
2개의 변경된 파일19개의 추가작업 그리고 4개의 파일을 삭제
  1. 13 3
      internal/core/plugin_manager/watcher.go
  2. 6 1
      internal/oss/s3/s3_storage.go

+ 13 - 3
internal/core/plugin_manager/watcher.go

@@ -5,7 +5,6 @@ import (
 	"fmt"
 	"os"
 	"path"
-	"path/filepath"
 	"strings"
 	"time"
 
@@ -96,9 +95,20 @@ func (p *PluginManager) removeUninstalledLocalPlugins() {
 			return true
 		}
 
+		plugin_unique_identifier, err := runtime.Identity()
+		if err != nil {
+			log.Error("get plugin identity failed: %s", err.Error())
+			return true
+		}
+
 		// check if plugin is deleted, stop it if so
-		plugin_path := filepath.Join(p.pluginStoragePath, key)
-		if _, err := os.Stat(plugin_path); os.IsNotExist(err) {
+		exists, err := p.installedBucket.Exists(plugin_unique_identifier)
+		if err != nil {
+			log.Error("check if plugin is deleted failed: %s", err.Error())
+			return true
+		}
+
+		if !exists {
 			runtime.Stop()
 		}
 

+ 6 - 1
internal/oss/s3/s3_storage.go

@@ -4,6 +4,7 @@ import (
 	"bytes"
 	"context"
 	"io"
+	"strings"
 	"time"
 
 	"github.com/aws/aws-sdk-go-v2/aws"
@@ -102,8 +103,12 @@ func (s *AWSS3Storage) List(prefix string) ([]oss.OSSPath, error) {
 			return nil, err
 		}
 		for _, obj := range page.Contents {
+			// remove prefix
+			key := strings.TrimPrefix(*obj.Key, prefix)
+			// remove leading slash
+			key = strings.TrimPrefix(key, "/")
 			keys = append(keys, oss.OSSPath{
-				Path:  *obj.Key,
+				Path:  key,
 				IsDir: false,
 			})
 		}