llvm.org GIT mirror llvm / 11ca2e5
Add a setLastModificationAndAccessTime to PathV2. With this we can remove the last use of PathV1 from llvm-ar.cpp. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184464 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 7 years ago
4 changed file(s) with 61 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
481481 /// platform specific error_code.
482482 error_code permissions(const Twine &path, perms prms);
483483
484 error_code setLastModificationAndAccessTime(int FD, TimeValue Time);
485
484486 /// @brief Is status available?
485487 ///
486488 /// @param s Input file status.
437437 return error_code(errno, system_category());
438438 }
439439
440 return error_code::success();
441 }
442
443 error_code setLastModificationAndAccessTime(int FD, TimeValue Time) {
444 timeval Times[2];
445 Times[0].tv_sec = Time.toPosixTime();
446 Times[0].tv_usec = 0;
447 Times[1] = Times[0];
448 if (::futimes(FD, Times))
449 return error_code(errno, system_category());
440450 return error_code::success();
441451 }
442452
584584 return error_code::success();
585585 }
586586
587 error_code setLastModificationAndAccessTime(int FD, TimeValue Time) {
588 ULARGE_INTEGER UI;
589 UI.QuadPart = Time.toWin32Time();
590 FILETIME FT;
591 FT.dwLowDateTime = UI.LowPart;
592 FT.dwHighDateTime = UI.HighPart;
593 HANDLE FileHandle = reinterpret_cast(_get_osfhandle(FD));
594 if (!SetFileTime(FileHandle, NULL, &FT, &FT))
595 return windows_error(::GetLastError());
596 return error_code::success();
597 }
587598
588599 // FIXME: mode should be used here and default to user r/w only,
589600 // it currently comes in as a UNIX mode.
1818 #include "llvm/Support/FileSystem.h"
1919 #include "llvm/Support/Format.h"
2020 #include "llvm/Support/ManagedStatic.h"
21 #include "llvm/Support/PathV1.h"
2221 #include "llvm/Support/PrettyStackTrace.h"
2322 #include "llvm/Support/Signals.h"
2423 #include "llvm/Support/raw_ostream.h"
2524 #include
2625 #include
26 #include
2727 #include
28
29 #if !defined(_MSC_VER) && !defined(__MINGW32__)
30 #include
31 #else
32 #include
33 #endif
34
2835 using namespace llvm;
2936
3037 // Option for compatibility with AIX, not used but must allow it to be present.
398405 (std::find(Paths.begin(), Paths.end(), I->getPath()) != Paths.end())) {
399406
400407 // Open up a file stream for writing
401 std::string Err;
402 raw_fd_ostream file(I->getPath().str().c_str(), Err,
403 raw_fd_ostream::F_Binary);
404 if (!Err.empty())
405 fail(Err);
406
407 // Get the data and its length
408 const char* data = reinterpret_cast(I->getData());
409 unsigned len = I->getSize();
410
411 // Write the data.
412 file.write(data,len);
413 file.close();
414
415 sys::PathWithStatus PWS(I->getPath());
416 sys::FileStatus Status = *PWS.getFileStatus();
408 int OpenFlags = O_TRUNC | O_WRONLY | O_CREAT;
409 #ifdef O_BINARY
410 OpenFlags |= O_BINARY;
411 #endif
412
413 int FD = open(I->getPath().str().c_str(), OpenFlags, 0664);
414 if (FD < 0)
415 return true;
416
417 {
418 raw_fd_ostream file(FD, false);
419
420 // Get the data and its length
421 const char* data = reinterpret_cast(I->getData());
422 unsigned len = I->getSize();
423
424 // Write the data.
425 file.write(data, len);
426 }
417427
418428 // Retain the original mode.
419 Status.mode = I->getMode();
429 sys::fs::perms Mode = sys::fs::perms(I->getMode());
430 error_code EC = sys::fs::permissions(I->getPath(), Mode);
431 if (EC)
432 fail(EC.message());
420433
421434 // If we're supposed to retain the original modification times, etc. do so
422435 // now.
423 if (OriginalDates)
424 Status.modTime = I->getModTime();
425
426 PWS.setStatusInfoOnDisk(Status);
436 if (OriginalDates) {
437 EC = sys::fs::setLastModificationAndAccessTime(FD, I->getModTime());
438 if (EC)
439 fail(EC.message());
440 }
441 if (close(FD))
442 return true;
427443 }
428444 }
429445 return false;