1 : // Copyright 2011 Google Inc.
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/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 FilePath& path1,
60 m : const FilePath& path2);
61 :
62 m : } // namespace core
63 :
64 : #endif // SYZYGY_CORE_FILE_UTIL_H_
|