mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-26 09:18:56 +00:00
Fix a problem in getDirectoryContents where sub-directory names were
appended to a path string that didn't end in a slash, yielding invalid path names. Path contribute by Nicholas Riley. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22539 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -53,6 +53,13 @@
|
|||||||
# undef HAVE_MKDTEMP
|
# undef HAVE_MKDTEMP
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
inline bool lastIsSlash(const std::string& path) {
|
||||||
|
return !path.empty() && path[path.length() - 1] == '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
using namespace sys;
|
using namespace sys;
|
||||||
|
|
||||||
@@ -437,11 +444,15 @@ Path::getDirectoryContents(std::set<Path>& result) const {
|
|||||||
if (direntries == 0)
|
if (direntries == 0)
|
||||||
ThrowErrno(path + ": can't open directory");
|
ThrowErrno(path + ": can't open directory");
|
||||||
|
|
||||||
|
std::string dirPath = path;
|
||||||
|
if (!lastIsSlash(dirPath))
|
||||||
|
dirPath += '/';
|
||||||
|
|
||||||
result.clear();
|
result.clear();
|
||||||
struct dirent* de = ::readdir(direntries);
|
struct dirent* de = ::readdir(direntries);
|
||||||
for ( ; de != 0; de = ::readdir(direntries)) {
|
for ( ; de != 0; de = ::readdir(direntries)) {
|
||||||
if (de->d_name[0] != '.') {
|
if (de->d_name[0] != '.') {
|
||||||
Path aPath(path + (const char*)de->d_name);
|
Path aPath(dirPath + (const char*)de->d_name);
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
if (0 != stat(aPath.path.c_str(), &buf)) {
|
if (0 != stat(aPath.path.c_str(), &buf)) {
|
||||||
int stat_errno = errno;
|
int stat_errno = errno;
|
||||||
@@ -477,11 +488,8 @@ Path::appendComponent(const std::string& name) {
|
|||||||
if (name.empty())
|
if (name.empty())
|
||||||
return false;
|
return false;
|
||||||
std::string save(path);
|
std::string save(path);
|
||||||
if (!path.empty()) {
|
if (!lastIsSlash(path))
|
||||||
size_t last = path.size() - 1;
|
path += '/';
|
||||||
if (path[last] != '/')
|
|
||||||
path += '/';
|
|
||||||
}
|
|
||||||
path += name;
|
path += name;
|
||||||
if (!isValid()) {
|
if (!isValid()) {
|
||||||
path = save;
|
path = save;
|
||||||
|
Reference in New Issue
Block a user