public UnixFileSystemInfo GetContents() { ReadLink(); return(UnixFileSystemInfo.GetFileSystemEntry( UnixPath.Combine(UnixPath.GetDirectoryName(FullPath), ContentsPath))); }
public static bool TryGetFileSystemEntry(string path, out UnixFileSystemInfo entry) { Native.Stat stat; int r = Native.Syscall.lstat(path, out stat); if (r == -1) { if (Native.Stdlib.GetLastError() == Native.Errno.ENOENT) { entry = new UnixFileInfo(path); return(true); } entry = null; return(false); } if (IsFileType(stat.st_mode, Native.FilePermissions.S_IFDIR)) { entry = new UnixDirectoryInfo(path, stat); } else if (IsFileType(stat.st_mode, Native.FilePermissions.S_IFLNK)) { entry = new UnixSymbolicLinkInfo(path, stat); } else { entry = new UnixFileInfo(path, stat); } return(true); }
private UnixFileSystemInfo[] GetFileSystemEntries(Dirent[] dentries) { UnixFileSystemInfo[] fileSystemEntry = new UnixFileSystemInfo[(int)dentries.Length]; for (int i = 0; i != (int)fileSystemEntry.Length; i++) { fileSystemEntry[i] = UnixFileSystemInfo.GetFileSystemEntry(UnixPath.Combine(base.FullPath, new string[] { dentries[i].d_name })); } return(fileSystemEntry); }
private UnixFileSystemInfo[] GetFileSystemEntries(Native.Dirent[] dentries) { UnixFileSystemInfo[] entries = new UnixFileSystemInfo[dentries.Length]; for (int i = 0; i != entries.Length; ++i) { entries [i] = UnixFileSystemInfo.GetFileSystemEntry( UnixPath.Combine(FullPath, dentries[i].d_name)); } return(entries); }
public static UnixFileSystemInfo GetFileSystemEntry(string path) { Stat stat; int num = Syscall.lstat(path, out stat); if (num == -1 && Stdlib.GetLastError() == Errno.ENOENT) { return(new UnixFileInfo(path)); } UnixMarshal.ThrowExceptionForLastErrorIf(num); if (UnixFileSystemInfo.IsFileType(stat.st_mode, FilePermissions.S_IFDIR)) { return(new UnixDirectoryInfo(path, stat)); } if (UnixFileSystemInfo.IsFileType(stat.st_mode, FilePermissions.S_IFLNK)) { return(new UnixSymbolicLinkInfo(path, stat)); } return(new UnixFileInfo(path, stat)); }
public void Delete(bool recursive) { if (recursive) { UnixFileSystemInfo[] fileSystemEntries = this.GetFileSystemEntries(); for (int i = 0; i < (int)fileSystemEntries.Length; i++) { UnixFileSystemInfo unixFileSystemInfo = fileSystemEntries[i]; UnixDirectoryInfo unixDirectoryInfo = unixFileSystemInfo as UnixDirectoryInfo; if (unixDirectoryInfo == null) { unixFileSystemInfo.Delete(); } else { unixDirectoryInfo.Delete(true); } } } UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.rmdir(base.FullPath)); base.Refresh(); }
/** BLOCKING */ public static string OwnerName(UnixFileSystemInfo f) { try { long uid = f.ToStat().st_uid; if (OwnerNameCache.ContainsKey(uid)) { return OwnerNameCache[uid]; } else { try { UnixUserInfo uf = f.OwnerUser; return OwnerNameCache[uf.UserId] = uf.UserName; } catch (System.ArgumentException) { return OwnerNameCache[uid] = uid.ToString(); } } } catch (System.InvalidOperationException) { return ""; } }
public UnixFileSystemInfo CreateLink(string path) { UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.link(this.FullName, path)); return(UnixFileSystemInfo.GetFileSystemEntry(path)); }
/** BLOCKING */ public static bool IsDir(UnixFileSystemInfo f) { try { return f.IsDirectory; } catch (System.InvalidOperationException) { return false; } }
/** BLOCKING */ public static DateTime LastModified(UnixFileSystemInfo f) { try { return f.LastWriteTime; } catch (Exception) { return DefaultTime; } }
/** BLOCKING */ public static FileTypes FileType(UnixFileSystemInfo f) { try { return (new UnixSymbolicLinkInfo(f.FullName)).FileType; } catch (System.InvalidOperationException) { return FileTypes.RegularFile; } }
/** BLOCKING */ public static string GroupName(UnixFileSystemInfo f) { try { long gid = f.ToStat().st_gid; if (GroupNameCache.ContainsKey(gid)) { return GroupNameCache[gid]; } else { try { UnixGroupInfo uf = f.OwnerGroup; return GroupNameCache[uf.GroupId] = uf.GroupName; } catch (System.ArgumentException) { return GroupNameCache[gid] = gid.ToString(); } } } catch (System.InvalidOperationException) { return ""; } }
/** BLOCKING */ public static FileAccessPermissions FilePermissions(UnixFileSystemInfo f) { try { return f.FileAccessPermissions; } catch (System.InvalidOperationException) { return (FileAccessPermissions)0; } }
public void Setup(UnixFileSystemInfo u) { FullName = u.FullName; Name = u.Name; LCName = Name.ToLower (); Owner = Helpers.OwnerName(u); Group = Helpers.GroupName(u); LastModified = Helpers.LastModified(u); LastFileChange = Helpers.LastChange(FullName); Permissions = Helpers.FilePermissions(u); FileType = Helpers.FileType(u); IsDirectory = FileType == FileTypes.Directory; if (FileType == FileTypes.SymbolicLink) { LinkTarget = Helpers.ReadLink(FullName); var lt = new UnixSymbolicLinkInfo(LinkTarget); IsDirectory = Helpers.FileExists(LinkTarget) && Helpers.FileType(lt) == FileTypes.Directory; } Suffix = IsDirectory ? "" : Helpers.Extname(Name).ToLower(); Size = Helpers.FileSize(u); if (!IsDirectory) { Count = 1; SubTreeSize = Size; SubTreeCount = 1; Complete = true; FilePassDone = true; } else { Count = 0; Entries = new List<FSEntry> (); } }
public void CreateSymbolicLinkTo(UnixFileSystemInfo path) { int r = Native.Syscall.symlink(path.FullName, FullName); UnixMarshal.ThrowExceptionForLastErrorIf(r); }
public void CreateSymbolicLinkTo(UnixFileSystemInfo path) { int num = Syscall.symlink(path.FullName, this.FullName); UnixMarshal.ThrowExceptionForLastErrorIf(num); }
public static bool TryGetFileSystemEntry (string path, out UnixFileSystemInfo entry) { Native.Stat stat; int r = Native.Syscall.lstat (path, out stat); if (r == -1) { if (Native.Stdlib.GetLastError() == Native.Errno.ENOENT) { entry = new UnixFileInfo (path); return true; } entry = null; return false; } if (IsFileType (stat.st_mode, Native.FilePermissions.S_IFDIR)) entry = new UnixDirectoryInfo (path, stat); else if (IsFileType (stat.st_mode, Native.FilePermissions.S_IFLNK)) entry = new UnixSymbolicLinkInfo (path, stat); else entry = new UnixFileInfo (path, stat); return true; }
private void GetUnixInfo(string fullName) { UnixDirectoryInfo = UnixFileSystemInfo.GetFileSystemEntry(fullName); }
private UnixFileSystemInfo[] GetFileSystemEntries (Native.Dirent[] dentries) { UnixFileSystemInfo[] entries = new UnixFileSystemInfo[dentries.Length]; for (int i = 0; i != entries.Length; ++i) entries [i] = UnixFileSystemInfo.GetFileSystemEntry ( UnixPath.Combine (FullPath, dentries[i].d_name)); return entries; }
public UnixFileSystemInfo GetContents() { this.ReadLink(); return(UnixFileSystemInfo.GetFileSystemEntry(UnixPath.Combine(UnixPath.GetDirectoryName(base.FullPath), new string[] { this.ContentsPath }))); }
public static long FileSize(UnixFileSystemInfo f) { try { return f.Length; } catch (System.InvalidOperationException) { return 0; } }
private UnixFileSystemInfo TraverseSymlink(UnixFileSystemInfo info) { lock (visited_symlinks) { visited_symlinks.Clear (); while (info.IsSymbolicLink) { if (visited_symlinks.Contains (info.FullName)) { return null; } visited_symlinks.Add (info.FullName); var target = new UnixSymbolicLinkInfo (info.FullName).GetContents (); if (info.FullName.StartsWith (target.FullName)) { return null; } if (!target.Exists) { return null; } info = target; } return info; } }
public FSEntry(UnixFileSystemInfo u) { LastDraw = FSDraw.frame; Setup(u); }
public void CreateSymbolicLinkTo (UnixFileSystemInfo path) { int r = Syscall.symlink (path.FullName, OriginalPath); UnixMarshal.ThrowExceptionForLastErrorIf (r); }
private UnixFileSystemInfo[] GetFileSystemEntries (Dirent[] dentries) { UnixFileSystemInfo[] entries = new UnixFileSystemInfo[dentries.Length]; for (int i = 0; i != entries.Length; ++i) entries [i] = UnixFileSystemInfo.Create (dentries[i].d_name); return entries; }