Resolve() public static method

根据路径解析目录,路径必须以 / 结尾
public static Resolve ( VFSCore vfs, String path ) : INodeDirectory
vfs VFSCore
path String
return INodeDirectory
示例#1
0
            public Directory(VFSCore vfs, String path)
            {
                this.vfs = vfs;

                if (!path.EndsWith("/"))
                {
                    path += "/";
                }

                this.path = path;

                dir = INodeDirectory.Resolve(vfs, path);

                if (dir == null)
                {
                    throw new Exception("无效路径");
                }
            }
示例#2
0
文件: VFS.File.cs 项目: bwbwbwbw/vfs
            public File(VFSCore vfs, String path, FileMode fileMode)
            {
                this.vfs = vfs;

                var directory = VFS.GetPathDirectory(path);
                var name      = VFS.GetPathName(path);

                VFS.AssertNameValid(name);

                INodeDirectory dir = INodeDirectory.Resolve(vfs, directory);

                if (dir == null)
                {
                    throw new Exception("无法访问目录");
                }
                switch (fileMode)
                {
                case FileMode.CreateNew:
                    if (dir.Contains(name))
                    {
                        throw new Exception("文件已存在");
                    }
                    CreateFile(dir, name);
                    break;

                case FileMode.Create:
                    if (dir.Contains(name))
                    {
                        OpenFile(dir, name);
                        inode.Resize(0);
                    }
                    else
                    {
                        CreateFile(dir, name);
                    }
                    break;

                case FileMode.Open:
                    if (!dir.Contains(name))
                    {
                        throw new Exception("文件未找到");
                    }
                    OpenFile(dir, name);
                    break;

                case FileMode.OpenOrCreate:
                    if (dir.Contains(name))
                    {
                        OpenFile(dir, name);
                    }
                    else
                    {
                        CreateFile(dir, name);
                    }
                    break;

                case FileMode.Truncate:
                    if (!dir.Contains(name))
                    {
                        throw new Exception("文件未找到");
                    }
                    OpenFile(dir, name);
                    inode.Resize(0);
                    break;

                case FileMode.Append:
                    if (!dir.Contains(name))
                    {
                        CreateFile(dir, name);
                    }
                    else
                    {
                        OpenFile(dir, name);
                        position = inode.data.sizeByte;
                    }
                    break;

                default:
                    throw new ArgumentException();
                }
            }