Ejemplo n.º 1
0
 public UnixFileSystemInfo GetContents()
 {
     ReadLink();
     return(UnixFileSystemInfo.GetFileSystemEntry(
                UnixPath.Combine(UnixPath.GetDirectoryName(FullPath),
                                 ContentsPath)));
 }
Ejemplo n.º 2
0
        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);
 }
Ejemplo n.º 5
0
        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();
 }
Ejemplo n.º 7
0
 /** 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 ""; }
 }
Ejemplo n.º 8
0
 public UnixFileSystemInfo CreateLink(string path)
 {
     UnixMarshal.ThrowExceptionForLastErrorIf(Syscall.link(this.FullName, path));
     return(UnixFileSystemInfo.GetFileSystemEntry(path));
 }
Ejemplo n.º 9
0
 /** BLOCKING */
 public static bool IsDir(UnixFileSystemInfo f)
 {
     try { return f.IsDirectory; }
     catch (System.InvalidOperationException) { return false; }
 }
Ejemplo n.º 10
0
 /** BLOCKING */
 public static DateTime LastModified(UnixFileSystemInfo f)
 {
     try {
       return f.LastWriteTime;
     } catch (Exception) {
       return DefaultTime;
     }
 }
Ejemplo n.º 11
0
 /** BLOCKING */
 public static FileTypes FileType(UnixFileSystemInfo f)
 {
     try {
       return (new UnixSymbolicLinkInfo(f.FullName)).FileType;
     }
     catch (System.InvalidOperationException) { return FileTypes.RegularFile; }
 }
Ejemplo n.º 12
0
 /** 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 ""; }
 }
Ejemplo n.º 13
0
 /** BLOCKING */
 public static FileAccessPermissions FilePermissions(UnixFileSystemInfo f)
 {
     try { return f.FileAccessPermissions; }
     catch (System.InvalidOperationException) { return (FileAccessPermissions)0; }
 }
Ejemplo n.º 14
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> ();
        }
    }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 17
0
		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;
		}
Ejemplo n.º 18
0
		private void GetUnixInfo(string fullName)
		{
			UnixDirectoryInfo = UnixFileSystemInfo.GetFileSystemEntry(fullName);
		}
Ejemplo n.º 19
0
		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 })));
 }
Ejemplo n.º 21
0
 public static long FileSize(UnixFileSystemInfo f)
 {
     try { return f.Length; }
     catch (System.InvalidOperationException) { return 0; }
 }
Ejemplo n.º 22
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;
            }
        }
Ejemplo n.º 23
0
 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;
		}