forked from OSchip/llvm-project
Add a setLastModificationAndAccessTime to PathV2.
With this we can remove the last use of PathV1 from llvm-ar.cpp. llvm-svn: 184464
This commit is contained in:
parent
463e2d9b19
commit
4a3365c869
|
@ -482,6 +482,8 @@ error_code status(const Twine &path, file_status &result);
|
||||||
/// platform specific error_code.
|
/// platform specific error_code.
|
||||||
error_code permissions(const Twine &path, perms prms);
|
error_code permissions(const Twine &path, perms prms);
|
||||||
|
|
||||||
|
error_code setLastModificationAndAccessTime(int FD, TimeValue Time);
|
||||||
|
|
||||||
/// @brief Is status available?
|
/// @brief Is status available?
|
||||||
///
|
///
|
||||||
/// @param s Input file status.
|
/// @param s Input file status.
|
||||||
|
|
|
@ -441,6 +441,16 @@ error_code permissions(const Twine &path, perms prms) {
|
||||||
return error_code::success();
|
return error_code::success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_code setLastModificationAndAccessTime(int FD, TimeValue Time) {
|
||||||
|
timeval Times[2];
|
||||||
|
Times[0].tv_sec = Time.toPosixTime();
|
||||||
|
Times[0].tv_usec = 0;
|
||||||
|
Times[1] = Times[0];
|
||||||
|
if (::futimes(FD, Times))
|
||||||
|
return error_code(errno, system_category());
|
||||||
|
return error_code::success();
|
||||||
|
}
|
||||||
|
|
||||||
// Since this is most often used for temporary files, mode defaults to 0600.
|
// Since this is most often used for temporary files, mode defaults to 0600.
|
||||||
error_code unique_file(const Twine &model, int &result_fd,
|
error_code unique_file(const Twine &model, int &result_fd,
|
||||||
SmallVectorImpl<char> &result_path,
|
SmallVectorImpl<char> &result_path,
|
||||||
|
|
|
@ -585,6 +585,17 @@ error_code permissions(const Twine &path, perms prms) {
|
||||||
return error_code::success();
|
return error_code::success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_code setLastModificationAndAccessTime(int FD, TimeValue Time) {
|
||||||
|
ULARGE_INTEGER UI;
|
||||||
|
UI.QuadPart = Time.toWin32Time();
|
||||||
|
FILETIME FT;
|
||||||
|
FT.dwLowDateTime = UI.LowPart;
|
||||||
|
FT.dwHighDateTime = UI.HighPart;
|
||||||
|
HANDLE FileHandle = reinterpret_cast<HANDLE>(_get_osfhandle(FD));
|
||||||
|
if (!SetFileTime(FileHandle, NULL, &FT, &FT))
|
||||||
|
return windows_error(::GetLastError());
|
||||||
|
return error_code::success();
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: mode should be used here and default to user r/w only,
|
// FIXME: mode should be used here and default to user r/w only,
|
||||||
// it currently comes in as a UNIX mode.
|
// it currently comes in as a UNIX mode.
|
||||||
|
|
|
@ -19,13 +19,20 @@
|
||||||
#include "llvm/Support/FileSystem.h"
|
#include "llvm/Support/FileSystem.h"
|
||||||
#include "llvm/Support/Format.h"
|
#include "llvm/Support/Format.h"
|
||||||
#include "llvm/Support/ManagedStatic.h"
|
#include "llvm/Support/ManagedStatic.h"
|
||||||
#include "llvm/Support/PathV1.h"
|
|
||||||
#include "llvm/Support/PrettyStackTrace.h"
|
#include "llvm/Support/PrettyStackTrace.h"
|
||||||
#include "llvm/Support/Signals.h"
|
#include "llvm/Support/Signals.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#if !defined(_MSC_VER) && !defined(__MINGW32__)
|
||||||
|
#include <unistd.h>
|
||||||
|
#else
|
||||||
|
#include <io.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
// Option for compatibility with AIX, not used but must allow it to be present.
|
// Option for compatibility with AIX, not used but must allow it to be present.
|
||||||
|
@ -399,32 +406,41 @@ doExtract(std::string* ErrMsg) {
|
||||||
(std::find(Paths.begin(), Paths.end(), I->getPath()) != Paths.end())) {
|
(std::find(Paths.begin(), Paths.end(), I->getPath()) != Paths.end())) {
|
||||||
|
|
||||||
// Open up a file stream for writing
|
// Open up a file stream for writing
|
||||||
std::string Err;
|
int OpenFlags = O_TRUNC | O_WRONLY | O_CREAT;
|
||||||
raw_fd_ostream file(I->getPath().str().c_str(), Err,
|
#ifdef O_BINARY
|
||||||
raw_fd_ostream::F_Binary);
|
OpenFlags |= O_BINARY;
|
||||||
if (!Err.empty())
|
#endif
|
||||||
fail(Err);
|
|
||||||
|
|
||||||
// Get the data and its length
|
int FD = open(I->getPath().str().c_str(), OpenFlags, 0664);
|
||||||
const char* data = reinterpret_cast<const char*>(I->getData());
|
if (FD < 0)
|
||||||
unsigned len = I->getSize();
|
return true;
|
||||||
|
|
||||||
// Write the data.
|
{
|
||||||
file.write(data,len);
|
raw_fd_ostream file(FD, false);
|
||||||
file.close();
|
|
||||||
|
|
||||||
sys::PathWithStatus PWS(I->getPath());
|
// Get the data and its length
|
||||||
sys::FileStatus Status = *PWS.getFileStatus();
|
const char* data = reinterpret_cast<const char*>(I->getData());
|
||||||
|
unsigned len = I->getSize();
|
||||||
|
|
||||||
|
// Write the data.
|
||||||
|
file.write(data, len);
|
||||||
|
}
|
||||||
|
|
||||||
// Retain the original mode.
|
// Retain the original mode.
|
||||||
Status.mode = I->getMode();
|
sys::fs::perms Mode = sys::fs::perms(I->getMode());
|
||||||
|
error_code EC = sys::fs::permissions(I->getPath(), Mode);
|
||||||
|
if (EC)
|
||||||
|
fail(EC.message());
|
||||||
|
|
||||||
// If we're supposed to retain the original modification times, etc. do so
|
// If we're supposed to retain the original modification times, etc. do so
|
||||||
// now.
|
// now.
|
||||||
if (OriginalDates)
|
if (OriginalDates) {
|
||||||
Status.modTime = I->getModTime();
|
EC = sys::fs::setLastModificationAndAccessTime(FD, I->getModTime());
|
||||||
|
if (EC)
|
||||||
PWS.setStatusInfoOnDisk(Status);
|
fail(EC.message());
|
||||||
|
}
|
||||||
|
if (close(FD))
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue