forked from canneverbe/Ketarin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added code to set permissions on the final file, respecting umask. Also fixed potentially similar problem with exports, although the file is opened differently, and I think it was already respecting umask.
- Loading branch information
Tom Francis
committed
Oct 2, 2019
1 parent
33c5732
commit b57c1fe
Showing
4 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using Mono.Unix; | ||
using Mono.Unix.Native; | ||
|
||
namespace Ketarin | ||
{ | ||
public class MaskedPermissions | ||
{ | ||
private static uint umask_value = getUmask(); | ||
|
||
public static uint getUmask() | ||
{ | ||
uint _umask_value = umask(0); | ||
umask(_umask_value); | ||
return _umask_value; | ||
} | ||
|
||
public static uint setMaskedPermissions(string path, FilePermissions mode) | ||
{ | ||
uint _mode = NativeConvert.FromFilePermissions(mode); | ||
_mode = _mode & ~(umask_value); | ||
return chmod(path, _mode); | ||
} | ||
|
||
[System.Runtime.InteropServices.DllImport("libc", SetLastError=false, EntryPoint="umask")] | ||
private extern static uint umask(uint mask); | ||
|
||
[System.Runtime.InteropServices.DllImport("libc", SetLastError=true, EntryPoint="chmod")] | ||
private extern static uint chmod([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(FileNameMarshaler))] string path, uint mode); | ||
} | ||
|
||
class FileNameMarshaler : ICustomMarshaler | ||
{ | ||
private static FileNameMarshaler instance = new FileNameMarshaler(); | ||
public static ICustomMarshaler GetInstance(string s) | ||
{ | ||
return instance; | ||
} | ||
|
||
public void CleanUpManagedData(Object obj) | ||
{ | ||
// do nothing | ||
} | ||
|
||
public void CleanUpNativeData(IntPtr pNativeData) | ||
{ | ||
UnixMarshal.FreeHeap(pNativeData); | ||
} | ||
|
||
public int GetNativeDataSize() | ||
{ | ||
return IntPtr.Size; | ||
} | ||
|
||
public IntPtr MarshalManagedToNative(object obj) | ||
{ | ||
String str = obj as string; | ||
if (str == null) | ||
{ | ||
return IntPtr.Zero; | ||
} | ||
return UnixMarshal.StringToHeap(str, UnixEncoding.Instance); | ||
} | ||
|
||
public object MarshalNativeToManaged(IntPtr pNativeData) | ||
{ | ||
return UnixMarshal.PtrToString(pNativeData, UnixEncoding.Instance); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters