Delete() public method

删除一个目录项
public Delete ( String name ) : System.Boolean
name String
return System.Boolean
Ejemplo n.º 1
0
 /// <summary>
 /// 删除文件或文件夹
 /// </summary>
 /// <param name="name"></param>
 public void Delete(String name)
 {
     if (!dir.Contains(name))
     {
         throw new Exception("文件或文件夹未找到");
     }
     if (!dir.Delete(name))
     {
         throw new Exception("删除失败");
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 删除一个目录项
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Boolean Delete(String name)
        {
            if (!Contains(name))
            {
                return(false);
            }
            if (name == "." || name == "..")
            {
                return(false);
            }

            var inodeIndex = entries[name];

            INode inode = INode.Load(vfs, inodeIndex);

            if (inode.IsDirectory())
            {
                // 删除非空目录项:递归删除
                INodeDirectory id = INodeDirectory.Load(vfs, inodeIndex);
                if (id.Size() > 2)
                {
                    var l = id.List();
                    foreach (var pair in l)
                    {
                        id.Delete(pair.Key);
                    }
                }
            }

            inode.data.linkCount--;

            if (inode.data.linkCount == 0)
            {
                inode.Resize(0);
                vfs.DeAllocateINode(inode.index);
            }
            else
            {
                inode.Save();
            }

            entries.Remove(name);
            Save();

            return(true);
        }