NanoByte.Common  2.9.0
NanoByte.Common.Native.UnixUtils Class Reference

Provides helper methods for Unix-specific features of the Mono library. More...

Static Public Member Functions

static void CreateSymlink ([Localizable(false)] string sourcePath, [Localizable(false)] string targetPath)
 Creates a new Unix symbolic link to a file or directory. More...
 
static void CreateHardlink ([Localizable(false)] string sourcePath, [Localizable(false)] string targetPath)
 Creates a new Unix hard link between two files. More...
 
static bool AreHardlinked ([Localizable(false)] string path1, [Localizable(false)] string path2)
 Determines whether to files are hardlinked. More...
 
static void Rename ([Localizable(false)] string source, [Localizable(false)] string destination)
 Renames a file. Atomically replaces the destination if present. More...
 
static bool IsRegularFile ([Localizable(false)] string path)
 Checks whether a file is a regular file (i.e. not a device file, symbolic link, etc.). More...
 
static bool IsSymlink ([Localizable(false)] string path)
 Checks whether a file is a Unix symbolic link. More...
 
static bool IsSymlink ([Localizable(false)] string path, [NotNullWhen(true)] out string? target)
 Checks whether a file is a Unix symbolic link. More...
 
static void MakeReadOnly ([Localizable(false)] string path)
 Removes write permissions for everyone on a filesystem object (file or directory). More...
 
static void MakeWritable ([Localizable(false)] string path)
 Sets write permissions for the owner on a filesystem object (file or directory). More...
 
static bool IsExecutable ([Localizable(false)] string path)
 Checks whether a file is marked as Unix-executable. More...
 
static void SetExecutable ([Localizable(false)] string path, bool executable)
 Marks a file as Unix-executable or not Unix-executable. More...
 
static ? byte[] GetXattr ([Localizable(false)] string path, [Localizable(false)] string name)
 Gets an extended file attribute. More...
 
static void SetXattr ([Localizable(false)] string path, [Localizable(false)] string name, byte[] data)
 Sets an extended file attribute. More...
 
static string GetFileSystem ([Localizable(false)] string path)
 Determines the file system type a file or directory is stored on. More...
 

Properties

static bool IsUnix [get]
 true if the current operating system is a Unixoid system (e.g. Linux or MacOS X). More...
 
static bool IsMacOSX [get]
 true if the current operating system is MacOS X. More...
 
static bool HasGui [get]
 true if there is an X Server running or the current operating system is MacOS X. More...
 
static string OSName [get]
 The operating system name as reported by the "uname" system call. More...
 
static string CpuType [get]
 The CPU type as reported by the "uname" system call (after applying some normalization). More...
 

Detailed Description

Provides helper methods for Unix-specific features of the Mono library.

This class has a dependency on Mono.Posix. Make sure to check IsUnix before calling any methods in this class to avoid exceptions.

Member Function Documentation

◆ AreHardlinked()

static bool NanoByte.Common.Native.UnixUtils.AreHardlinked ( [Localizable(false)] string  path1,
[Localizable(false)] string  path2 
)
static

Determines whether to files are hardlinked.

Parameters
path1The path of the first file.
path2The path of the second file.
Exceptions
InvalidOperationExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).
UnixIOExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).

◆ CreateHardlink()

static void NanoByte.Common.Native.UnixUtils.CreateHardlink ( [Localizable(false)] string  sourcePath,
[Localizable(false)] string  targetPath 
)
static

Creates a new Unix hard link between two files.

Parameters
sourcePathThe path of the link to create.
targetPathThe absolute path of the existing file to point to.
Exceptions
InvalidOperationExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).
UnixIOExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).

◆ CreateSymlink()

static void NanoByte.Common.Native.UnixUtils.CreateSymlink ( [Localizable(false)] string  sourcePath,
[Localizable(false)] string  targetPath 
)
static

Creates a new Unix symbolic link to a file or directory.

Parameters
sourcePathThe path of the link to create.
targetPathThe path of the existing file or directory to point to (relative to sourcePath ).
Exceptions
InvalidOperationExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).
UnixIOExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).

◆ GetFileSystem()

static string NanoByte.Common.Native.UnixUtils.GetFileSystem ( [Localizable(false)] string  path)
inlinestatic

Determines the file system type a file or directory is stored on.

Parameters
pathThe path of the file.
Returns
The name of the file system in fstab format (e.g. ext3 or ntfs-3g).

Only works on Linux, not on other Unixes (e.g. MacOS X).

Exceptions
IOExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).

◆ GetXattr()

static ? byte [] NanoByte.Common.Native.UnixUtils.GetXattr ( [Localizable(false)] string  path,
[Localizable(false)] string  name 
)
static

Gets an extended file attribute.

Parameters
pathThe path of the file to read the attribute from.
nameThe name of the attribute to read.
Returns
The contents of the attribute as a byte array; null if there was a problem reading the file.

◆ IsExecutable()

static bool NanoByte.Common.Native.UnixUtils.IsExecutable ( [Localizable(false)] string  path)
inlinestatic

Checks whether a file is marked as Unix-executable.

Parameters
pathThe file to check for executable rights.
Returns
true if path points to an executable; false otherwise.
Exceptions
InvalidOperationExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).
UnixIOExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).

Will return false for non-existing files.

◆ IsRegularFile()

static bool NanoByte.Common.Native.UnixUtils.IsRegularFile ( [Localizable(false)] string  path)
static

Checks whether a file is a regular file (i.e. not a device file, symbolic link, etc.).

Returns
true if path points to a regular file; false otherwise.

Will return false for non-existing files.

Exceptions
InvalidOperationExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).
UnixIOExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).

◆ IsSymlink() [1/2]

static bool NanoByte.Common.Native.UnixUtils.IsSymlink ( [Localizable(false)] string  path)
static

Checks whether a file is a Unix symbolic link.

Parameters
pathThe path of the file to check.
Returns
true if path points to a symbolic link; false otherwise.

Will return false for non-existing files.

Exceptions
InvalidOperationExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).
UnixIOExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).

◆ IsSymlink() [2/2]

static bool NanoByte.Common.Native.UnixUtils.IsSymlink ( [Localizable(false)] string  path,
[NotNullWhen(true)] out string?  target 
)
inlinestatic

Checks whether a file is a Unix symbolic link.

Parameters
pathThe path of the file to check.
targetReturns the target the symbolic link points to if it exists.
Returns
true if path points to a symbolic link; false otherwise.
Exceptions
InvalidOperationExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).
UnixIOExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).

◆ MakeReadOnly()

static void NanoByte.Common.Native.UnixUtils.MakeReadOnly ( [Localizable(false)] string  path)
inlinestatic

Removes write permissions for everyone on a filesystem object (file or directory).

Parameters
pathThe filesystem object (file or directory) to make read-only.
Exceptions
InvalidOperationExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).
UnixIOExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).

◆ MakeWritable()

static void NanoByte.Common.Native.UnixUtils.MakeWritable ( [Localizable(false)] string  path)
inlinestatic

Sets write permissions for the owner on a filesystem object (file or directory).

Parameters
pathThe filesystem object (file or directory) to make writable by the owner.
Exceptions
InvalidOperationExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).
UnixIOExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).

◆ Rename()

static void NanoByte.Common.Native.UnixUtils.Rename ( [Localizable(false)] string  source,
[Localizable(false)] string  destination 
)
inlinestatic

Renames a file. Atomically replaces the destination if present.

Parameters
sourceThe path of the file to rename.
destinationThe new path of the file. Must reside on the same file system as source .
Exceptions
UnixIOExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).

◆ SetExecutable()

static void NanoByte.Common.Native.UnixUtils.SetExecutable ( [Localizable(false)] string  path,
bool  executable 
)
inlinestatic

Marks a file as Unix-executable or not Unix-executable.

Parameters
pathThe file to mark as executable or not executable.
executabletrue to mark the file as executable, true to mark it as not executable.
Exceptions
InvalidOperationExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).
UnixIOExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).

◆ SetXattr()

static void NanoByte.Common.Native.UnixUtils.SetXattr ( [Localizable(false)] string  path,
[Localizable(false)] string  name,
byte[]  data 
)
inlinestatic

Sets an extended file attribute.

Parameters
pathThe path of the file to set the attribute for.
nameThe name of the attribute to set.
dataThe data to write to the attribute.
Exceptions
UnixIOExceptionThe underlying Unix subsystem failed to process the request (e.g. because of insufficient rights).

Property Documentation

◆ CpuType

string NanoByte.Common.Native.UnixUtils.CpuType
staticget

The CPU type as reported by the "uname" system call (after applying some normalization).

◆ HasGui

bool NanoByte.Common.Native.UnixUtils.HasGui
staticget

true if there is an X Server running or the current operating system is MacOS X.

◆ IsMacOSX

bool NanoByte.Common.Native.UnixUtils.IsMacOSX
staticget

true if the current operating system is MacOS X.

◆ IsUnix

bool NanoByte.Common.Native.UnixUtils.IsUnix
staticget

true if the current operating system is a Unixoid system (e.g. Linux or MacOS X).

◆ OSName

string NanoByte.Common.Native.UnixUtils.OSName
staticget

The operating system name as reported by the "uname" system call.


The documentation for this class was generated from the following file: