summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-06-19 15:45:37 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-06-19 15:45:37 +0000
commit4d07abbb01b7bfc8e6e24ce07f2487803df50ea3 (patch)
treee2c87c02c38710dc98913172dc3daf7ae7709f5d /tools
parent7c8397081c3d101fe467e8375601b091056465e0 (diff)
downloadllvm-4d07abbb01b7bfc8e6e24ce07f2487803df50ea3.tar.gz
llvm-4d07abbb01b7bfc8e6e24ce07f2487803df50ea3.tar.bz2
llvm-4d07abbb01b7bfc8e6e24ce07f2487803df50ea3.tar.xz
Reduce sys::Path usage in llvm-ar.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184315 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/llvm-ar/Archive.cpp19
-rw-r--r--tools/llvm-ar/Archive.h4
-rw-r--r--tools/llvm-ar/ArchiveReader.cpp2
-rw-r--r--tools/llvm-ar/ArchiveWriter.cpp9
-rw-r--r--tools/llvm-ar/llvm-ar.cpp40
5 files changed, 39 insertions, 35 deletions
diff --git a/tools/llvm-ar/Archive.cpp b/tools/llvm-ar/Archive.cpp
index 3e9b9b2c25..9086d4e42e 100644
--- a/tools/llvm-ar/Archive.cpp
+++ b/tools/llvm-ar/Archive.cpp
@@ -33,7 +33,7 @@ ArchiveMember::getMemberSize() const {
// If it has a long filename, include the name length
if (hasLongFilename())
- result += path.str().length() + 1;
+ result += path.length() + 1;
// If its now odd lengthed, include the padding byte
if (result % 2 != 0 )
@@ -76,35 +76,35 @@ bool ArchiveMember::replaceWith(const sys::Path& newFile, std::string* ErrMsg) {
}
data = 0;
- path = newFile;
+ path = newFile.str();
// SVR4 symbol tables have an empty name
- if (path.str() == ARFILE_SVR4_SYMTAB_NAME)
+ if (path == ARFILE_SVR4_SYMTAB_NAME)
flags |= SVR4SymbolTableFlag;
else
flags &= ~SVR4SymbolTableFlag;
// BSD4.4 symbol tables have a special name
- if (path.str() == ARFILE_BSD4_SYMTAB_NAME)
+ if (path == ARFILE_BSD4_SYMTAB_NAME)
flags |= BSD4SymbolTableFlag;
else
flags &= ~BSD4SymbolTableFlag;
// String table name
- if (path.str() == ARFILE_STRTAB_NAME)
+ if (path == ARFILE_STRTAB_NAME)
flags |= StringTableFlag;
else
flags &= ~StringTableFlag;
// If it has a slash then it has a path
- bool hasSlash = path.str().find('/') != std::string::npos;
+ bool hasSlash = path.find('/') != std::string::npos;
if (hasSlash)
flags |= HasPathFlag;
else
flags &= ~HasPathFlag;
// If it has a slash or its over 15 chars then its a long filename format
- if (hasSlash || path.str().length() > 15)
+ if (hasSlash || path.length() > 15)
flags |= HasLongFilenameFlag;
else
flags &= ~HasLongFilenameFlag;
@@ -113,9 +113,10 @@ bool ArchiveMember::replaceWith(const sys::Path& newFile, std::string* ErrMsg) {
const char* signature = (const char*) data;
SmallString<4> magic;
if (!signature) {
- sys::fs::get_magic(path.str(), magic.capacity(), magic);
+ sys::fs::get_magic(path, magic.capacity(), magic);
signature = magic.c_str();
- const sys::FileStatus *FSinfo = path.getFileStatus(false, ErrMsg);
+ sys::PathWithStatus PWS(path);
+ const sys::FileStatus *FSinfo = PWS.getFileStatus(false, ErrMsg);
if (FSinfo)
info = *FSinfo;
else
diff --git a/tools/llvm-ar/Archive.h b/tools/llvm-ar/Archive.h
index bd76298c42..43b870684c 100644
--- a/tools/llvm-ar/Archive.h
+++ b/tools/llvm-ar/Archive.h
@@ -66,7 +66,7 @@ class ArchiveMember : public ilist_node<ArchiveMember> {
/// @returns the path to the Archive's file
/// @brief Get the path to the archive member
- const sys::Path& getPath() const { return path; }
+ StringRef getPath() const { return path; }
/// The "user" is the owner of the file per Unix security. This may not
/// have any applicability on non-Unix systems but is a required component
@@ -159,7 +159,7 @@ class ArchiveMember : public ilist_node<ArchiveMember> {
/// @{
private:
Archive* parent; ///< Pointer to parent archive
- sys::PathWithStatus path; ///< Path of file containing the member
+ std::string path; ///< Path of file containing the member
sys::FileStatus info; ///< Status info (size,mode,date)
unsigned flags; ///< Flags about the archive member
const char* data; ///< Data for the member
diff --git a/tools/llvm-ar/ArchiveReader.cpp b/tools/llvm-ar/ArchiveReader.cpp
index 8ad01dca0b..1271d02028 100644
--- a/tools/llvm-ar/ArchiveReader.cpp
+++ b/tools/llvm-ar/ArchiveReader.cpp
@@ -174,7 +174,7 @@ Archive::parseMemberHeader(const char*& At, const char* End, std::string* error)
// Fill in fields of the ArchiveMember
member->parent = this;
- member->path.set(pathname);
+ member->path = pathname;
member->info.fileSize = MemberSize;
member->info.modTime.fromEpochTime(atoi(Hdr->date));
unsigned int mode;
diff --git a/tools/llvm-ar/ArchiveWriter.cpp b/tools/llvm-ar/ArchiveWriter.cpp
index 24f5dbc0dc..16e748469f 100644
--- a/tools/llvm-ar/ArchiveWriter.cpp
+++ b/tools/llvm-ar/ArchiveWriter.cpp
@@ -166,8 +166,9 @@ Archive::addFileBefore(const sys::Path& filePath, iterator where,
ArchiveMember* mbr = new ArchiveMember(this);
mbr->data = 0;
- mbr->path = filePath;
- const sys::FileStatus *FSInfo = mbr->path.getFileStatus(false, ErrMsg);
+ mbr->path = filePath.str();
+ sys::PathWithStatus PWS(mbr->path);
+ const sys::FileStatus *FSInfo = PWS.getFileStatus(false, ErrMsg);
if (!FSInfo) {
delete mbr;
return true;
@@ -182,7 +183,7 @@ Archive::addFileBefore(const sys::Path& filePath, iterator where,
flags |= ArchiveMember::HasLongFilenameFlag;
sys::fs::file_magic type;
- if (sys::fs::identify_magic(mbr->path.str(), type))
+ if (sys::fs::identify_magic(mbr->path, type))
type = sys::fs::file_magic::unknown;
switch (type) {
case sys::fs::file_magic::bitcode:
@@ -216,7 +217,7 @@ Archive::writeMember(
MemoryBuffer *mFile = 0;
if (!data) {
OwningPtr<MemoryBuffer> File;
- if (error_code ec = MemoryBuffer::getFile(member.getPath().c_str(), File)) {
+ if (error_code ec = MemoryBuffer::getFile(member.getPath(), File)) {
if (ErrMsg)
*ErrMsg = ec.message();
return true;
diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp
index 792b46bded..68f51ce88b 100644
--- a/tools/llvm-ar/llvm-ar.cpp
+++ b/tools/llvm-ar/llvm-ar.cpp
@@ -121,7 +121,7 @@ std::vector<std::string> Members;
// This variable holds the (possibly expanded) list of path objects that
// correspond to files we will
-std::set<sys::Path> Paths;
+std::set<std::string> Paths;
// The Archive object to which all the editing operations will be sent.
Archive* TheArchive = 0;
@@ -300,9 +300,9 @@ bool buildPaths(bool checkExistence, std::string* ErrMsg) {
if (si->isDir)
fail(aPath.str() + " Is a directory");
- Paths.insert(aPath);
+ Paths.insert(aPath.str());
} else {
- Paths.insert(aPath);
+ Paths.insert(aPath.str());
}
}
return false;
@@ -430,7 +430,7 @@ doExtract(std::string* ErrMsg) {
// Open up a file stream for writing
std::ios::openmode io_mode = std::ios::out | std::ios::trunc |
std::ios::binary;
- std::ofstream file(I->getPath().c_str(), io_mode);
+ std::ofstream file(I->getPath(), io_mode);
// Get the data and its length
const char* data = reinterpret_cast<const char*>(I->getData());
@@ -442,8 +442,10 @@ doExtract(std::string* ErrMsg) {
// If we're supposed to retain the original modification times, etc. do so
// now.
- if (OriginalDates)
- I->getPath().setStatusInfoOnDisk(I->getFileStatus());
+ if (OriginalDates) {
+ sys::PathWithStatus PWS(I->getPath());
+ PWS.setStatusInfoOnDisk(I->getFileStatus());
+ }
}
}
return false;
@@ -514,14 +516,14 @@ doMove(std::string* ErrMsg) {
}
// Keep a list of the paths remaining to be moved
- std::set<sys::Path> remaining(Paths);
+ std::set<std::string> remaining(Paths);
// Scan the archive again, this time looking for the members to move to the
// moveto_spot.
for (Archive::iterator I = TheArchive->begin(), E= TheArchive->end();
I != E && !remaining.empty(); ++I ) {
- std::set<sys::Path>::iterator found =
- std::find(remaining.begin(),remaining.end(),I->getPath());
+ std::set<std::string>::iterator found =
+ std::find(remaining.begin(),remaining.end(), I->getPath());
if (found != remaining.end()) {
if (I != moveto_spot)
TheArchive->splice(moveto_spot,*TheArchive,I);
@@ -548,9 +550,9 @@ doQuickAppend(std::string* ErrMsg) {
return false;
// Append them quickly.
- for (std::set<sys::Path>::iterator PI = Paths.begin(), PE = Paths.end();
+ for (std::set<std::string>::iterator PI = Paths.begin(), PE = Paths.end();
PI != PE; ++PI) {
- if (TheArchive->addFileBefore(*PI,TheArchive->end(),ErrMsg))
+ if (TheArchive->addFileBefore(sys::Path(*PI),TheArchive->end(),ErrMsg))
return true;
}
@@ -574,7 +576,7 @@ doReplaceOrInsert(std::string* ErrMsg) {
return false;
// Keep track of the paths that remain to be inserted.
- std::set<sys::Path> remaining(Paths);
+ std::set<std::string> remaining(Paths);
// Default the insertion spot to the end of the archive
Archive::iterator insert_spot = TheArchive->end();
@@ -586,10 +588,10 @@ doReplaceOrInsert(std::string* ErrMsg) {
// Determine if this archive member matches one of the paths we're trying
// to replace.
- std::set<sys::Path>::iterator found = remaining.end();
- for (std::set<sys::Path>::iterator RI = remaining.begin(),
+ std::set<std::string>::iterator found = remaining.end();
+ for (std::set<std::string>::iterator RI = remaining.begin(),
RE = remaining.end(); RI != RE; ++RI ) {
- std::string compare(RI->str());
+ std::string compare(*RI);
if (TruncateNames && compare.length() > 15) {
const char* nm = compare.c_str();
unsigned len = compare.length();
@@ -618,11 +620,11 @@ doReplaceOrInsert(std::string* ErrMsg) {
if (OnlyUpdate) {
// Replace the item only if it is newer.
if (si->modTime > I->getModTime())
- if (I->replaceWith(*found, ErrMsg))
+ if (I->replaceWith(sys::Path(*found), ErrMsg))
return true;
} else {
// Replace the item regardless of time stamp
- if (I->replaceWith(*found, ErrMsg))
+ if (I->replaceWith(sys::Path(*found), ErrMsg))
return true;
}
} else {
@@ -645,9 +647,9 @@ doReplaceOrInsert(std::string* ErrMsg) {
// If we didn't replace all the members, some will remain and need to be
// inserted at the previously computed insert-spot.
if (!remaining.empty()) {
- for (std::set<sys::Path>::iterator PI = remaining.begin(),
+ for (std::set<std::string>::iterator PI = remaining.begin(),
PE = remaining.end(); PI != PE; ++PI) {
- if (TheArchive->addFileBefore(*PI,insert_spot, ErrMsg))
+ if (TheArchive->addFileBefore(sys::Path(*PI),insert_spot, ErrMsg))
return true;
}
}