Definition at line 304 of file IOBufferFile.h. References ILOG_ERROR, ILOG_WARN, and Impala::StringReplaceAll(). Referenced by FileExists(), and IOBufferFile(). 00305 { 00306 String thePath = path; 00307 #ifdef WIN32 00308 thePath = StringReplaceAll(thePath, "/", "\\"); 00309 thePath = StringReplaceAll(thePath, "\\\\", "\\", true, 2); 00310 thePath = StringReplaceAll(thePath, "\\.\\", "\\"); // for _fullpath 00311 bool isAbs = (thePath.at(0) == '\\') || (thePath.find(":") != String::npos); 00312 int pathSize = thePath.size(); 00313 00314 static const long maxSimplePath = _MAX_PATH; 00315 if ((pathSize > maxSimplePath) || !isAbs) 00316 { 00317 if (!isAbs) 00318 { 00319 if (pathSize > maxSimplePath) 00320 { 00321 ILOG_ERROR("Relative path over " << maxSimplePath << 00322 " characters long: " << thePath); 00323 return NULL; 00324 } 00325 static const int relPathWarnLength = maxSimplePath / 2; 00326 if (pathSize > relPathWarnLength) 00327 ILOG_WARN("Relative path over " << relPathWarnLength << 00328 " characters long; it may not be possible to" << 00329 " resolve the absolute path for: " << thePath); 00330 00331 // _fullpath cannot deal with long (relative) paths; 00332 // to extend the range of paths we are able to handle we apply 00333 // _fullpath to only part of the relative path (if possible) 00334 String pathHead = thePath; 00335 String pathTail = ""; 00336 int firstSepPos = thePath.find("\\"); 00337 if (firstSepPos != String::npos) 00338 { 00339 int secondSepPos = thePath.find("\\", firstSepPos + 1); 00340 if (secondSepPos != String::npos) 00341 { 00342 pathHead = thePath.substr(0, secondSepPos); 00343 pathTail = thePath.substr(secondSepPos); 00344 } 00345 } 00346 char absPath[maxSimplePath + 1]; 00347 if (!_fullpath(absPath, pathHead.c_str(), maxSimplePath + 1)) 00348 { 00349 ILOG_ERROR("Failed to compose absolute path for " << 00350 thePath << " (" << strerror(errno) << ")"); 00351 return NULL; 00352 } 00353 thePath = String(absPath) + pathTail; 00354 } 00355 00356 static const String longPathPrefix = "\\\\?\\"; 00357 String longPath = longPathPrefix; 00358 if (thePath.substr(0, 2) == "\\\\") 00359 longPath += "UNC" + thePath.substr(1); 00360 else 00361 longPath += thePath; 00362 // Note that this long path specification does not support '..\' 00363 // (nor '.\'), but that we currently do not check for this! 00364 00365 static const int maxLongPath = 32 * 1024; 00366 wchar_t longPathWC[maxLongPath + 1]; // reserve one for null char 00367 for (int i = 0; i < longPath.size(); i++) 00368 longPathWC[i] = (wchar_t) longPath.at(i); 00369 longPathWC[longPath.size()] = L'\0'; 00370 wchar_t modeWC[10]; 00371 for (int i = 0; i < mode.size(); i++) 00372 modeWC[i] = (wchar_t) mode.at(i); 00373 modeWC[mode.size()] = L'\0'; 00374 FILE* fp = _wfopen(longPathWC, modeWC); // non-relative paths only 00375 return fp; 00376 } // if .. 00377 #endif 00378 return fopen(thePath.c_str(), mode.c_str()); 00379 }
Here is the call graph for this function: ![]()
|