How to call chmod +x from a Unity Mac applications? Hacks welcome

Hi all,

I need to call chmod +x from a Unity mac application.

I have a Unity based patcher that downloads and unzips a second Unity project. However, the unzipped project loses its execution rights. Calling "chmod +x" fixes this. But how to do so automatically?

Options I tried: - I made a mycom.command file that a user can execute manually. I cannot seem to run this from Unity. - The .Net file system rights do not seem to be implemented on mac - And the last option I tried was calling Mono.Posix or Mono.Unix.Native.syscall.chmod but this keeps complaining about missing DLLs up untill missing mscrvt (somthing like that) which is a windows only DLL.

Unity forum topic:

I just solved similar with:

[DllImport ("libc", EntryPoint = "chmod", SetLastError = true)]
private static extern int sys_chmod (string path, uint mode);

sys_chmod("some_file_path", 755);

The simplest way is probably to use the System.Diagnostics.Process class, to spawn a process with the "chmod" executable and the proper parameters you need.

@aSig was on the right track, but that wrote the wrong values for me.

This solution works for IL2CPP:

[System.Runtime.InteropServices.DllImport("libc", EntryPoint = "chmod", SetLastError = true)]
private static extern int sys_chmod(string path, int mode);

// user permissions
const int S_IRUSR = 0x100;
const int S_IWUSR = 0x80;
const int S_IXUSR = 0x40;

// group permission
const int S_IRGRP = 0x20;
const int S_IWGRP = 0x10;
const int S_IXGRP = 0x8;

// other permissions
const int S_IROTH = 0x4;
const int S_IWOTH = 0x2;
const int S_IXOTH = 0x1;

const int _0755 =
            S_IRUSR | S_IXUSR | S_IWUSR
            | S_IRGRP | S_IXGRP
            | S_IROTH | S_IXOTH;

sys_chmod("some_file_path", _0755);