summaryrefslogtreecommitdiff
path: root/tools/llvm-ar
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-06-21 22:11:36 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-06-21 22:11:36 +0000
commit995017caf95e2651953f356f00bc779970c294e2 (patch)
treee08788a7dc3c2c9302a48d28bd84e82f0989f15c /tools/llvm-ar
parenta622a3f4508e4af62e57a318514f17f03a4fe464 (diff)
downloadllvm-995017caf95e2651953f356f00bc779970c294e2.tar.gz
llvm-995017caf95e2651953f356f00bc779970c294e2.tar.bz2
llvm-995017caf95e2651953f356f00bc779970c294e2.tar.xz
Convert some uses of PathV1.h in ArchiveWriter.cpp.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184599 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-ar')
-rw-r--r--tools/llvm-ar/Archive.h3
-rw-r--r--tools/llvm-ar/ArchiveWriter.cpp54
2 files changed, 29 insertions, 28 deletions
diff --git a/tools/llvm-ar/Archive.h b/tools/llvm-ar/Archive.h
index 37489992cf..3922e375ae 100644
--- a/tools/llvm-ar/Archive.h
+++ b/tools/llvm-ar/Archive.h
@@ -20,6 +20,7 @@
#include "llvm/ADT/ilist.h"
#include "llvm/ADT/ilist_node.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/TimeValue.h"
#include <map>
#include <set>
@@ -375,7 +376,7 @@ class Archive {
/// returns true if writing member failed, \p error set to error message.
bool writeMember(
const ArchiveMember& member, ///< The member to be written
- std::ofstream& ARFile, ///< The file to write member onto
+ raw_fd_ostream& ARFile, ///< The file to write member onto
bool TruncateNames, ///< Should names be truncated to 11 chars?
std::string* ErrMessage ///< If non-null, place were error msg is set
);
diff --git a/tools/llvm-ar/ArchiveWriter.cpp b/tools/llvm-ar/ArchiveWriter.cpp
index 135ed5665f..2e4c2e178c 100644
--- a/tools/llvm-ar/ArchiveWriter.cpp
+++ b/tools/llvm-ar/ArchiveWriter.cpp
@@ -160,17 +160,22 @@ bool Archive::addFileBefore(StringRef filePath, iterator where,
mbr->data = 0;
mbr->path = filePath;
- sys::PathWithStatus PWS(filePath);
- const sys::FileStatus *FSInfo = PWS.getFileStatus(false, ErrMsg);
- if (!FSInfo) {
+ sys::fs::file_status Status;
+ error_code EC = sys::fs::status(filePath, Status);
+ if (EC) {
+ delete mbr;
+ return true;
+ }
+ mbr->User = Status.getUser();
+ mbr->Group = Status.getGroup();
+ mbr->Mode = Status.permissions();
+ mbr->ModTime = Status.getLastModificationTime();
+ // FIXME: On posix this is a second stat.
+ EC = sys::fs::file_size(filePath, mbr->Size);
+ if (EC) {
delete mbr;
return true;
}
- mbr->User = FSInfo->getUser();
- mbr->Group = FSInfo->getGroup();
- mbr->Mode = FSInfo->getMode();
- mbr->ModTime = FSInfo->getTimestamp();
- mbr->Size = FSInfo->getSize();
unsigned flags = 0;
if (sys::path::filename(filePath).size() > 15)
@@ -195,12 +200,12 @@ bool Archive::addFileBefore(StringRef filePath, iterator where,
bool
Archive::writeMember(
const ArchiveMember& member,
- std::ofstream& ARFile,
+ raw_fd_ostream& ARFile,
bool TruncateNames,
std::string* ErrMsg
) {
- unsigned filepos = ARFile.tellp();
+ uint64_t filepos = ARFile.tell();
filepos -= 8;
// Get the data and its size either from the
@@ -239,7 +244,7 @@ Archive::writeMember(
ARFile.write(data,fSize);
// Make sure the member is an even length
- if ((ARFile.tellp() & 1) == 1)
+ if ((ARFile.tell() & 1) == 1)
ARFile << ARFILE_PAD;
// Close the mapped file if it was opened
@@ -261,25 +266,18 @@ bool Archive::writeToDisk(bool TruncateNames, std::string *ErrMsg) {
}
// Create a temporary file to store the archive in
- sys::Path TmpArchive(archPath);
- if (TmpArchive.createTemporaryFileOnDisk(ErrMsg))
+ int TmpArchiveFD;
+ SmallString<128> TmpArchive;
+ error_code EC = sys::fs::unique_file("temp-archive-%%%%%%%.a", TmpArchiveFD,
+ TmpArchive);
+ if (EC)
return true;
// Make sure the temporary gets removed if we crash
- sys::RemoveFileOnSignal(TmpArchive.str());
+ sys::RemoveFileOnSignal(TmpArchive);
// Create archive file for output.
- std::ios::openmode io_mode = std::ios::out | std::ios::trunc |
- std::ios::binary;
- std::ofstream ArchiveFile(TmpArchive.c_str(), io_mode);
-
- // Check for errors opening or creating archive file.
- if (!ArchiveFile.is_open() || ArchiveFile.bad()) {
- TmpArchive.eraseFromDisk();
- if (ErrMsg)
- *ErrMsg = "Error opening archive file: " + archPath;
- return true;
- }
+ raw_fd_ostream ArchiveFile(TmpArchiveFD, true);
// Write magic string to archive.
ArchiveFile << ARFILE_MAGIC;
@@ -288,7 +286,7 @@ bool Archive::writeToDisk(bool TruncateNames, std::string *ErrMsg) {
// builds the symbol table, symTab.
for (MembersList::iterator I = begin(), E = end(); I != E; ++I) {
if (writeMember(*I, ArchiveFile, TruncateNames, ErrMsg)) {
- TmpArchive.eraseFromDisk();
+ sys::fs::remove(Twine(TmpArchive));
ArchiveFile.close();
return true;
}
@@ -302,8 +300,10 @@ bool Archive::writeToDisk(bool TruncateNames, std::string *ErrMsg) {
// this because we cannot replace an open file on Windows.
cleanUpMemory();
- if (TmpArchive.renamePathOnDisk(sys::Path(archPath), ErrMsg))
+ if (sys::fs::rename(Twine(TmpArchive), archPath)) {
+ *ErrMsg = EC.message();
return true;
+ }
// Set correct read and write permissions after temporary file is moved
// to final destination path.