Beispiel #1
0
        public void Equality()
        {
            var          pt = new PathTable();
            AbsolutePath a1 = AbsolutePath.Create(pt, @"/usr/local");
            AbsolutePath a2 = AbsolutePath.Create(pt, @"/usr/local");
            AbsolutePath a3 = AbsolutePath.Create(pt, @"/usr/local/bin");

            XAssert.IsTrue(a1.Equals(a1));
            XAssert.IsTrue(a1.Equals(a2));
            XAssert.IsTrue(a2.Equals(a1));
            XAssert.IsFalse(a1.Equals(a3));
            XAssert.IsFalse(a2.Equals(a3));

            XAssert.IsTrue(a1.Equals((object)a1));
            XAssert.IsTrue(a1.Equals((object)a2));
            XAssert.IsTrue(a2.Equals((object)a1));
            XAssert.IsFalse(a1.Equals((object)a3));
            XAssert.IsFalse(a2.Equals((object)a3));

            XAssert.IsTrue(a1 == a2);
            XAssert.IsTrue(a2 == a1);
            XAssert.IsFalse(a1 == a3);
            XAssert.IsFalse(a2 == a3);

            XAssert.IsFalse(a1 != a2);
            XAssert.IsFalse(a2 != a1);
            XAssert.IsTrue(a1 != a3);
            XAssert.IsTrue(a2 != a3);

            int h1 = a1.GetHashCode();
            int h2 = a2.GetHashCode();

            XAssert.AreEqual(h1, h2);

            AbsolutePath a3DifferentCase = AbsolutePath.Create(pt, @"/usr/local/Bin");

            if (OperatingSystemHelper.IsPathComparisonCaseSensitive)
            {
                XAssert.IsFalse(a3.Equals(a3DifferentCase));
                XAssert.IsFalse(a3.Equals((object)a3DifferentCase));
                XAssert.IsFalse(a3 == a3DifferentCase);
            }
            else
            {
                XAssert.IsTrue(a3.Equals(a3DifferentCase));
                XAssert.IsTrue(a3.Equals((object)a3DifferentCase));
                XAssert.IsTrue(a3 == a3DifferentCase);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Checks if a path matches the filter
        /// </summary>
        internal bool PathMatches(AbsolutePath path, PathTable pathTable)
        {
            switch (m_matchMode)
            {
            case MatchMode.FilePath:
                return(path.Equals(m_path));

            case MatchMode.WithinDirectory:
                return(path.GetParent(pathTable).Equals(m_path));

            case MatchMode.WithinDirectoryAndSubdirectories:
                return(path.IsWithin(pathTable, m_path));

            case MatchMode.PathPrefixWildcard:
                return(path.ToString(pathTable).EndsWith(m_pathWildcardUpper, StringComparison.OrdinalIgnoreCase));

            case MatchMode.PathSuffixWildcard:
                return(path.ToString(pathTable).StartsWith(m_pathWildcardUpper, StringComparison.OrdinalIgnoreCase));

            case MatchMode.PathPrefixAndSuffixWildcard:
                return(path.ToString(pathTable).ToUpperInvariant().Contains(m_pathWildcardUpper));

            default:
                throw Contract.AssertFailure("Unknown Match Mode");
            }
        }
Beispiel #3
0
 /// <inheridoc/>
 public bool Equals(Artifact other)
 {
     return(m_fileArtifact.Equals(other.m_fileArtifact) &&
            m_absolutePath.Equals(other.m_absolutePath) &&
            m_directoryArtifact.Equals(other.m_directoryArtifact) &&
            Kind == other.Kind &&
            Type == other.Type);
 }
Beispiel #4
0
 public override bool Equals(object obj)
 {
     if (obj == null || !(obj is IDevice))
     {
         return(false);
     }
     return(AbsolutePath.Equals(((IDevice)obj).AbsolutePath));
 }
        public void Equality()
        {
            var          pt = new PathTable();
            AbsolutePath a1 = AbsolutePath.Create(pt, @"/usr/local");
            AbsolutePath a2 = AbsolutePath.Create(pt, @"/usr/local");
            AbsolutePath a3 = AbsolutePath.Create(pt, @"/usr/local/bin");

            XAssert.IsTrue(a1.Equals(a1));
            XAssert.IsTrue(a1.Equals(a2));
            XAssert.IsTrue(a2.Equals(a1));
            XAssert.IsFalse(a1.Equals(a3));
            XAssert.IsFalse(a2.Equals(a3));

            XAssert.IsTrue(a1.Equals((object)a1));
            XAssert.IsTrue(a1.Equals((object)a2));
            XAssert.IsTrue(a2.Equals((object)a1));
            XAssert.IsFalse(a1.Equals((object)a3));
            XAssert.IsFalse(a2.Equals((object)a3));

            XAssert.IsTrue(a1 == a2);
            XAssert.IsTrue(a2 == a1);
            XAssert.IsFalse(a1 == a3);
            XAssert.IsFalse(a2 == a3);

            XAssert.IsFalse(a1 != a2);
            XAssert.IsFalse(a2 != a1);
            XAssert.IsTrue(a1 != a3);
            XAssert.IsTrue(a2 != a3);

            int h1 = a1.GetHashCode();
            int h2 = a2.GetHashCode();

            XAssert.AreEqual(h1, h2);

            // TODO: Case insensitive comparisons, currently we do not differentiate between casing!
            AbsolutePath a3DifferentCase = AbsolutePath.Create(pt, @"/usr/local/Bin");

            XAssert.IsTrue(a3.Equals(a3DifferentCase));
            XAssert.IsTrue(a3.Equals((object)a3DifferentCase));
            XAssert.IsTrue(a3 == a3DifferentCase);
        }
Beispiel #6
0
        public void Equality()
        {
            var          pt = new PathTable();
            AbsolutePath a1 = AbsolutePath.Create(pt, @"c:\AAA\CCC");
            AbsolutePath a2 = AbsolutePath.Create(pt, @"c:\AAA\CCC");
            AbsolutePath a3 = AbsolutePath.Create(pt, @"c:\BBB\CCC");

            XAssert.IsTrue(a1.Equals(a1));
            XAssert.IsTrue(a1.Equals(a2));
            XAssert.IsTrue(a2.Equals(a1));
            XAssert.IsFalse(a1.Equals(a3));
            XAssert.IsFalse(a2.Equals(a3));

            XAssert.IsTrue(a1.Equals((object)a1));
            XAssert.IsTrue(a1.Equals((object)a2));
            XAssert.IsTrue(a2.Equals((object)a1));
            XAssert.IsFalse(a1.Equals((object)a3));
            XAssert.IsFalse(a2.Equals((object)a3));

            XAssert.IsTrue(a1 == a2);
            XAssert.IsTrue(a2 == a1);
            XAssert.IsFalse(a1 == a3);
            XAssert.IsFalse(a2 == a3);

            XAssert.IsFalse(a1 != a2);
            XAssert.IsFalse(a2 != a1);
            XAssert.IsTrue(a1 != a3);
            XAssert.IsTrue(a2 != a3);

            int h1 = a1.GetHashCode();
            int h2 = a2.GetHashCode();

            XAssert.AreEqual(h1, h2);

            // Case insensitive comparisons
            AbsolutePath a3DifferentCase = AbsolutePath.Create(pt, @"C:\bbb\ccc");

            XAssert.IsTrue(a3.Equals(a3DifferentCase));
            XAssert.IsTrue(a3.Equals((object)a3DifferentCase));
            XAssert.IsTrue(a3 == a3DifferentCase);
        }
Beispiel #7
0
        /// <inheridoc />
        public bool Equals(ParsedPath other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(m_absolutePath.Equals(other.m_absolutePath) && m_packageRelativePath.Equals(other.m_packageRelativePath) &&
                   m_fileRelativePath.Equals(other.m_fileRelativePath) && m_parentCount == other.m_parentCount);
        }
Beispiel #8
0
 /// <inheritdoc />
 public bool Equals(TokenData other)
 {
     return(other.Position == Position && other.Line == Line && Text.Equals(other.Text) && Path.Equals(other.Path));
 }
Beispiel #9
0
 /// <inheritdoc />
 public bool Equals(LocationData other)
 {
     return(other.Position == Position && other.Line == Line && Path.Equals(other.Path));
 }
Beispiel #10
0
 /// <inheritdoc />
 public bool Equals(ExpandedTokenData <TChars> other)
 {
     return(other.Position == Position && other.Line == Line && Text.Equals(other.Text) && Path.Equals(other.Path));
 }
Beispiel #11
0
 /// <inheritdoc/>
 public bool Equals(UniversalLocation other)
 {
     return(m_absolutePath.Equals(other.m_absolutePath) && m_absolutePosition == other.m_absolutePosition && m_lineInfo.Equals(other.m_lineInfo));
 }
Beispiel #12
0
        public override int Analyze()
        {
            HashSet <(CaseInsensitiveString toolPath, AbsolutePath directoryPath)> toolAndEnumerations = new HashSet <(CaseInsensitiveString toolPath, AbsolutePath directoryPath)>();
            HashSet <AbsolutePath> enumeratedDirectories = new HashSet <AbsolutePath>();
            HashSet <string>       enumerationTools      = new HashSet <string>(OperatingSystemHelper.PathComparer);

            foreach (var observedInputEntry in m_observedInputsMap)
            {
                var pip            = observedInputEntry.Key;
                var observedInputs = observedInputEntry.Value;

                if (!m_toolEnumerationMap.ContainsKey(pip))
                {
                    continue;
                }

                var reportedFileAccesses = m_toolEnumerationMap[pip];

                foreach (var observedInput in observedInputs)
                {
                    if (observedInput.Type == ObservedInputType.DirectoryEnumeration)
                    {
                        enumeratedDirectories.Add(observedInput.Path);
                    }
                }

                foreach (var reportedFileAccess in reportedFileAccesses)
                {
                    var path = reportedFileAccess.ManifestPath;
                    if (reportedFileAccess.Path != null)
                    {
                        if (!AbsolutePath.TryCreate(PathTable, reportedFileAccess.Path, out path))
                        {
                            continue;
                        }
                    }

                    if (!enumeratedDirectories.Contains(path))
                    {
                        continue;
                    }

                    enumerationTools.Add(reportedFileAccess.Process.Path);
                    toolAndEnumerations.Add((new CaseInsensitiveString(reportedFileAccess.Process.Path), path));
                }
            }

            var toolEnumerationList = toolAndEnumerations.ToList();

            toolEnumerationList.Sort((v1, v2) =>
            {
                var result = OperatingSystemHelper.PathComparer.Compare(v1.toolPath.Value, v2.toolPath.Value);
                if (result != 0)
                {
                    return(result);
                }

                return(PathTable.ExpandedPathComparer.Compare(v1.Item2, v2.Item2));
            });

            using (var outputStream = File.Create(OutputFilePath, bufferSize: 64 << 10 /* 64 KB */))
            {
                using (var writer = new StreamWriter(outputStream))
                {
                    writer.WriteLine("Directory Enumeration Tools:");
                    foreach (var tool in enumerationTools.OrderBy(s => s, OperatingSystemHelper.PathComparer))
                    {
                        writer.WriteLine(tool);
                    }

                    writer.WriteLine();
                    writer.WriteLine("Enumerations By Tool:");

                    CaseInsensitiveString last = new CaseInsensitiveString(string.Empty);
                    foreach (var toolEnumerationEntry in toolEnumerationList)
                    {
                        var toolPath      = toolEnumerationEntry.Item1;
                        var directoryPath = toolEnumerationEntry.Item2;
                        if (!last.Equals(toolPath))
                        {
                            last = toolPath;
                            writer.WriteLine();
                            writer.WriteLine("Tool: {0}", toolPath.Value);
                        }

                        writer.WriteLine("  Directory: {0}", directoryPath.ToString(PathTable));
                    }

                    toolEnumerationList.Sort((v1, v2) =>
                    {
                        var result = PathTable.ExpandedPathComparer.Compare(v1.Item2, v2.Item2);
                        if (result != 0)
                        {
                            return(result);
                        }

                        return(OperatingSystemHelper.PathComparer.Compare(v1.Item1.Value, v2.Item1.Value));
                    });

                    writer.WriteLine();
                    writer.WriteLine("Enumerations By Directory:");

                    AbsolutePath lastDirectory = AbsolutePath.Invalid;
                    foreach (var toolEnumerationEntry in toolEnumerationList)
                    {
                        var toolPath      = toolEnumerationEntry.toolPath;
                        var directoryPath = toolEnumerationEntry.directoryPath;
                        if (!lastDirectory.Equals(directoryPath))
                        {
                            lastDirectory = directoryPath;
                            writer.WriteLine();
                            writer.WriteLine("Directory: {0}", directoryPath.ToString(PathTable));
                        }

                        writer.WriteLine("  Tool: {0}", toolPath.Value);
                    }
                }
            }

            return(0);
        }