OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 if (failure) | 115 if (failure) |
116 { | 116 { |
117 if (errno == ENOENT) | 117 if (errno == ENOENT) |
118 return result; | 118 return result; |
119 throw RuntimeErrorWithErrno("Unable to stat " + path); | 119 throw RuntimeErrorWithErrno("Unable to stat " + path); |
120 } | 120 } |
121 result.exists = true; | 121 result.exists = true; |
122 result.isFile = S_ISREG(nativeStat.st_mode); | 122 result.isFile = S_ISREG(nativeStat.st_mode); |
123 result.isDirectory = S_ISDIR(nativeStat.st_mode); | 123 result.isDirectory = S_ISDIR(nativeStat.st_mode); |
124 | 124 |
125 /* | 125 #define MSEC_IN_SEC 1000 |
126 * In order to get millisecond resolution for modification times, it's necessa
ry to use the 'stat' structure defined in | 126 #define NSEC_IN_MSEC 1000000 |
127 * POSIX 2008, which has 'struct timespec st_mtim' instead of 'time_t st_mtime
'. Use "#define _POSIX_C_SOURCE 200809L" | 127 // Note: _POSIX_C_SOURCE macro is defined automatically on Linux due to g++ |
128 * before the headers to invoke. The trouble is that not all systems may have
this available, a category that includes | 128 // defining _GNU_SOURCE macro. |
129 * MS Windows, and so we'll need multiple implementations. | 129 #if _POSIX_C_SOURCE >= 200809L |
130 */ | 130 result.lastModified = static_cast<int64_t>(nativeStat.st_mtim.tv_sec) * MSEC_I
N_SEC |
131 result.lastModified = static_cast<int64_t>(nativeStat.st_mtime) * 1000; | 131 + static_cast<int64_t>(nativeStat.st_mtim.tv_nsec) / NSEC
_IN_MSEC; |
| 132 #else |
| 133 result.lastModified = static_cast<int64_t>(nativeStat.st_mtime) * MSEC_IN_SEC; |
| 134 #endif |
132 return result; | 135 return result; |
133 #endif | 136 #endif |
134 } | 137 } |
135 | 138 |
136 std::string DefaultFileSystem::Resolve(const std::string& path) const | 139 std::string DefaultFileSystem::Resolve(const std::string& path) const |
137 { | 140 { |
138 if (basePath == "") | 141 if (basePath == "") |
139 { | 142 { |
140 return path; | 143 return path; |
141 } | 144 } |
(...skipping 17 matching lines...) Expand all Loading... |
159 void DefaultFileSystem::SetBasePath(const std::string& path) | 162 void DefaultFileSystem::SetBasePath(const std::string& path) |
160 { | 163 { |
161 basePath = path; | 164 basePath = path; |
162 | 165 |
163 if ((*basePath.rbegin() == PATH_SEPARATOR)) | 166 if ((*basePath.rbegin() == PATH_SEPARATOR)) |
164 { | 167 { |
165 basePath.resize(basePath.size() - 1); | 168 basePath.resize(basePath.size() - 1); |
166 } | 169 } |
167 } | 170 } |
168 | 171 |
OLD | NEW |