Skip to content

Commit

Permalink
Merge pull request #10 from aktsk/fix/update-local-py
Browse files Browse the repository at this point in the history
Change lldb-driver.py to be updated automatically
  • Loading branch information
tkmru authored Sep 3, 2021
2 parents f0aa02c + be56234 commit 228aa58
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# vendor/

ipa-medit
lldb-driver.py

# goreleaser
dist/
Expand Down
31 changes: 27 additions & 4 deletions pkg/lldb/lldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ package lldb

import (
"bytes"
"crypto/sha256"
"io"
"os"
"os/exec"
"os/signal"
"path/filepath"
"reflect"
"syscall"
)

Expand All @@ -20,18 +22,39 @@ func fileExists(filepath string) bool {
return err == nil
}

func calcFileHash(filepath string) []byte {
f, _ := os.Open(filepath)
defer f.Close()

h := sha256.New()
io.Copy(h, f)

return h.Sum(nil)
}

func makePythonFile(filepath string) error {
fp, err := os.Create(filepath)
if err != nil {
return err
}
fp.WriteString(pythonData)
return nil
}

func PreparePythonFile() error {
exePath, err := os.Executable()
if err != nil {
return err
}
pyPath = filepath.Join(filepath.Dir(exePath), "lldb-driver.py")
if !fileExists(pyPath) {
fp, err := os.Create(pyPath)
if err != nil {
return err
makePythonFile(pyPath)
} else {
pyDataHash := sha256.Sum256([]byte(pythonData))
fileHash := calcFileHash(pyPath)
if !reflect.DeepEqual(pyDataHash[:], fileHash) {
makePythonFile(pyPath)
}
fp.WriteString(pythonData)
}
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/lldb/lldb_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

package lldb

const pythonData string = `
#!/usr/bin/env python3
const pythonData string = `#!/usr/bin/env python3
# coding: UTF-8
import multiprocessing
Expand Down

0 comments on commit 228aa58

Please sign in to comment.