示例#1
0
        /// <summary>
        /// Create a CanonicalPathCache.
        /// </summary>
        ///
        /// <remarks>
        /// Creates the appropriate PathStrategy object which encapsulates
        /// the correct algorithm. Falls back to different implementations
        /// depending on platform.
        /// </remarks>
        ///
        /// <param name="maxCapacity">Size of the cache.</param>
        /// <param name="symlinks">Policy for following symlinks.</param>
        /// <returns>A new CanonicalPathCache.</returns>
        public static CanonicalPathCache Create(ILogger logger, int maxCapacity, Symlinks symlinks)
        {
            PathStrategy pathStrategy;

            switch (symlinks)
            {
            case Symlinks.Follow:
                try
                {
                    pathStrategy = Win32.IsWindows() ?
                                   (PathStrategy) new GetFinalPathNameByHandleStrategy() :
                                   (PathStrategy) new PosixSymlinkStrategy();
                }
                catch (Exception)
                {
                    // Failed to late-bind a suitable library.
                    logger.Log(Severity.Warning, "Preserving symlinks in canonical paths");
                    pathStrategy = new QueryDirectoryStrategy();
                }
                break;

            case Symlinks.Preserve:
                pathStrategy = new QueryDirectoryStrategy();
                break;

            default:
                throw new ArgumentOutOfRangeException("Invalid symlinks option");
            }

            return(new CanonicalPathCache(maxCapacity, pathStrategy));
        }
示例#2
0
        /// <summary>
        /// Create cache with a given capacity.
        /// </summary>
        /// <param name="pathStrategy">The algorithm for determining the canonical path.</param>
        /// <param name="capacity">The size of the cache.</param>
        public CanonicalPathCache(int maxCapacity, PathStrategy pathStrategy)
        {
            if (maxCapacity <= 0)
            {
                throw new ArgumentOutOfRangeException("Invalid cache size specified");
            }

            this.maxCapacity  = maxCapacity;
            this.pathStrategy = pathStrategy;
        }