private BuilderDirectory CreateDirectory(string path, int user, int group, UnixFilePermissions permissions) { BuilderDirectory currentDir = GetRoot(); string[] elems = path.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < elems.Length; ++i) { BuilderNode nextDirAsNode = currentDir.GetChild(elems[i]); BuilderDirectory nextDir = nextDirAsNode as BuilderDirectory; if (nextDirAsNode == null) { nextDir = new BuilderDirectory() { UserId = user, GroupId = group, Mode = permissions, ModificationTime = DateTime.Now, }; currentDir.AddChild(elems[i], nextDir); } else if (nextDir == null) { throw new FileNotFoundException("Found " + nextDirAsNode.Inode.Type + ", expecting Directory", string.Join("\\", elems, 0, i + 1)); } currentDir = nextDir; } return(currentDir); }
/// <summary> /// Creates a new instance with default settings. /// </summary> public NfsFileSystemOptions() { NewFilePermissions = UnixFilePermissions.OwnerRead | UnixFilePermissions.OwnerWrite | UnixFilePermissions.GroupRead | UnixFilePermissions.GroupWrite; NewDirectoryPermissions = UnixFilePermissions.OwnerRead | UnixFilePermissions.OwnerWrite | UnixFilePermissions.OwnerExecute | UnixFilePermissions.GroupRead | UnixFilePermissions.GroupWrite | UnixFilePermissions.GroupExecute; }
public static int GetFileMode([NotNull] string filePath, out UnixFilePermissions permission) { permission = UnixFilePermissions.None; int ret; if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { var stat = new Mac.STAT64(); ret = Mac.stat(filePath, ref stat); if (ret == 0) { permission = (UnixFilePermissions)(stat.st_mode & (uint)UnixFilePermissions.All); } } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { var stat = new Linux.STAT64(); ret = Linux.stat(filePath, ref stat); if (ret == 0) { permission = (UnixFilePermissions)(stat.st_mode & (uint)UnixFilePermissions.All); } } else { throw new NotSupportedException("Not supported on this platform"); } return(ret); }
public UnixBuildFileRecord(string name, BuilderExtentSource fileSource, UnixFilePermissions fileMode, int ownerId, int groupId, DateTime modificationTime) { _name = name; _source = fileSource; _fileMode = fileMode; _ownerId = ownerId; _groupId = groupId; _modificationTime = modificationTime; }
public void ReadFrom(byte[] buffer, int offset) { FileName = ReadNullTerminatedString(buffer, offset + 0, 100); FileMode = (UnixFilePermissions)OctalToLong(ReadNullTerminatedString(buffer, offset + 100, 8)); OwnerId = (int)OctalToLong(ReadNullTerminatedString(buffer, offset + 108, 8)); GroupId = (int)OctalToLong(ReadNullTerminatedString(buffer, offset + 116, 8)); FileLength = OctalToLong(ReadNullTerminatedString(buffer, offset + 124, 12)); ModificationTime = Utilities.DateTimeFromUnix((uint)OctalToLong(ReadNullTerminatedString(buffer, offset + 136, 12))); }
public TarHeaderExtent(long start, string fileName, long fileLength, UnixFilePermissions mode, int ownerId, int groupId, DateTime modificationTime) : base(start, 512) { _fileName = fileName; _fileLength = fileLength; _mode = mode; _ownerId = ownerId; _groupId = groupId; _modificationTime = modificationTime; }
public static bool MkDir(string pathname, UnixFilePermissions mode = CommonUnixFilePermissions.Perm0777) { try { Directory.CreateDirectory(pathname); } catch { return(false); } return(true); }
public Nfs3FileAttributes(XdrDataReader reader) { Type = (Nfs3FileType)reader.ReadInt32(); Mode = (UnixFilePermissions)reader.ReadInt32(); LinkCount = reader.ReadUInt32(); Uid = reader.ReadUInt32(); Gid = reader.ReadUInt32(); Size = reader.ReadInt64(); BytesUsed = reader.ReadInt64(); RdevMajor = reader.ReadUInt32(); RdevMinor = reader.ReadUInt32(); FileSystemId = reader.ReadUInt64(); FileId = reader.ReadUInt64(); AccessTime = new Nfs3FileTime(reader); ModifyTime = new Nfs3FileTime(reader); ChangeTime = new Nfs3FileTime(reader); }
/// <summary> /// Adds a directory to the file system. /// </summary> /// <param name="path">The full path to the directory.</param> /// <param name="user">The owner of the directory.</param> /// <param name="group">The group of the directory.</param> /// <param name="permissions">The access permission of the directory.</param> /// <param name="modificationTime">The modification time of the directory.</param> /// <remarks> /// <para>The created directory with have the default owner, group, permissions and the /// current time as it's modification time. Any missing parent directories will be /// created with the specified owner, group, and directory permissions. The current time /// will be used as the modification time.</para> /// </remarks> public void AddDirectory(string path, int user, int group, UnixFilePermissions permissions, DateTime modificationTime) { BuilderDirectory dir = new BuilderDirectory(); dir.UserId = user; dir.GroupId = group; dir.Mode = permissions; dir.ModificationTime = modificationTime; BuilderDirectory parentDir = CreateDirectory( Utilities.GetDirectoryFromPath(path), user, group, permissions); parentDir.AddChild(Utilities.GetFileFromPath(path), dir); }
/// <summary> /// Adds a file to the file system. /// </summary> /// <param name="path">The full path to the file.</param> /// <param name="contentPath">Local file system path to the file to add.</param> /// <param name="user">The owner of the file.</param> /// <param name="group">The group of the file.</param> /// <param name="permissions">The access permission of the file.</param> /// <param name="modificationTime">The modification time of the file.</param> /// <remarks> /// <para>Any missing parent directories will be created with the specified owner and group, /// default directory permissions and the current time as the modification time.</para> /// </remarks> public void AddFile(string path, string contentPath, int user, int group, UnixFilePermissions permissions, DateTime modificationTime) { BuilderFile file = new BuilderFile(contentPath); file.UserId = user; file.GroupId = group; file.Mode = permissions; file.ModificationTime = modificationTime; BuilderDirectory dirNode = CreateDirectory( Utilities.GetDirectoryFromPath(path), user, group, DefaultDirectoryPermissions); dirNode.AddChild(Utilities.GetFileFromPath(path), file); }
public static PhpDirectory Make(string dirName, UnixFilePermissions perm) { return new RuntimePhpDirectory(dirName); }
public UnixBuildFileRecord( string name, Stream stream, UnixFilePermissions fileMode, int ownerId, int groupId, DateTime modificationTime) : this(name, new BuilderStreamExtentSource(stream), fileMode, ownerId, groupId, modificationTime) { }
public void ChMod(UnixFilePermissions i) { throw new NotImplementedException(); }
public static int SetFileMode([NotNull] string pathname, UnixFilePermissions mode) => chmod(pathname, mode);
public static bool ChangeMod(string filename, UnixFilePermissions mode) { return(true); }
/// <summary> /// "Change Mode" -- sets file permissions in Linux / Unix. /// </summary> /// <param name="path">Path to set</param> /// <param name="mode">Permissions mode flags</param> /// <returns>System result status</returns> public static int chmod(string path, UnixFilePermissions mode) { return(sys_chmod(path, (uint)mode)); }
public static bool MkDir(string pathname, UnixFilePermissions mode = CommonUnixFilePermissions.Perm0777) { try { Directory.CreateDirectory(pathname); } catch { return false; } return true; }
public static bool ChangeMod(string filename, UnixFilePermissions mode) { return true; }
/// <summary> /// Add a file to the tar archive. /// </summary> /// <param name="name">The name of the file.</param> /// <param name="stream">The file data.</param> /// <param name="fileMode">The access mode of the file.</param> /// <param name="ownerId">The uid of the owner.</param> /// <param name="groupId">The gid of the owner.</param> /// <param name="modificationTime">The modification time for the file.</param> public void AddFile( string name, Stream stream, UnixFilePermissions fileMode, int ownerId, int groupId, DateTime modificationTime) { _files.Add(new UnixBuildFileRecord(name, stream, fileMode, ownerId, groupId, modificationTime)); }
public static PhpDirectory Make(string dirName, UnixFilePermissions perm) { return(new RuntimePhpDirectory(dirName)); }
/// <summary> /// Adds a file to the file system. /// </summary> /// <param name="path">The full path to the file.</param> /// <param name="contentPath">Local file system path to the file to add.</param> /// <param name="user">The owner of the file.</param> /// <param name="group">The group of the file.</param> /// <param name="permissions">The access permission of the file.</param> /// <param name="modificationTime">The modification time of the file</param> /// <remarks> /// <para>Any missing parent directories will be created with the specified owner and group, /// default directory permissions and the current time as the modification time.</para> /// </remarks> public void AddFile(string path, string contentPath, int user, int group, UnixFilePermissions permissions, DateTime modificationTime) { BuilderFile file = new BuilderFile(contentPath); file.UserId = user; file.GroupId = group; file.Mode = permissions; file.ModificationTime = modificationTime; BuilderDirectory dirNode = CreateDirectory( Utilities.GetDirectoryFromPath(path), user, group, DefaultDirectoryPermissions); dirNode.AddChild(Utilities.GetFileFromPath(path), file); }
public UnixBuildFileRecord( string name, byte[] buffer, UnixFilePermissions fileMode, int ownerId, int groupId, DateTime modificationTime) : this(name, new BuilderBufferExtentSource(buffer), fileMode, ownerId, groupId, modificationTime) { }
private BuilderDirectory CreateDirectory(string path, int user, int group, UnixFilePermissions permissions) { BuilderDirectory currentDir = GetRoot(); string[] elems = path.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < elems.Length; ++i) { BuilderNode nextDirAsNode = currentDir.GetChild(elems[i]); BuilderDirectory nextDir = nextDirAsNode as BuilderDirectory; if (nextDirAsNode == null) { nextDir = new BuilderDirectory() { UserId = user, GroupId = group, Mode = permissions, ModificationTime = DateTime.Now, }; currentDir.AddChild(elems[i], nextDir); } else if (nextDir == null) { throw new FileNotFoundException("Found " + nextDirAsNode.Inode.Type + ", expecting Directory", string.Join("\\", elems, 0, i + 1)); } currentDir = nextDir; } return currentDir; }
static extern int chmod(string pathname, UnixFilePermissions mode);
/// <summary> /// "Change Mode" -- sets file permissions in Linux / Unix. /// </summary> /// <param name="path">Path to set</param> /// <param name="mode">Permissions mode flags</param> /// <returns>System result status</returns> public static int chmod(string path, UnixFilePermissions mode) { return sys_chmod(path, (uint)mode); }