示例#1
0
        public VirtualFileSystem(FtpConfig config, FtpUserGroup group, string rootpath = null)
        {
            _config = config;
            _group  = group;
            if (!string.IsNullOrEmpty(rootpath))
            {
                _rootPath = rootpath;
            }
            else if (!string.IsNullOrEmpty(group.HomeDir))
            {
                _rootPath = group.HomeDir;
            }
            else
            {
                _rootPath = config.HomeDir;
            }
            _rootDirectory = new VDirectory(null, new FilePermission("r-xr-xr-x"), _rootPath, "");



            _currentDirectory = _rootDirectory;
            _currentDirectory.Refresh();
            AddGroupLinks();    //FIXED:应在刷新后加入链接
            _currentDirectory.Refresh();
            SetPermission(_currentDirectory, true);
        }
示例#2
0
        /// <summary>
        /// 切换当前目录
        /// </summary>
        /// <param name="vPath">虚拟路径</param>
        /// <param name="createDirIfNotExists">目录不存在时,是否创建目录</param> //MARK: WARNING: may cause Security Issue!
        /// <returns></returns>
        public bool ChangeCurrentDirectory(string vPath, bool createDirIfNotExists = false)
        {
            string pre = VPath.NormalizeFilename(vPath, true);

            if (pre == "..")
            {
                _currentDirectory = _currentDirectory.ParentDirectory;
            }
            else if (pre == "/") //FIXED:
            {
                _currentDirectory = _rootDirectory;
            }
            else
            {
                VDirectory v;
                if (pre.StartsWith("/", StringComparison.OrdinalIgnoreCase))    //绝对虚拟路径
                {
                    v = Get(pre, true) as VDirectory;
                }
                else    //相对虚拟路径
                {
                    v = _currentDirectory.SubFiles.Find((t) => t.IsDirectory && t.Name == pre) as VDirectory;
                }
                if (v == null)
                {
                    if (!createDirIfNotExists)
                    {
                        return(false);
                    }
                    //ADDED:
                    FileError fileError = CreateDirectory(pre);
                    if (fileError == FileError.None)
                    {
                        var dir = Get(pre, true) as VDirectory;
                        if (dir != null)
                        {
                            v = dir;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                _currentDirectory = v;
            }
            _currentDirectory.Refresh();
            SetPermission(_currentDirectory, true);
            return(true);
        }