1 : // Copyright 2011 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // A few utility functions for determining if paths refer to the same file
16 : // or not.
17 : #ifndef SYZYGY_CORE_FILE_UTIL_H_
18 : #define SYZYGY_CORE_FILE_UTIL_H_
19 :
20 : #include "base/files/file_path.h"
21 :
22 m : namespace core {
23 :
24 : // Possible return values from this test.
25 m : enum FilePathCompareResult {
26 m : kFilePathCompareError,
27 :
28 : // This is returned of the two file paths are equivalent on this machine.
29 : // That is they both refer to the same file on disk, even if that is via
30 : // junctions or indirection.
31 m : kEquivalentFilePaths,
32 :
33 : // This is returned if the two file paths are guaranteed to refer to different
34 : // files on disk. It does not mean that they are both immediately creatable,
35 : // as there may be part of a directory hierarchy that also needs to be
36 : // created.
37 m : kDistinctFilePaths,
38 :
39 : // This is returned if *neither* of the file paths exist. That is, they
40 : // may very well refer to the same path via filesystem shenanigans, but there
41 : // is no way to know without creating at least one of them.
42 m : kUnableToCompareFilePaths,
43 m : };
44 :
45 : // Compares two paths, determining if they both refer to the same object.
46 : //
47 : // This test is read-only, and as such it is possible for the test to fail.
48 : // This can occur if neither of the paths exist, yet they do in fact refer to
49 : // the same file via some aliasing mechanism (junctions, mounts, etc). In that
50 : // case this will return kUnableToCompare. To attempt a comparison in this case
51 : // both paths will be converted to absolute paths using the current working
52 : // directory. If the paths are identical we can infer that the files will be
53 : // the same (but not vice versa). To get a solid answer at least one of the
54 : // paths must exist.
55 : //
56 : // @param path1 the first path to compare.
57 : // @param path2 the second path to compare.
58 : // @returns a FilePathCompareResult, described above.
59 m : FilePathCompareResult CompareFilePaths(const base::FilePath& path1,
60 m : const base::FilePath& path2);
61 :
62 : // A list of known file types.
63 m : enum FileType {
64 m : kUnknownFileType,
65 m : kPdbFileType,
66 : // X86 COFF files.
67 m : kCoffFileType,
68 : // X86 PE files.
69 m : kPeFileType,
70 m : kArchiveFileType,
71 m : kResourceFileType,
72 m : kImportDefinitionFileType,
73 : // Intermediate code object files.
74 m : kAnonymousCoffFileType,
75 : // X86-64 COFF files.
76 m : kCoff64FileType,
77 m : };
78 :
79 : // @{
80 : // Guesses the type of the given file. This does not do extensive validation.
81 : // There may be false positives, but there will be no false negatives.
82 : // @param path The path of the file whose type is to be determined.
83 : // @param contents The contents of the file.
84 : // @param length The length of the file contents.
85 : // @param file_type Will be populated with the type of the file.
86 : // @returns true on success, false on failure. On success sets @p file_type.
87 m : bool GuessFileType(const base::FilePath& path, FileType* file_type);
88 m : bool GuessFileType(const uint8* contents, size_t length, FileType* file_type);
89 : // @}
90 :
91 m : } // namespace core
92 :
93 : #endif // SYZYGY_CORE_FILE_UTIL_H_
|