コード例 #1
0
ファイル: FileUtilities.cs プロジェクト: zlphoenix/roslyn
        internal static Stream OpenAsyncRead(string fullPath)
        {
            Debug.Assert(PathUtilities.IsAbsolute(fullPath));

            return(RethrowExceptionsAsIOException(() => PortableShim.FileStream.Create(fullPath, PortableShim.FileMode.Open, PortableShim.FileAccess.Read, PortableShim.FileShare.Read, 4096, PortableShim.FileOptions.Asynchronous)));
        }
コード例 #2
0
ファイル: FileUtilities.cs プロジェクト: zlphoenix/roslyn
 internal static string ResolveRelativePath(string path, string basePath, string baseDirectory)
 {
     Debug.Assert(baseDirectory == null || PathUtilities.IsAbsolute(baseDirectory));
     return(ResolveRelativePath(PathUtilities.GetPathKind(path), path, basePath, baseDirectory));
 }
コード例 #3
0
ファイル: FileUtilities.cs プロジェクト: zlphoenix/roslyn
        private static string ResolveRelativePath(PathKind kind, string path, string basePath, string baseDirectory)
        {
            switch (kind)
            {
            case PathKind.Empty:
                return(null);

            case PathKind.Relative:
                baseDirectory = GetBaseDirectory(basePath, baseDirectory);
                if (baseDirectory == null)
                {
                    return(null);
                }

                // with no search paths relative paths are relative to the base directory:
                return(PathUtilities.CombinePathsUnchecked(baseDirectory, path));

            case PathKind.RelativeToCurrentDirectory:
                baseDirectory = GetBaseDirectory(basePath, baseDirectory);
                if (baseDirectory == null)
                {
                    return(null);
                }

                if (path.Length == 1)
                {
                    // "."
                    return(baseDirectory);
                }
                else
                {
                    // ".\path"
                    return(PathUtilities.CombinePathsUnchecked(baseDirectory, path));
                }

            case PathKind.RelativeToCurrentParent:
                baseDirectory = GetBaseDirectory(basePath, baseDirectory);
                if (baseDirectory == null)
                {
                    return(null);
                }

                // ".."
                return(PathUtilities.CombinePathsUnchecked(baseDirectory, path));

            case PathKind.RelativeToCurrentRoot:
                string baseRoot;
                if (basePath != null)
                {
                    baseRoot = PathUtilities.GetPathRoot(basePath);
                }
                else if (baseDirectory != null)
                {
                    baseRoot = PathUtilities.GetPathRoot(baseDirectory);
                }
                else
                {
                    return(null);
                }

                if (string.IsNullOrEmpty(baseRoot))
                {
                    return(null);
                }

                Debug.Assert(PathUtilities.IsDirectorySeparator(path[0]));
                Debug.Assert(path.Length == 1 || !PathUtilities.IsDirectorySeparator(path[1]));
                return(PathUtilities.CombinePathsUnchecked(baseRoot, path.Substring(1)));

            case PathKind.RelativeToDriveDirectory:
                // drive relative paths not supported, can't resolve:
                return(null);

            case PathKind.Absolute:
                return(path);

            default:
                throw ExceptionUtilities.UnexpectedValue(kind);
            }
        }