mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 15:11:53 +08:00
Remove xattr via obj-c
This commit is contained in:
parent
3694dd2a55
commit
880a4e0b40
34
v2/internal/xattr/xattr.go
Normal file
34
v2/internal/xattr/xattr.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package xattr
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo CFLAGS: -x objective-c
|
||||||
|
#cgo LDFLAGS: -framework Foundation
|
||||||
|
#import <sys/xattr.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
void removeXattrFrom(const char *path) {
|
||||||
|
ssize_t xattrNamesSize = listxattr(path, NULL, 0, XATTR_NOFOLLOW);
|
||||||
|
if (xattrNamesSize <= 0) return;
|
||||||
|
|
||||||
|
char *xattrNames = (char *)malloc(xattrNamesSize);
|
||||||
|
xattrNamesSize = listxattr(path, xattrNames, xattrNamesSize, XATTR_NOFOLLOW);
|
||||||
|
|
||||||
|
ssize_t pos = 0;
|
||||||
|
while (pos < xattrNamesSize) {
|
||||||
|
char *name = xattrNames + pos;
|
||||||
|
removexattr(path, name, XATTR_NOFOLLOW);
|
||||||
|
pos += strlen(name) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(xattrNames);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
func RemoveXAttr(filepath string) {
|
||||||
|
cpath := C.CString(filepath)
|
||||||
|
defer C.free(unsafe.Pointer(cpath))
|
||||||
|
C.removeXattrFrom(cpath)
|
||||||
|
}
|
@ -13,6 +13,8 @@ import (
|
|||||||
"github.com/wailsapp/wails/v2/pkg/commands/buildtags"
|
"github.com/wailsapp/wails/v2/pkg/commands/buildtags"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var fixupXattrs func(string)
|
||||||
|
|
||||||
// Options for generating bindings
|
// Options for generating bindings
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Filename string
|
Filename string
|
||||||
@ -58,12 +60,9 @@ func GenerateBindings(options Options) (string, error) {
|
|||||||
return stdout, fmt.Errorf("%s\n%s\n%s", stdout, stderr, err)
|
return stdout, fmt.Errorf("%s\n%s\n%s", stdout, stderr, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "darwin" {
|
// Fix up xattrs if required
|
||||||
// Remove quarantine attribute
|
if fixupXattrs != nil {
|
||||||
stdout, stderr, err = shell.RunCommand(workingDirectory, "xattr", "-rc", filename)
|
fixupXattrs(filename)
|
||||||
if err != nil {
|
|
||||||
return stdout, fmt.Errorf("%s\n%s\n%s", stdout, stderr, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
9
v2/pkg/commands/bindings/bindings_darwin.go
Normal file
9
v2/pkg/commands/bindings/bindings_darwin.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
//go:build darwin
|
||||||
|
|
||||||
|
package bindings
|
||||||
|
|
||||||
|
import "github.com/wailsapp/wails/v2/internal/xattr"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
fixupXattrs = xattr.RemoveXAttr
|
||||||
|
}
|
@ -22,6 +22,8 @@ import (
|
|||||||
"github.com/wailsapp/wails/v2/pkg/clilogger"
|
"github.com/wailsapp/wails/v2/pkg/clilogger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var fixupXattrs func(string)
|
||||||
|
|
||||||
// Mode is the type used to indicate the build modes
|
// Mode is the type used to indicate the build modes
|
||||||
type Mode int
|
type Mode int
|
||||||
|
|
||||||
@ -327,6 +329,11 @@ func execBuildApplication(builder Builder, options *Options) (string, error) {
|
|||||||
if _, err := os.Stat(options.CompiledBinary); os.IsNotExist(err) {
|
if _, err := os.Stat(options.CompiledBinary); os.IsNotExist(err) {
|
||||||
return "", fmt.Errorf("compiled binary does not exist at path: %s", options.CompiledBinary)
|
return "", fmt.Errorf("compiled binary does not exist at path: %s", options.CompiledBinary)
|
||||||
}
|
}
|
||||||
|
if fixupXattrs != nil {
|
||||||
|
os.Chdir(options.BinDirectory)
|
||||||
|
fixupXattrs(options.CompiledBinary)
|
||||||
|
os.Chdir(options.ProjectData.Path)
|
||||||
|
}
|
||||||
stdout, stderr, err := shell.RunCommand(options.BinDirectory, "xattr", "-rc", options.CompiledBinary)
|
stdout, stderr, err := shell.RunCommand(options.BinDirectory, "xattr", "-rc", options.CompiledBinary)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("%s - %s", err.Error(), stderr)
|
return "", fmt.Errorf("%s - %s", err.Error(), stderr)
|
||||||
|
9
v2/pkg/commands/build/build_darwin.go
Normal file
9
v2/pkg/commands/build/build_darwin.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
//go:build darwin
|
||||||
|
|
||||||
|
package build
|
||||||
|
|
||||||
|
import "github.com/wailsapp/wails/v2/internal/xattr"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
fixupXattrs = xattr.RemoveXAttr
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user