Skip to content

Commit

Permalink
重构 - bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
lvyahui8 committed Nov 3, 2024
1 parent 22549a7 commit a0d0cc8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion instr/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (p *Program) handleFile(pkg *agent.Package, file os.DirEntry, handler fileH
p.executor.Submit(func() {
defer fileGroup.Done()
fileAbsPath := filepath.Join(pkg.Dir, file.Name())
fmt.Printf("dir %s,relativePath %s\n", pkg.Dir, file.Name())
// fmt.Printf("dir %s,relativePath %s\n", pkg.Dir, file.Name())
handler(pkg, fileAbsPath)
})
}
Expand Down
17 changes: 7 additions & 10 deletions sdk/agent/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package agent

import (
"bytes"
"embed"
"encoding/json"
"errors"
"fmt"
Expand All @@ -23,8 +22,6 @@ import (
"time"
)

var targetSources embed.FS

const feAddr = ":19898"

const (
Expand Down Expand Up @@ -56,7 +53,7 @@ func handle404(fs http.FileSystem) http.Handler {
_, err := fs.Open(path.Clean(request.URL.Path))
if os.IsNotExist(err) {
// 返回index.html的内容
indexHtml, _ := meta.ReadFile(filepath.Join(MetaRelativePath, "page/index.html"))
indexHtml, _ := meta.ReadFile(filepath.ToSlash(filepath.Join(MetaRelativePath, "page/index.html")))
http.ServeContent(writer, request, "", time.Now(), bytes.NewReader(indexHtml))
return
}
Expand All @@ -75,7 +72,7 @@ func newServer() {
registerApi("/target/info", targetInfo)

// page
staticResources, _ := fs.Sub(meta, filepath.Join(MetaRelativePath, "page"))
staticResources, _ := fs.Sub(meta, filepath.ToSlash(filepath.Join(MetaRelativePath, "page")))
http.Handle("/", handle404(http.FS(staticResources)))

// open browser
Expand Down Expand Up @@ -236,10 +233,10 @@ func sourceFile(writer http.ResponseWriter, request *http.Request) {

// readCode 读取指定代码id文件
func readCode(fileId uint32) []byte {
bytes, err := targetSources.ReadFile(
filepath.ToSlash(filepath.Join(SourcesDir, files[fileId].RelativePath)) + SourcesFileExt)
content, err := meta.ReadFile(
filepath.ToSlash(filepath.Join(MetaRelativePath, SourcesDir, files[fileId].RelativePath)) + SourcesFileExt)
asserts.IsNil(err)
return bytes
return content
}

// queryVal 工具方法
Expand Down Expand Up @@ -271,11 +268,11 @@ func responseError(writer http.ResponseWriter, err error) {
}

func responseJson(writer http.ResponseWriter, res any) {
bytes, err := json.Marshal(res)
content, err := json.Marshal(res)
if err != nil {
_, _ = writer.Write([]byte(err.Error()))
}
_, _ = writer.Write(bytes)
_, _ = writer.Write(content)
}

type CoveredBlock struct {
Expand Down

0 comments on commit a0d0cc8

Please sign in to comment.