Exemplo n.º 1
0
        public override string GetCanonicalPath(string path, IPathCache cache)
        {
            DirectoryInfo parent = Directory.GetParent(path);

            if (parent != null)
            {
                string name       = Path.GetFileName(path);
                string parentPath = cache.GetCanonicalPath(parent.FullName);
                try
                {
                    string[] entries = Directory.GetFileSystemEntries(parentPath, name);
                    return(entries.Length == 1 ?
                           entries[0] :
                           Path.Combine(parentPath, name));
                }
                catch (Exception)
                {
                    // IO error or security error querying directory.
                    return(Path.Combine(parentPath, name));
                }
            }
            else
            {
                // We are at a root of the filesystem.
                // Convert drive letters, UNC paths etc. to uppercase.
                // On UNIX, this should be "/" or "".
                return(path.ToUpperInvariant());
            }
        }
Exemplo n.º 2
0
 public SolutionForDependencyPathRules(
     IPathCache pathCache,
     IReadOnlyDictionary <ProjectId, IDotNetProject> projectsById)
 {
     _pathCache    = pathCache;
     _projectsById = projectsById;
 }
Exemplo n.º 3
0
 public void Check(IPathCache cache, IAnalysisReportInProgress report)
 {
     foreach (var dependencyRule in _rules)
     {
         cache.Check(dependencyRule, report);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Constructs a canonical path for a file
        /// which doesn't yet exist.
        /// </summary>
        /// <param name="path">Path to canonicalise.</param>
        /// <param name="cache">The PathCache.</param>
        /// <returns>A canonical path.</returns>
        protected static string ConstructCanonicalPath(string path, IPathCache cache)
        {
            DirectoryInfo parent = Directory.GetParent(path);

            return(parent != null?
                   Path.Combine(cache.GetCanonicalPath(parent.FullName), Path.GetFileName(path)) :
                       path.ToUpperInvariant());
        }
Exemplo n.º 5
0
 public override string GetCanonicalPath(string path, IPathCache cache)
 {
     try
     {
         return(GetRealPath(path));
     }
     catch
     {
         // File does not exist
         return(ConstructCanonicalPath(path, cache));
     }
 }
Exemplo n.º 6
0
 public override string GetCanonicalPath(string path, IPathCache cache)
 {
     try
     {
         return(GetRealPath(path));
     }
     catch  // lgtm[cs/catch-of-all-exceptions]
     {
         // File does not exist
         return(ConstructCanonicalPath(path, cache));
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Call GetFinalPathNameByHandle() to get a canonical filename.
        /// Follows symlinks.
        /// </summary>
        ///
        /// <remarks>
        /// GetFinalPathNameByHandle() only works on open file handles,
        /// so if the path doesn't yet exist, construct the path
        /// by appending the filename to the canonical parent directory.
        /// </remarks>
        ///
        /// <param name="path">The path to canonicalise.</param>
        /// <param name="cache">Subquery cache.</param>
        /// <returns>The canonical path.</returns>
        public override string GetCanonicalPath(string path, IPathCache cache)
        {
            using (var hFile = Win32.CreateFile(
                       path,
                       0,
                       Win32.FILE_SHARE_READ | Win32.FILE_SHARE_WRITE,
                       IntPtr.Zero,
                       Win32.OPEN_EXISTING,
                       Win32.FILE_FLAG_BACKUP_SEMANTICS,
                       IntPtr.Zero))
            {
                if (hFile.IsInvalid)
                {
                    // File/directory does not exist.
                    return(ConstructCanonicalPath(path, cache));
                }
                else
                {
                    StringBuilder outPath = new StringBuilder(Win32.MAX_PATH);
                    int           length  = Win32.GetFinalPathNameByHandle(hFile, outPath, outPath.Capacity, 0);
                    if (length >= outPath.Capacity)
                    {
                        // Path length exceeded MAX_PATH.
                        // Possible if target has a long path.
                        outPath = new StringBuilder(length + 1);
                        length  = Win32.GetFinalPathNameByHandle(hFile, outPath, outPath.Capacity, 0);
                    }

                    const int PREAMBLE = 4; // outPath always starts \\?\

                    if (length <= PREAMBLE)
                    {
                        // Failed. GetFinalPathNameByHandle() failed somehow.
                        return(ConstructCanonicalPath(path, cache));
                    }

                    string result = outPath.ToString(PREAMBLE, length - PREAMBLE);  // Trim off leading \\?\

                    return(result.StartsWith("UNC") ?
                           @"\" + result.Substring(3) :
                           result);
                }
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Obtain a canonical path.
 /// </summary>
 /// <param name="path">The path to canonicalise.</param>
 /// <param name="cache">A cache for making subqueries.</param>
 /// <returns>The canonical path.</returns>
 public abstract string GetCanonicalPath(string path, IPathCache cache);
 /// <summary>
 /// Default constructor reads parameters from the environment.
 /// </summary>
 public PathTransformer(IPathCache pathCache) :
     this(pathCache, Environment.GetEnvironmentVariable("CODEQL_PATH_TRANSFORMER") is string file ? File.ReadAllLines(file) : null)