For PR495:

Change interface to Path class:
readable -> canRead
writable -> canWrite
executable -> canExecute

More (incremental) changes coming to close 495.

llvm-svn: 22345
This commit is contained in:
Reid Spencer 2005-07-07 18:21:42 +00:00
parent 2e81f65eb8
commit 5b891e9847
12 changed files with 47 additions and 39 deletions

View File

@ -241,6 +241,14 @@ namespace sys {
/// @brief Determines if the path name references a directory.
bool isDirectory() const;
/// This function determines if the path refers to a hidden file. The
/// notion of hidden files is defined by the underlying system. The
/// system may not support hidden files in which case this function always
/// returns false on such systems. Hidden files have the "hidden"
/// attribute set on Win32. On Unix, hidden files start with a period.
/// @brief Determines if the path name references a hidden file.
bool isHidden() const;
/// This function determines if the path name in this object references
/// the root (top level directory) of the file system. The details of what
/// is considered the "root" may vary from system to system so this method
@ -303,7 +311,7 @@ namespace sys {
/// @returns true if the pathname references a readable file.
/// @brief Determines if the path is a readable file or directory
/// in the file system.
bool readable() const;
bool canRead() const;
/// This function determines if the path name references a writable file
/// or directory in the file system. Unlike isFile and isDirectory, this
@ -312,7 +320,7 @@ namespace sys {
/// @returns true if the pathname references a writable file.
/// @brief Determines if the path is a writable file or directory
/// in the file system.
bool writable() const;
bool canWrite() const;
/// This function determines if the path name references an executable
/// file in the file system. Unlike isFile and isDirectory, this
@ -321,7 +329,7 @@ namespace sys {
/// @returns true if the pathname references an executable file.
/// @brief Determines if the path is an executable file in the file
/// system.
bool executable() const;
bool canExecute() const;
/// This function returns the current contents of the path as a
/// std::string. This allows the underlying path string to be manipulated

View File

@ -174,7 +174,7 @@ SourceFile &SourceFileInfo::getSourceText() const {
if (!Directory.empty())
tmpPath.setDirectory(Directory);
tmpPath.appendFile(BaseName);
if (tmpPath.readable())
if (tmpPath.canRead())
SourceText = new SourceFile(tmpPath.toString(), Descriptor);
else
SourceText = new SourceFile(BaseName, Descriptor);

View File

@ -118,7 +118,7 @@ bool Linker::LinkInLibraries(const std::vector<std::string> &Libraries) {
///
bool Linker::LinkInFile(const sys::Path &File) {
// Make sure we can at least read the file
if (!File.readable())
if (!File.canRead())
return error("Cannot find linker input '" + File.toString() + "'");
// A user may specify an ar archive without -l, perhaps because it

View File

@ -153,7 +153,7 @@ Linker::FindLib(const std::string &Filename)
{
// Determine if the pathname can be found as it stands.
sys::Path FilePath(Filename);
if (FilePath.readable() &&
if (FilePath.canRead() &&
(FilePath.isArchive() || FilePath.isDynamicLibrary()))
return FilePath;

View File

@ -48,7 +48,7 @@ sys::Path llvm::FindExecutable(const std::string &ExeName,
Result.elideFile();
if (!Result.isEmpty()) {
Result.appendFile(ExeName);
if (Result.executable())
if (Result.canExecute())
return Result;
}

View File

@ -62,14 +62,14 @@ sys::IdentifyFileType(const char*magic, unsigned length) {
bool
Path::isArchive() const {
if (readable())
if (canRead())
return hasMagicNumber("!<arch>\012");
return false;
}
bool
Path::isDynamicLibrary() const {
if (readable())
if (canRead())
return hasMagicNumber("\177ELF");
return false;
}

View File

@ -168,14 +168,14 @@ static void getPathList(const char*path, std::vector<sys::Path>& Paths) {
while( delim != 0 ) {
std::string tmp(at, size_t(delim-at));
if (tmpPath.setDirectory(tmp))
if (tmpPath.readable())
if (tmpPath.canRead())
Paths.push_back(tmpPath);
at = delim + 1;
delim = strchr(at, ':');
}
if (*at != 0)
if (tmpPath.setDirectory(std::string(at)))
if (tmpPath.readable())
if (tmpPath.canRead())
Paths.push_back(tmpPath);
}
@ -205,7 +205,7 @@ Path::GetBytecodeLibraryPaths(std::vector<sys::Path>& Paths) {
{
Path tmpPath;
if (tmpPath.setDirectory(LLVM_LIBDIR))
if (tmpPath.readable())
if (tmpPath.canRead())
Paths.push_back(tmpPath);
}
#endif
@ -305,17 +305,17 @@ Path::exists() const {
}
bool
Path::readable() const {
Path::canRead() const {
return 0 == access(path.c_str(), F_OK | R_OK );
}
bool
Path::writable() const {
Path::canWrite() const {
return 0 == access(path.c_str(), F_OK | W_OK );
}
bool
Path::executable() const {
Path::canExecute() const {
struct stat st;
int r = stat(path.c_str(), &st);
if (r != 0 || !S_ISREG(st.st_mode))

View File

@ -46,7 +46,7 @@ Program::FindProgramByName(const std::string& progName) {
return Path();
// FIXME: have to check for absolute filename - we cannot assume anything
// about "." being in $PATH
if (temp.executable()) // already executable as is
if (temp.canExecute()) // already executable as is
return temp;
// At this point, the file name is valid and its not executable
@ -66,7 +66,7 @@ Program::FindProgramByName(const std::string& progName) {
Path FilePath;
if (FilePath.setDirectory(std::string(PathStr,Colon))) {
FilePath.appendFile(progName);
if (FilePath.executable())
if (FilePath.canExecute())
return FilePath; // Found the executable!
}
@ -109,7 +109,7 @@ Program::ExecuteAndWait(const Path& path,
const Path** redirects,
unsigned secondsToWait
) {
if (!path.executable())
if (!path.canExecute())
throw path.toString() + " is not executable";
#ifdef HAVE_SYS_WAIT_H

View File

@ -139,14 +139,14 @@ static void getPathList(const char*path, std::vector<sys::Path>& Paths) {
while( delim != 0 ) {
std::string tmp(at, size_t(delim-at));
if (tmpPath.setDirectory(tmp))
if (tmpPath.readable())
if (tmpPath.canRead())
Paths.push_back(tmpPath);
at = delim + 1;
delim = strchr(at, ';');
}
if (*at != 0)
if (tmpPath.setDirectory(std::string(at)))
if (tmpPath.readable())
if (tmpPath.canRead())
Paths.push_back(tmpPath);
}
@ -167,7 +167,7 @@ Path::GetBytecodeLibraryPaths(std::vector<sys::Path>& Paths) {
{
Path tmpPath;
if (tmpPath.setDirectory(LLVM_LIBDIR))
if (tmpPath.readable())
if (tmpPath.canRead())
Paths.push_back(tmpPath);
}
#endif
@ -237,21 +237,21 @@ Path::exists() const {
}
bool
Path::readable() const {
Path::canRead() const {
// FIXME: take security attributes into account.
DWORD attr = GetFileAttributes(path.c_str());
return attr != INVALID_FILE_ATTRIBUTES;
}
bool
Path::writable() const {
Path::canWrite() const {
// FIXME: take security attributes into account.
DWORD attr = GetFileAttributes(path.c_str());
return (attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_READONLY);
}
bool
Path::executable() const {
Path::canExecute() const {
// FIXME: take security attributes into account.
DWORD attr = GetFileAttributes(path.c_str());
return attr != INVALID_FILE_ATTRIBUTES;

View File

@ -119,7 +119,7 @@ void DumpSymbolNamesFromModule (Module *M) {
void DumpSymbolNamesFromFile (std::string &Filename) {
std::string ErrorMessage;
sys::Path aPath(Filename);
if (Filename != "-" && !aPath.readable()) {
if (Filename != "-" && !aPath.canRead()) {
std::cerr << ToolName << ": " << Filename << ": " << strerror (errno)
<< "\n";
return;

View File

@ -187,7 +187,7 @@ private:
void cleanup() {
if (!isSet(KEEP_TEMPS_FLAG)) {
if (TempDir.isDirectory() && TempDir.writable())
if (TempDir.isDirectory() && TempDir.canWrite())
TempDir.destroyDirectory(/*remove_contents=*/true);
} else {
std::cout << "Temporary files are in " << TempDir << "\n";
@ -415,7 +415,7 @@ private:
if (progpath.isEmpty())
throw std::string("Can't find program '" +
action->program.toString()+"'");
else if (progpath.executable())
else if (progpath.canExecute())
action->program = progpath;
else
throw std::string("Program '"+action->program.toString()+
@ -449,32 +449,32 @@ private:
bool native = false) {
sys::Path fullpath;
fullpath.setFile(link_item);
if (fullpath.readable())
if (fullpath.canRead())
return fullpath;
for (PathVector::iterator PI = LibraryPaths.begin(),
PE = LibraryPaths.end(); PI != PE; ++PI) {
fullpath.setDirectory(PI->toString());
fullpath.appendFile(link_item);
if (fullpath.readable())
if (fullpath.canRead())
return fullpath;
if (native) {
fullpath.appendSuffix("a");
} else {
fullpath.appendSuffix("bc");
if (fullpath.readable())
if (fullpath.canRead())
return fullpath;
fullpath.elideSuffix();
fullpath.appendSuffix("o");
if (fullpath.readable())
if (fullpath.canRead())
return fullpath;
fullpath = *PI;
fullpath.appendFile(std::string("lib") + link_item);
fullpath.appendSuffix("a");
if (fullpath.readable())
if (fullpath.canRead())
return fullpath;
fullpath.elideSuffix();
fullpath.appendSuffix("so");
if (fullpath.readable())
if (fullpath.canRead())
return fullpath;
}
}
@ -494,7 +494,7 @@ private:
// First, see if the unadorned file name is not readable. If so,
// we must track down the file in the lib search path.
sys::Path fullpath;
if (!link_item.readable()) {
if (!link_item.canRead()) {
// look for the library using the -L arguments specified
// on the command line.
fullpath = GetPathForLinkageItem(link_item.toString());

View File

@ -549,7 +549,7 @@ LLVMC_ConfigDataProvider::ReadConfigData(const std::string& ftype) {
if (conf) {
confFile.setDirectory(conf);
confFile.appendFile(ftype);
if (!confFile.readable())
if (!confFile.canRead())
throw std::string("Configuration file for '") + ftype +
"' is not available.";
} else {
@ -559,18 +559,18 @@ LLVMC_ConfigDataProvider::ReadConfigData(const std::string& ftype) {
confFile.appendDirectory(".llvm");
confFile.appendDirectory("etc");
confFile.appendFile(ftype);
if (!confFile.readable())
if (!confFile.canRead())
confFile.clear();
}
if (confFile.isEmpty()) {
// Okay, try the LLVM installation directory
confFile = sys::Path::GetLLVMConfigDir();
confFile.appendFile(ftype);
if (!confFile.readable()) {
if (!confFile.canRead()) {
// Okay, try the "standard" place
confFile = sys::Path::GetLLVMDefaultConfigDir();
confFile.appendFile(ftype);
if (!confFile.readable()) {
if (!confFile.canRead()) {
throw std::string("Configuration file for '") + ftype +
"' is not available.";
}
@ -580,7 +580,7 @@ LLVMC_ConfigDataProvider::ReadConfigData(const std::string& ftype) {
} else {
confFile = configDir;
confFile.appendFile(ftype);
if (!confFile.readable())
if (!confFile.canRead())
throw std::string("Configuration file for '") + ftype +
"' is not available.";
}