| 214 | |
| 215 | |
| 216 | static path_key_entry * path_key( OBJECT * const path, |
| 217 | int const known_to_be_canonic ) |
| 218 | { |
| 219 | path_key_entry * result; |
| 220 | int found; |
| 221 | |
| 222 | if ( !path_key_cache ) |
| 223 | path_key_cache = hashinit( sizeof( path_key_entry ), "path to key" ); |
| 224 | |
| 225 | result = (path_key_entry *)hash_insert( path_key_cache, path, &found ); |
| 226 | if ( !found ) |
| 227 | { |
| 228 | OBJECT * normalized; |
| 229 | int normalized_size; |
| 230 | path_key_entry * nresult; |
| 231 | result->path = path; |
| 232 | { |
| 233 | string buf[ 1 ]; |
| 234 | string_copy( buf, object_str( path ) ); |
| 235 | normalize_path( buf ); |
| 236 | normalized = object_new( buf->value ); |
| 237 | normalized_size = buf->size; |
| 238 | string_free( buf ); |
| 239 | } |
| 240 | nresult = (path_key_entry *)hash_insert( path_key_cache, normalized, |
| 241 | &found ); |
| 242 | if ( !found || nresult == result ) |
| 243 | { |
| 244 | nresult->path = normalized; |
| 245 | if ( known_to_be_canonic ) |
| 246 | nresult->key = object_copy( path ); |
| 247 | else |
| 248 | { |
| 249 | string canonic_path[ 1 ]; |
| 250 | string_new( canonic_path ); |
| 251 | if ( canonicWindowsPath( object_str( normalized ), normalized_size, |
| 252 | canonic_path ) ) |
| 253 | nresult->exists = 1; |
| 254 | else |
| 255 | nresult->exists = 0; |
| 256 | nresult->key = object_new( canonic_path->value ); |
| 257 | string_free( canonic_path ); |
| 258 | } |
| 259 | } |
| 260 | else |
| 261 | object_free( normalized ); |
| 262 | if ( nresult != result ) |
| 263 | { |
| 264 | result->path = object_copy( path ); |
| 265 | result->key = object_copy( nresult->key ); |
| 266 | result->exists = nresult->exists; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | return result; |
| 271 | } |
| 272 | |
| 273 |
no test coverage detected