/[eiffelstudio]/trunk/eweasel/tests/incr071/file_comparer.e
ViewVC logotype

Contents of /trunk/eweasel/tests/incr071/file_comparer.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 65297 - (show annotations)
Thu Nov 30 20:22:33 2006 UTC (13 years ago) by manus
File size: 3735 byte(s)
Moved from trunk/Src/eweasel to trunk/eweasel so that a simple checkout of the source code is not penalized by the lenghty process of checking out all the tests of eweasel.
1 indexing
2 description: "Find out if two paths corresponds to exactly the same file."
3 date: "$Date$"
4 revision: "$Revision$"
5
6 class
7 FILE_COMPARER
8
9 feature -- Comparison
10
11 same_files (a_path1, a_path2: STRING): BOOLEAN
12 -- Are `a_path1' and `a_path1'
13 require
14 a_path1_not_void: a_path1 /= Void
15 a_path1_not_empty: not a_path1.is_empty
16 a_path2_not_void: a_path2 /= Void
17 a_path2_not_empty: not a_path2.is_empty
18 local
19 l_p1, l_p2: C_STRING
20 do
21 create l_p1.make (a_path1)
22 create l_p2.make (a_path2)
23 Result := c_same_files (l_p1.item, l_p2.item)
24 end
25
26 feature {NONE} -- Implementation
27
28 c_same_files (a_path1, a_path2: POINTER): BOOLEAN is
29 -- Do C paths `a_path1' and `a_path2' represent the same file?
30 require
31 a_path1_not_null: a_path1 /= default_pointer
32 a_path2_not_null: a_path2 /= default_pointer
33 external
34 "C inline use %"eif_eiffel.h%""
35 alias
36 "[
37 EIF_BOOLEAN Result = EIF_FALSE;
38 #ifdef EIF_WINDOWS
39 /* To check this, we use `CreateFileA' to open both file, and then using the information
40 * returned by `GetFileInformationByHandle' we can check whether or not they are indeed
41 * the same.
42 * Note: it is important to use the A version of CreateFileA because arguments
43 * are ASCII strings, not unicode. */
44 BY_HANDLE_FILE_INFORMATION l_path1_info, l_path2_info;
45 HANDLE l_path2_file = CreateFileA ($a_path2, GENERIC_READ, FILE_SHARE_READ, NULL,
46 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
47 HANDLE l_path1_file = CreateFileA ($a_path1, GENERIC_READ, FILE_SHARE_READ, NULL,
48 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
49
50 if ((l_path2_file == INVALID_HANDLE_VALUE) || (l_path1_file == INVALID_HANDLE_VALUE)) {
51 /* We do not need the handles anymore, simply close them. Since Microsoft
52 * API accepts INVALID_HANDLE_VALUE we don't check the validity of arguments. */
53 CloseHandle(l_path2_file);
54 CloseHandle(l_path1_file);
55 } else {
56 BOOL success = GetFileInformationByHandle (l_path2_file, &l_path2_info);
57 success = success && GetFileInformationByHandle (l_path1_file, &l_path1_info);
58 /* We do not need the handles anymore, simply close them. */
59 CloseHandle(l_path2_file);
60 CloseHandle(l_path1_file);
61 if (success) {
62 /* Check that `path2' and `path1' do not represent the same file. */
63 if
64 ((l_path2_info.dwVolumeSerialNumber == l_path1_info.dwVolumeSerialNumber) &&
65 (l_path2_info.nFileIndexLow == l_path1_info.nFileIndexLow) &&
66 (l_path2_info.nFileIndexHigh == l_path1_info.nFileIndexHigh))
67 {
68 Result = EIF_TRUE;
69 }
70 }
71 }
72 #else
73 struct stat buf1, buf2;
74 int status;
75 #ifdef HAS_LSTAT
76 status = lstat($a_path1, &buf1);
77 if (status == 0) {
78 /* We found a file, now let's check if it is not a symbolic link. If it is, we use `stat'
79 * to ensure the validity of the link. */
80 if ((buf1.st_mode & S_IFLNK) == S_IFLNK) {
81 status = stat ($a_path1, &buf1);
82 }
83 }
84
85 if (status == 0) {
86 status = lstat($a_path2, &buf2);
87 if (status == 0) {
88 /* We found a file, now let's check if it is not a symbolic link. If it is, we use `stat'
89 * to ensure the validity of the link. */
90 if ((buf2.st_mode & S_IFLNK) == S_IFLNK) {
91 status = stat ($a_path2, &buf2);
92 }
93 }
94 }
95 #else
96 status = stat ($a_path1, &buf1);
97 if (status == 0) {
98 status = stat ($a_path2, &buf2);
99 }
100 #endif
101 if (status == 0) {
102 /* Both files are present, check they represent the same one. */
103 if ((buf1.st_dev == buf2.st_dev) && (buf1.st_ino == buf2.st_ino)) {
104 Result = EIF_TRUE;
105 }
106 }
107 #endif
108 return Result;
109 ]"
110 end
111
112 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23