예제 #1
0
        /// <inheritdoc/>
        public IStaticDirectory GetDirectory(string path)
        {
            Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(path), nameof(path));
            Covenant.Requires <ArgumentException>(!path.Contains("/../"), $"{nameof(path)}: Relative path segments like \"/../\" are not supported.");
            Covenant.Requires <ArgumentException>(!path.StartsWith("./"), $"{nameof(path)}: Relative path segments like \"./\" are not supported.");

            // Special case the root directory.

            if (path == "/")
            {
                return(root ?? this);
            }

            if (path.Length > 1 && path.EndsWith("/"))
            {
                path = path.Substring(0, path.Length - 1);
            }

            if (!LinuxPath.IsPathRooted(path))
            {
                path = LinuxPath.Combine(this.Path, path);
            }

            var directory = FindDirectory(path);

            if (directory == null)
            {
                throw new FileNotFoundException($"Directory [{path}] not found.");
            }

            return(directory);
        }
예제 #2
0
        /// <summary>
        /// Protected constructor.
        /// </summary>
        /// <param name="path">The logical path to this file.</param>
        protected StaticFileBase(string path)
        {
            Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(path));

            this.Path = path;
            this.Name = LinuxPath.GetFileName(path);
        }
예제 #3
0
        /// <inheritdoc/>
        public virtual IStaticFile GetFile(string path)
        {
            Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(path), nameof(path));
            Covenant.Requires <ArgumentException>(!path.Contains("/../"), $"{nameof(path)}: Relative path segments like \"/../\" are not supported.");
            Covenant.Requires <ArgumentException>(!path.StartsWith("./"), $"{nameof(path)}: Relative path segments like \"./\" are not supported.");

            if (!LinuxPath.IsPathRooted(path))
            {
                path = LinuxPath.Combine(this.Path, path);
            }

            var file = FindFile(path);

            if (file == null)
            {
                throw new FileNotFoundException($"File [{path}] not found.");
            }

            return(file);
        }