5
0
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:
Lea Anthony 2024-03-20 19:08:47 +11:00
parent 3694dd2a55
commit 880a4e0b40
5 changed files with 64 additions and 6 deletions

View 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)
}

View File

@ -13,6 +13,8 @@ import (
"github.com/wailsapp/wails/v2/pkg/commands/buildtags"
)
var fixupXattrs func(string)
// Options for generating bindings
type Options struct {
Filename string
@ -58,12 +60,9 @@ func GenerateBindings(options Options) (string, error) {
return stdout, fmt.Errorf("%s\n%s\n%s", stdout, stderr, err)
}
if runtime.GOOS == "darwin" {
// Remove quarantine attribute
stdout, stderr, err = shell.RunCommand(workingDirectory, "xattr", "-rc", filename)
if err != nil {
return stdout, fmt.Errorf("%s\n%s\n%s", stdout, stderr, err)
}
// Fix up xattrs if required
if fixupXattrs != nil {
fixupXattrs(filename)
}
defer func() {

View File

@ -0,0 +1,9 @@
//go:build darwin
package bindings
import "github.com/wailsapp/wails/v2/internal/xattr"
func init() {
fixupXattrs = xattr.RemoveXAttr
}

View File

@ -22,6 +22,8 @@ import (
"github.com/wailsapp/wails/v2/pkg/clilogger"
)
var fixupXattrs func(string)
// Mode is the type used to indicate the build modes
type Mode int
@ -327,6 +329,11 @@ func execBuildApplication(builder Builder, options *Options) (string, error) {
if _, err := os.Stat(options.CompiledBinary); os.IsNotExist(err) {
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)
if err != nil {
return "", fmt.Errorf("%s - %s", err.Error(), stderr)

View File

@ -0,0 +1,9 @@
//go:build darwin
package build
import "github.com/wailsapp/wails/v2/internal/xattr"
func init() {
fixupXattrs = xattr.RemoveXAttr
}