Skip to content

Commit

Permalink
fix some error
Browse files Browse the repository at this point in the history
  • Loading branch information
unkmonster committed Aug 9, 2024
1 parent 03b8cfd commit 8beabc1
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 73 deletions.
86 changes: 39 additions & 47 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,45 @@ env:
CT0: ${{secrets.CT0}}

jobs:

build-win:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
release:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

- name: G++
run: g++ -v
runs-on: ${{matrix.os}}

- name: Build
run: go build -o tmd2.exe -v -ldflags "-linkmode external -extldflags -static" .

- name: Test
run: go test ./...

- name: List
run: ls

- name: Release
uses: softprops/action-gh-release@v2
with:
files: |
tmd2.exe
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Build
run: go build -o tmd2 -v .

- name: Test
run: go test ./...

- name: Release
uses: softprops/action-gh-release@v2
with:
files: |
tmd2
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Build
run: |
if [${{runner.os}} = 'Windows']; then
go build -v -o tmd2.exe -ldflags "-linkmode external -extldflags -static" .
else
go build -v -o tmd2 .
fi
- name: Package
run: |
if [ ${{ runner.os }} = 'Windows' ]; then
Compress-Archive -Path tmd2.exe -DestinationPath tmd2-${{runner.os}}.zip
else
tar -czvf tmd2-${{runner.os}}.tar.gz tmd2
fi
- name: Release Win
if: runner.os == 'Windows'
uses: softprops/action-gh-release@v2
with:
files: tmd2-${{runner.os}}.zip

- name: Release Posix
if: runner.os != 'Windows'
uses: softprops/action-gh-release@v2
with:
files: tmd2-${{ runner.os }}.tar.gz
1 change: 1 addition & 0 deletions .github/workflows/gotest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
env:
AUTH_TOKEN: ${{secrets.AUTH_TOKEN}}
CT0: ${{secrets.CT0}}
CGO_ENABLED: 0

jobs:

Expand Down
5 changes: 1 addition & 4 deletions downloading/entity.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package downloading

import (
"fmt"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -258,7 +257,7 @@ func updateUserLink(lnk *database.UserLink, db *sqlx.DB, path string) error {
if err != nil && !os.IsExist(err) {
return err
}
} else if runtime.GOOS == "linux" {
} else {
if err = os.RemoveAll(linkpath); err != nil {
return err
}
Expand All @@ -271,8 +270,6 @@ func updateUserLink(lnk *database.UserLink, db *sqlx.DB, path string) error {
return err
}
}
} else {
return fmt.Errorf("unsupported system: %s", runtime.GOOS)
}

if err = database.UpdateUserLink(db, lnk.Id.Int32, name); err != nil {
Expand Down
21 changes: 0 additions & 21 deletions internal/utils/fs.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package utils

/*
#cgo CPPFLAGS: -DUNICODE=1
#cgo windows LDFLAGS: -luuid -lole32 -loleaut32
#cgo linux LDFLAGS: -static-libstdc++ -static-libgcc
#include <stdlib.h>
int CreateSymLink(const char* path, const char* sympath);
*/
import "C"
import (
"bytes"
"fmt"
Expand All @@ -16,7 +8,6 @@ import (
"regexp"
"strconv"
"strings"
"unsafe"
)

var (
Expand Down Expand Up @@ -102,15 +93,3 @@ func UniquePath(path string) (string, error) {
path = filepath.Join(dir, stem+"(1)"+ext)
}
}

func CreateLink(path string, lnk string) error {
cpath := C.CString(path)
clnk := C.CString(lnk)
defer C.free(unsafe.Pointer(cpath))
defer C.free(unsafe.Pointer(clnk))
hr := C.CreateSymLink(cpath, clnk)
if hr != 0 {
return fmt.Errorf("failed to create link: hresult/errno = %d", hr)
}
return nil
}
10 changes: 10 additions & 0 deletions internal/utils/link_posix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build !windows
// +build !windows

package utils

import "os"

func CreateLink(path string, lnk string) error {
return os.Symlink(path, lnk)
}
28 changes: 28 additions & 0 deletions internal/utils/link_win.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//go:build windows
// +build windows

package utils

/*
#cgo CPPFLAGS: -DUNICODE=1
#cgo windows LDFLAGS: -luuid -lole32 -loleaut32
#include <stdlib.h>
int CreateSymLink(const char* path, const char* sympath);
*/
import "C"
import (
"fmt"
"unsafe"
)

func CreateLink(path string, lnk string) error {
cpath := C.CString(path)
clnk := C.CString(lnk)
defer C.free(unsafe.Pointer(cpath))
defer C.free(unsafe.Pointer(clnk))
hr := C.CreateSymLink(cpath, clnk)
if hr != 0 {
return fmt.Errorf("failed to create link: hresult = %d", hr)
}
return nil
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func main() {
var homepath string
if runtime.GOOS == "windows" {
homepath = os.Getenv("appdata")
} else if runtime.GOOS == "linux" {
} else {
homepath = os.Getenv("HOME")
}

Expand Down

0 comments on commit 8beabc1

Please sign in to comment.