Path.inc revision fa2bbb31fae64bc8cc3dc3736f5465d3ddba1704
1//===- llvm/Support/Win32/Path.cpp - Win32 Path Implementation ---*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file provides the Win32 specific implementation of the Path class. 11// 12//===----------------------------------------------------------------------===// 13 14//===----------------------------------------------------------------------===// 15//=== WARNING: Implementation here must contain only generic Win32 code that 16//=== is guaranteed to work on *all* Win32 variants. 17//===----------------------------------------------------------------------===// 18 19#include "Windows.h" 20#include <cstdio> 21#include <malloc.h> 22 23// We need to undo a macro defined in Windows.h, otherwise we won't compile: 24#undef GetCurrentDirectory 25 26// Windows happily accepts either forward or backward slashes, though any path 27// returned by a Win32 API will have backward slashes. As LLVM code basically 28// assumes forward slashes are used, backward slashs are converted where they 29// can be introduced into a path. 30// 31// Another invariant is that a path ends with a slash if and only if the path 32// is a root directory. Any other use of a trailing slash is stripped. Unlike 33// in Unix, Windows has a rather complicated notion of a root path and this 34// invariant helps simply the code. 35 36static void FlipBackSlashes(std::string& s) { 37 for (size_t i = 0; i < s.size(); i++) 38 if (s[i] == '\\') 39 s[i] = '/'; 40} 41 42namespace llvm { 43namespace sys { 44 45const char PathSeparator = ';'; 46 47StringRef Path::GetEXESuffix() { 48 return "exe"; 49} 50 51Path::Path(llvm::StringRef p) 52 : path(p) { 53 FlipBackSlashes(path); 54} 55 56Path::Path(const char *StrStart, unsigned StrLen) 57 : path(StrStart, StrLen) { 58 FlipBackSlashes(path); 59} 60 61Path& 62Path::operator=(StringRef that) { 63 path.assign(that.data(), that.size()); 64 FlipBackSlashes(path); 65 return *this; 66} 67 68bool 69Path::isValid() const { 70 if (path.empty()) 71 return false; 72 73 size_t len = path.size(); 74 // If there is a null character, it and all its successors are ignored. 75 size_t pos = path.find_first_of('\0'); 76 if (pos != std::string::npos) 77 len = pos; 78 79 // If there is a colon, it must be the second character, preceded by a letter 80 // and followed by something. 81 pos = path.rfind(':',len); 82 size_t rootslash = 0; 83 if (pos != std::string::npos) { 84 if (pos != 1 || !isalpha(static_cast<unsigned char>(path[0])) || len < 3) 85 return false; 86 rootslash = 2; 87 } 88 89 // Look for a UNC path, and if found adjust our notion of the root slash. 90 if (len > 3 && path[0] == '/' && path[1] == '/') { 91 rootslash = path.find('/', 2); 92 if (rootslash == std::string::npos) 93 rootslash = 0; 94 } 95 96 // Check for illegal characters. 97 if (path.find_first_of("\\<>\"|\001\002\003\004\005\006\007\010\011\012" 98 "\013\014\015\016\017\020\021\022\023\024\025\026" 99 "\027\030\031\032\033\034\035\036\037") 100 != std::string::npos) 101 return false; 102 103 // Remove trailing slash, unless it's a root slash. 104 if (len > rootslash+1 && path[len-1] == '/') 105 path.erase(--len); 106 107 // Check each component for legality. 108 for (pos = 0; pos < len; ++pos) { 109 // A component may not end in a space. 110 if (path[pos] == ' ') { 111 if (pos+1 == len || path[pos+1] == '/' || path[pos+1] == '\0') 112 return false; 113 } 114 115 // A component may not end in a period. 116 if (path[pos] == '.') { 117 if (pos+1 == len || path[pos+1] == '/') { 118 // Unless it is the pseudo-directory "."... 119 if (pos == 0 || path[pos-1] == '/' || path[pos-1] == ':') 120 return true; 121 // or "..". 122 if (pos > 0 && path[pos-1] == '.') { 123 if (pos == 1 || path[pos-2] == '/' || path[pos-2] == ':') 124 return true; 125 } 126 return false; 127 } 128 } 129 } 130 131 return true; 132} 133 134void Path::makeAbsolute() { 135 TCHAR FullPath[MAX_PATH + 1] = {0}; 136 LPTSTR FilePart = NULL; 137 138 DWORD RetLength = ::GetFullPathNameA(path.c_str(), 139 sizeof(FullPath)/sizeof(FullPath[0]), 140 FullPath, &FilePart); 141 142 if (0 == RetLength) { 143 // FIXME: Report the error GetLastError() 144 assert(0 && "Unable to make absolute path!"); 145 } else if (RetLength > MAX_PATH) { 146 // FIXME: Report too small buffer (needed RetLength bytes). 147 assert(0 && "Unable to make absolute path!"); 148 } else { 149 path = FullPath; 150 } 151} 152 153static Path *TempDirectory; 154 155Path 156Path::GetTemporaryDirectory(std::string* ErrMsg) { 157 if (TempDirectory) { 158#if defined(_MSC_VER) 159 // Visual Studio gets confused and emits a diagnostic about calling exists, 160 // even though this is the implementation for PathV1. Temporarily 161 // disable the deprecated warning message 162 #pragma warning(push) 163 #pragma warning(disable:4996) 164#endif 165 assert(TempDirectory->exists() && "Who has removed TempDirectory?"); 166#if defined(_MSC_VER) 167 #pragma warning(pop) 168#endif 169 return *TempDirectory; 170 } 171 172 char pathname[MAX_PATH]; 173 if (!GetTempPath(MAX_PATH, pathname)) { 174 if (ErrMsg) 175 *ErrMsg = "Can't determine temporary directory"; 176 return Path(); 177 } 178 179 Path result; 180 result.set(pathname); 181 182 // Append a subdirectory based on our process id so multiple LLVMs don't 183 // step on each other's toes. 184#ifdef __MINGW32__ 185 // Mingw's Win32 header files are broken. 186 sprintf(pathname, "LLVM_%u", unsigned(GetCurrentProcessId())); 187#else 188 sprintf(pathname, "LLVM_%u", GetCurrentProcessId()); 189#endif 190 result.appendComponent(pathname); 191 192 // If there's a directory left over from a previous LLVM execution that 193 // happened to have the same process id, get rid of it. 194 result.eraseFromDisk(true); 195 196 // And finally (re-)create the empty directory. 197 result.createDirectoryOnDisk(false); 198 TempDirectory = new Path(result); 199 return *TempDirectory; 200} 201 202Path 203Path::GetCurrentDirectory() { 204 char pathname[MAX_PATH]; 205 ::GetCurrentDirectoryA(MAX_PATH,pathname); 206 return Path(pathname); 207} 208 209/// GetMainExecutable - Return the path to the main executable, given the 210/// value of argv[0] from program startup. 211Path Path::GetMainExecutable(const char *argv0, void *MainAddr) { 212 char pathname[MAX_PATH]; 213 DWORD ret = ::GetModuleFileNameA(NULL, pathname, MAX_PATH); 214 return ret != MAX_PATH ? Path(pathname) : Path(); 215} 216 217 218// FIXME: the above set of functions don't map to Windows very well. 219 220bool 221Path::exists() const { 222 DWORD attr = GetFileAttributes(path.c_str()); 223 return attr != INVALID_FILE_ATTRIBUTES; 224} 225 226bool 227Path::isDirectory() const { 228 DWORD attr = GetFileAttributes(path.c_str()); 229 return (attr != INVALID_FILE_ATTRIBUTES) && 230 (attr & FILE_ATTRIBUTE_DIRECTORY); 231} 232 233bool 234Path::isSymLink() const { 235 DWORD attributes = GetFileAttributes(path.c_str()); 236 237 if (attributes == INVALID_FILE_ATTRIBUTES) 238 // There's no sane way to report this :(. 239 assert(0 && "GetFileAttributes returned INVALID_FILE_ATTRIBUTES"); 240 241 // This isn't exactly what defines a NTFS symlink, but it is only true for 242 // paths that act like a symlink. 243 return attributes & FILE_ATTRIBUTE_REPARSE_POINT; 244} 245 246bool 247Path::canRead() const { 248 // FIXME: take security attributes into account. 249 DWORD attr = GetFileAttributes(path.c_str()); 250 return attr != INVALID_FILE_ATTRIBUTES; 251} 252 253bool 254Path::canWrite() const { 255 // FIXME: take security attributes into account. 256 DWORD attr = GetFileAttributes(path.c_str()); 257 return (attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_READONLY); 258} 259 260bool 261Path::canExecute() const { 262 // FIXME: take security attributes into account. 263 DWORD attr = GetFileAttributes(path.c_str()); 264 return attr != INVALID_FILE_ATTRIBUTES; 265} 266 267bool 268Path::isRegularFile() const { 269 bool res; 270 if (fs::is_regular_file(path, res)) 271 return false; 272 return res; 273} 274 275const FileStatus * 276PathWithStatus::getFileStatus(bool update, std::string *ErrStr) const { 277 if (!fsIsValid || update) { 278 WIN32_FILE_ATTRIBUTE_DATA fi; 279 if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi)) { 280 MakeErrMsg(ErrStr, "getStatusInfo():" + std::string(path) + 281 ": Can't get status: "); 282 return 0; 283 } 284 285 status.fileSize = fi.nFileSizeHigh; 286 status.fileSize <<= sizeof(fi.nFileSizeHigh)*8; 287 status.fileSize += fi.nFileSizeLow; 288 289 status.mode = fi.dwFileAttributes & FILE_ATTRIBUTE_READONLY ? 0555 : 0777; 290 status.user = 9999; // Not applicable to Windows, so... 291 status.group = 9999; // Not applicable to Windows, so... 292 293 // FIXME: this is only unique if the file is accessed by the same file path. 294 // How do we do this for C:\dir\file and ..\dir\file ? Unix has inode 295 // numbers, but the concept doesn't exist in Windows. 296 status.uniqueID = 0; 297 for (unsigned i = 0; i < path.length(); ++i) 298 status.uniqueID += path[i]; 299 300 ULARGE_INTEGER ui; 301 ui.LowPart = fi.ftLastWriteTime.dwLowDateTime; 302 ui.HighPart = fi.ftLastWriteTime.dwHighDateTime; 303 status.modTime.fromWin32Time(ui.QuadPart); 304 305 status.isDir = fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; 306 fsIsValid = true; 307 } 308 return &status; 309} 310 311bool Path::makeReadableOnDisk(std::string* ErrMsg) { 312 // All files are readable on Windows (ignoring security attributes). 313 return false; 314} 315 316bool Path::makeWriteableOnDisk(std::string* ErrMsg) { 317 DWORD attr = GetFileAttributes(path.c_str()); 318 319 // If it doesn't exist, we're done. 320 if (attr == INVALID_FILE_ATTRIBUTES) 321 return false; 322 323 if (attr & FILE_ATTRIBUTE_READONLY) { 324 if (!SetFileAttributes(path.c_str(), attr & ~FILE_ATTRIBUTE_READONLY)) { 325 MakeErrMsg(ErrMsg, std::string(path) + ": Can't make file writable: "); 326 return true; 327 } 328 } 329 return false; 330} 331 332bool 333Path::getDirectoryContents(std::set& result, std::string* ErrMsg) const { 334 WIN32_FILE_ATTRIBUTE_DATA fi; 335 if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi)) { 336 MakeErrMsg(ErrMsg, path + ": can't get status of file"); 337 return true; 338 } 339 340 if (!(fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { 341 if (ErrMsg) 342 *ErrMsg = path + ": not a directory"; 343 return true; 344 } 345 346 result.clear(); 347 WIN32_FIND_DATA fd; 348 std::string searchpath = path; 349 if (path.size() == 0 || searchpath[path.size()-1] == '/') 350 searchpath += "*"; 351 else 352 searchpath += "/*"; 353 354 HANDLE h = FindFirstFile(searchpath.c_str(), &fd); 355 if (h == INVALID_HANDLE_VALUE) { 356 if (GetLastError() == ERROR_FILE_NOT_FOUND) 357 return true; // not really an error, now is it? 358 MakeErrMsg(ErrMsg, path + ": Can't read directory: "); 359 return true; 360 } 361 362 do { 363 if (fd.cFileName[0] == '.') 364 continue; 365 Path aPath(path); 366 aPath.appendComponent(&fd.cFileName[0]); 367 result.insert(aPath); 368 } while (FindNextFile(h, &fd)); 369 370 DWORD err = GetLastError(); 371 FindClose(h); 372 if (err != ERROR_NO_MORE_FILES) { 373 SetLastError(err); 374 MakeErrMsg(ErrMsg, path + ": Can't read directory: "); 375 return true; 376 } 377 return false; 378} 379 380bool 381Path::set(StringRef a_path) { 382 if (a_path.empty()) 383 return false; 384 std::string save(path); 385 path = a_path; 386 FlipBackSlashes(path); 387 if (!isValid()) { 388 path = save; 389 return false; 390 } 391 return true; 392} 393 394bool 395Path::appendComponent(StringRef name) { 396 if (name.empty()) 397 return false; 398 std::string save(path); 399 if (!path.empty()) { 400 size_t last = path.size() - 1; 401 if (path[last] != '/') 402 path += '/'; 403 } 404 path += name; 405 if (!isValid()) { 406 path = save; 407 return false; 408 } 409 return true; 410} 411 412bool 413Path::eraseComponent() { 414 size_t slashpos = path.rfind('/',path.size()); 415 if (slashpos == path.size() - 1 || slashpos == std::string::npos) 416 return false; 417 std::string save(path); 418 path.erase(slashpos); 419 if (!isValid()) { 420 path = save; 421 return false; 422 } 423 return true; 424} 425 426bool 427Path::eraseSuffix() { 428 size_t dotpos = path.rfind('.',path.size()); 429 size_t slashpos = path.rfind('/',path.size()); 430 if (dotpos != std::string::npos) { 431 if (slashpos == std::string::npos || dotpos > slashpos+1) { 432 std::string save(path); 433 path.erase(dotpos, path.size()-dotpos); 434 if (!isValid()) { 435 path = save; 436 return false; 437 } 438 return true; 439 } 440 } 441 return false; 442} 443 444inline bool PathMsg(std::string* ErrMsg, const char* pathname, const char*msg) { 445 if (ErrMsg) 446 *ErrMsg = std::string(pathname) + ": " + std::string(msg); 447 return true; 448} 449 450bool 451Path::createDirectoryOnDisk(bool create_parents, std::string* ErrMsg) { 452 // Get a writeable copy of the path name 453 size_t len = path.length(); 454 char *pathname = reinterpret_cast<char *>(_alloca(len+2)); 455 path.copy(pathname, len); 456 pathname[len] = 0; 457 458 // Make sure it ends with a slash. 459 if (len == 0 || pathname[len - 1] != '/') { 460 pathname[len] = '/'; 461 pathname[++len] = 0; 462 } 463 464 // Determine starting point for initial / search. 465 char *next = pathname; 466 if (pathname[0] == '/' && pathname[1] == '/') { 467 // Skip host name. 468 next = strchr(pathname+2, '/'); 469 if (next == NULL) 470 return PathMsg(ErrMsg, pathname, "badly formed remote directory"); 471 472 // Skip share name. 473 next = strchr(next+1, '/'); 474 if (next == NULL) 475 return PathMsg(ErrMsg, pathname,"badly formed remote directory"); 476 477 next++; 478 if (*next == 0) 479 return PathMsg(ErrMsg, pathname, "badly formed remote directory"); 480 481 } else { 482 if (pathname[1] == ':') 483 next += 2; // skip drive letter 484 if (*next == '/') 485 next++; // skip root directory 486 } 487 488 // If we're supposed to create intermediate directories 489 if (create_parents) { 490 // Loop through the directory components until we're done 491 while (*next) { 492 next = strchr(next, '/'); 493 *next = 0; 494 if (!CreateDirectory(pathname, NULL) && 495 GetLastError() != ERROR_ALREADY_EXISTS) 496 return MakeErrMsg(ErrMsg, 497 std::string(pathname) + ": Can't create directory: "); 498 *next++ = '/'; 499 } 500 } else { 501 // Drop trailing slash. 502 pathname[len-1] = 0; 503 if (!CreateDirectory(pathname, NULL) && 504 GetLastError() != ERROR_ALREADY_EXISTS) { 505 return MakeErrMsg(ErrMsg, std::string(pathname) + 506 ": Can't create directory: "); 507 } 508 } 509 return false; 510} 511 512bool 513Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const { 514 WIN32_FILE_ATTRIBUTE_DATA fi; 515 if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi)) 516 return true; 517 518 if (fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { 519 // If it doesn't exist, we're done. 520 bool Exists; 521 if (fs::exists(path, Exists) || !Exists) 522 return false; 523 524 char *pathname = reinterpret_cast<char *>(_alloca(path.length()+3)); 525 int lastchar = path.length() - 1 ; 526 path.copy(pathname, lastchar+1); 527 528 // Make path end with '/*'. 529 if (pathname[lastchar] != '/') 530 pathname[++lastchar] = '/'; 531 pathname[lastchar+1] = '*'; 532 pathname[lastchar+2] = 0; 533 534 if (remove_contents) { 535 WIN32_FIND_DATA fd; 536 HANDLE h = FindFirstFile(pathname, &fd); 537 538 // It's a bad idea to alter the contents of a directory while enumerating 539 // its contents. So build a list of its contents first, then destroy them. 540 541 if (h != INVALID_HANDLE_VALUE) { 542 std::vector<Path> list; 543 544 do { 545 if (strcmp(fd.cFileName, ".") == 0) 546 continue; 547 if (strcmp(fd.cFileName, "..") == 0) 548 continue; 549 550 Path aPath(path); 551 aPath.appendComponent(&fd.cFileName[0]); 552 list.push_back(aPath); 553 } while (FindNextFile(h, &fd)); 554 555 DWORD err = GetLastError(); 556 FindClose(h); 557 if (err != ERROR_NO_MORE_FILES) { 558 SetLastError(err); 559 return MakeErrMsg(ErrStr, path + ": Can't read directory: "); 560 } 561 562 for (std::vector<Path>::iterator I = list.begin(); I != list.end(); 563 ++I) { 564 Path &aPath = *I; 565 aPath.eraseFromDisk(true); 566 } 567 } else { 568 if (GetLastError() != ERROR_FILE_NOT_FOUND) 569 return MakeErrMsg(ErrStr, path + ": Can't read directory: "); 570 } 571 } 572 573 pathname[lastchar] = 0; 574 if (!RemoveDirectory(pathname)) 575 return MakeErrMsg(ErrStr, 576 std::string(pathname) + ": Can't destroy directory: "); 577 return false; 578 } else { 579 // Read-only files cannot be deleted on Windows. Must remove the read-only 580 // attribute first. 581 if (fi.dwFileAttributes & FILE_ATTRIBUTE_READONLY) { 582 if (!SetFileAttributes(path.c_str(), 583 fi.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY)) 584 return MakeErrMsg(ErrStr, path + ": Can't destroy file: "); 585 } 586 587 if (!DeleteFile(path.c_str())) 588 return MakeErrMsg(ErrStr, path + ": Can't destroy file: "); 589 return false; 590 } 591} 592 593bool Path::getMagicNumber(std::string& Magic, unsigned len) const { 594 assert(len < 1024 && "Request for magic string too long"); 595 char* buf = reinterpret_cast<char*>(alloca(len)); 596 597 HANDLE h = CreateFile(path.c_str(), 598 GENERIC_READ, 599 FILE_SHARE_READ, 600 NULL, 601 OPEN_EXISTING, 602 FILE_ATTRIBUTE_NORMAL, 603 NULL); 604 if (h == INVALID_HANDLE_VALUE) 605 return false; 606 607 DWORD nRead = 0; 608 BOOL ret = ReadFile(h, buf, len, &nRead, NULL); 609 CloseHandle(h); 610 611 if (!ret || nRead != len) 612 return false; 613 614 Magic = std::string(buf, len); 615 return true; 616} 617 618bool 619Path::renamePathOnDisk(const Path& newName, std::string* ErrMsg) { 620 if (!MoveFileEx(path.c_str(), newName.c_str(), MOVEFILE_REPLACE_EXISTING)) 621 return MakeErrMsg(ErrMsg, "Can't move '" + path + "' to '" + newName.path 622 + "': "); 623 return false; 624} 625 626bool 627Path::setStatusInfoOnDisk(const FileStatus &si, std::string *ErrMsg) const { 628 // FIXME: should work on directories also. 629 if (!si.isFile) { 630 return true; 631 } 632 633 HANDLE h = CreateFile(path.c_str(), 634 FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES, 635 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 636 NULL, 637 OPEN_EXISTING, 638 FILE_ATTRIBUTE_NORMAL, 639 NULL); 640 if (h == INVALID_HANDLE_VALUE) 641 return true; 642 643 BY_HANDLE_FILE_INFORMATION bhfi; 644 if (!GetFileInformationByHandle(h, &bhfi)) { 645 DWORD err = GetLastError(); 646 CloseHandle(h); 647 SetLastError(err); 648 return MakeErrMsg(ErrMsg, path + ": GetFileInformationByHandle: "); 649 } 650 651 ULARGE_INTEGER ui; 652 ui.QuadPart = si.modTime.toWin32Time(); 653 FILETIME ft; 654 ft.dwLowDateTime = ui.LowPart; 655 ft.dwHighDateTime = ui.HighPart; 656 BOOL ret = SetFileTime(h, NULL, &ft, &ft); 657 DWORD err = GetLastError(); 658 CloseHandle(h); 659 if (!ret) { 660 SetLastError(err); 661 return MakeErrMsg(ErrMsg, path + ": SetFileTime: "); 662 } 663 664 // Best we can do with Unix permission bits is to interpret the owner 665 // writable bit. 666 if (si.mode & 0200) { 667 if (bhfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY) { 668 if (!SetFileAttributes(path.c_str(), 669 bhfi.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY)) 670 return MakeErrMsg(ErrMsg, path + ": SetFileAttributes: "); 671 } 672 } else { 673 if (!(bhfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) { 674 if (!SetFileAttributes(path.c_str(), 675 bhfi.dwFileAttributes | FILE_ATTRIBUTE_READONLY)) 676 return MakeErrMsg(ErrMsg, path + ": SetFileAttributes: "); 677 } 678 } 679 680 return false; 681} 682 683bool 684Path::makeUnique(bool reuse_current, std::string* ErrMsg) { 685 bool Exists; 686 if (reuse_current && (fs::exists(path, Exists) || !Exists)) 687 return false; // File doesn't exist already, just use it! 688 689 // Reserve space for -XXXXXX at the end. 690 char *FNBuffer = (char*) alloca(path.size()+8); 691 unsigned offset = path.size(); 692 path.copy(FNBuffer, offset); 693 694 // Find a numeric suffix that isn't used by an existing file. Assume there 695 // won't be more than 1 million files with the same prefix. Probably a safe 696 // bet. 697 static int FCounter = -1; 698 if (FCounter < 0) { 699 // Give arbitrary initial seed. 700 // FIXME: We should use sys::fs::unique_file() in future. 701 LARGE_INTEGER cnt64; 702 DWORD x = GetCurrentProcessId(); 703 x = (x << 16) | (x >> 16); 704 if (QueryPerformanceCounter(&cnt64)) // RDTSC 705 x ^= cnt64.HighPart ^ cnt64.LowPart; 706 FCounter = x % 1000000; 707 } 708 do { 709 sprintf(FNBuffer+offset, "-%06u", FCounter); 710 if (++FCounter > 999999) 711 FCounter = 0; 712 path = FNBuffer; 713 } while (!fs::exists(path, Exists) && Exists); 714 return false; 715} 716 717bool 718Path::createTemporaryFileOnDisk(bool reuse_current, std::string* ErrMsg) { 719 // Make this into a unique file name 720 makeUnique(reuse_current, ErrMsg); 721 722 // Now go and create it 723 HANDLE h = CreateFile(path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_NEW, 724 FILE_ATTRIBUTE_NORMAL, NULL); 725 if (h == INVALID_HANDLE_VALUE) 726 return MakeErrMsg(ErrMsg, path + ": can't create file"); 727 728 CloseHandle(h); 729 return false; 730} 731} 732} 733