本文整理汇总了C++中FilePath::absolutePath方法的典型用法代码示例。如果您正苦于以下问题:C++ FilePath::absolutePath方法的具体用法?C++ FilePath::absolutePath怎么用?C++ FilePath::absolutePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilePath
的用法示例。
在下文中一共展示了FilePath::absolutePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isSharedPath
bool isSharedPath(const std::string& projectPath,
const core::FilePath& userHomePath)
{
#ifndef _WIN32
// ensure this is a real path
FilePath projectDir = FilePath::resolveAliasedPath(projectPath,
userHomePath);
if (!projectDir.exists())
return false;
struct stat st;
if (::stat(projectDir.absolutePath().c_str(), &st) == 0)
{
// consider this project to be shared if we aren't the owner
if (st.st_uid != ::geteuid())
{
return true;
}
}
else
{
Error error = systemError(errno, ERROR_LOCATION);
error.addProperty("path", projectDir.absolutePath());
LOG_ERROR(error);
}
#endif
return false;
}
示例2: addToSystemPath
void addToSystemPath(const FilePath& path, bool prepend)
{
std::string systemPath = system::getenv("PATH");
if (prepend)
systemPath = path.absolutePath() + ":" + systemPath;
else
systemPath = systemPath + ":" + path.absolutePath();
system::setenv("PATH", systemPath);
}
示例3: readStringFromFile
Error readStringFromFile(const FilePath& filePath,
std::string* pStr,
string_utils::LineEnding lineEnding)
{
using namespace boost::system::errc ;
// open file
boost::shared_ptr<std::istream> pIfs;
Error error = filePath.open_r(&pIfs);
if (error)
return error;
try
{
// set exception mask (required for proper reporting of errors)
pIfs->exceptions(std::istream::failbit | std::istream::badbit);
// copy file to string stream
std::ostringstream ostr;
boost::iostreams::copy(*pIfs, ostr);
*pStr = ostr.str();
string_utils::convertLineEndings(pStr, lineEnding);
// return success
return Success();
}
catch(const std::exception& e)
{
Error error = systemError(boost::system::errc::io_error,
ERROR_LOCATION);
error.addProperty("what", e.what());
error.addProperty("path", filePath.absolutePath());
return error;
}
}
示例4: writeStringToFile
Error writeStringToFile(const FilePath& filePath,
const std::string& str,
string_utils::LineEnding lineEnding)
{
using namespace boost::system::errc ;
// open file
boost::shared_ptr<std::ostream> pOfs;
Error error = filePath.open_w(&pOfs);
if (error)
return error;
try
{
// set exception mask (required for proper reporting of errors)
pOfs->exceptions(std::ostream::failbit | std::ostream::badbit);
// copy string to file
std::string normalized = str;
string_utils::convertLineEndings(&normalized, lineEnding);
std::istringstream istr(normalized);
boost::iostreams::copy(istr, *pOfs);
// return success
return Success();
}
catch(const std::exception& e)
{
Error error = systemError(boost::system::errc::io_error,
ERROR_LOCATION);
error.addProperty("what", e.what());
error.addProperty("path", filePath.absolutePath());
return error;
}
}
示例5: texFilePath
FilePath texFilePath(const std::string& logPath, const FilePath& compileDir)
{
// some tex compilers report file names with absolute paths and some
// report them relative to the compilation directory -- on Posix use
// realPath to get a clean full path back -- note the fact that we
// don't do this on Windows is a tacit assumption that Windows TeX logs
// are either absolute or don't require interpretation of .., etc.
FilePath path = compileDir.complete(logPath);
#ifdef _WIN32
return path;
#else
FilePath realPath;
Error error = core::system::realPath(path.absolutePath(), &realPath);
if (error)
{
LOG_ERROR(error);
return path;
}
else
{
return realPath;
}
#endif
}
示例6: validate
bool validate(const FilePath& userHomePath,
bool projectSharingEnabled) const
{
// ensure the scratch path and properties paths exist
if (!scratchPath_.exists() || !propertiesPath_.exists())
return false;
// ensure the properties are there
if (project().empty() || workingDir().empty() || (lastUsed() == 0))
return false;
// for projects validate that the base directory still exists
std::string theProject = project();
if (theProject != kProjectNone)
{
FilePath projectDir = FilePath::resolveAliasedPath(theProject,
userHomePath);
if (!projectDir.exists())
return false;
// check for project file
FilePath projectPath = r_util::projectFromDirectory(projectDir);
if (!projectPath.exists())
return false;
// if we got this far the scope is valid, do one final check for
// trying to open a shared project if sharing is disabled
if (!projectSharingEnabled &&
r_util::isSharedPath(projectPath.absolutePath(), userHomePath))
return false;
}
// validated!
return true;
}
示例7: changeFileMode
inline Error changeFileMode(const FilePath& filePath, FileMode fileMode)
{
mode_t mode ;
switch(fileMode)
{
case UserReadWriteMode:
mode = S_IRUSR | S_IWUSR;
break;
case UserReadWriteGroupReadMode:
mode = S_IRUSR | S_IWUSR | S_IRGRP ;
break;
case EveryoneReadWriteMode:
mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
break;
case EveryoneReadWriteExecuteMode:
mode = S_IRWXU | S_IRWXG | S_IRWXO;
break;
default:
return systemError(ENOTSUP, ERROR_LOCATION);
}
// change the mode
errno = 0;
if (::chmod(filePath.absolutePath().c_str(), mode) < 0)
return systemError(errno, ERROR_LOCATION);
else
return Success();
}
示例8: source
Error SourceManager::source(const FilePath& filePath, bool local)
{
std::string localPrefix = local ? "local(" : "";
std::string localParam = local ? "TRUE" : "FALSE" ;
std::string localSuffix = local ? ")" : "";
// do \ escaping (for windows)
std::string path = filePath.absolutePath();
boost::algorithm::replace_all(path, "\\", "\\\\");
// Build the code. If this build is targeted for debugging, keep the source
// code around; otherwise, turn it off to conserve memory and expose fewer
// internals to the user.
std::string rCode = localPrefix + "source(\""
+ path + "\", " +
"local=" + localParam + ", " +
"echo=FALSE, " +
"verbose=FALSE, " +
#ifdef NDEBUG
"keep.source=FALSE, " +
#else
"keep.source=TRUE, " +
#endif
"encoding='UTF-8')" + localSuffix;
// record that we sourced the file.
recordSourcedFile(filePath, local);
// source the file
return r::exec::executeString(rCode);
}
示例9: showKeyboardShortcutHelp
void GwtCallback::showKeyboardShortcutHelp()
{
FilePath keyboardHelpPath = options().wwwDocsPath().complete("keyboard.htm");
QString file = QString::fromUtf8(keyboardHelpPath.absolutePath().c_str());
QUrl url = QUrl::fromLocalFile(file);
desktop::openUrl(url);
}
示例10: saveDefaultGlobalEnvironment
Error saveDefaultGlobalEnvironment()
{
// path to save to
FilePath globalEnvPath = rSaveGlobalEnvironmentFilePath();
// notify client of serialization status
SerializationCallbackScope cb(kSerializationActionSaveDefaultWorkspace,
globalEnvPath);
// suppress interrupts which occur during saving
r::exec::IgnoreInterruptsScope ignoreInterrupts;
// save global environment
std::string path = string_utils::utf8ToSystem(globalEnvPath.absolutePath());
Error error = r::exec::executeSafely(
boost::bind(R_SaveGlobalEnvToFile, path.c_str()));
if (error)
{
return error;
}
else
{
return Success();
}
}
示例11: restoreDefaultGlobalEnvironment
Error restoreDefaultGlobalEnvironment()
{
// restore the default global environment if there is one
FilePath globalEnvPath = s_options.startupEnvironmentFilePath;
if (globalEnvPath.exists())
{
// notify client of serialization status
SerializationCallbackScope cb(kSerializationActionLoadDefaultWorkspace,
globalEnvPath);
// ignore interrupts which occur during restoring of the global env
// the restoration will run to completion in any case and then the
// next thing the user does will be "interrupted" -- clearly not
// what they intended
r::exec::IgnoreInterruptsScope ignoreInterrupts;
Error error = r::exec::executeSafely(boost::bind(
R_RestoreGlobalEnvFromFile,
globalEnvPath.absolutePath().c_str(),
TRUE));
if (error)
return error;
// print path to console
std::string aliasedPath = createAliasedPath(globalEnvPath);
Rprintf(("[Workspace loaded from " + aliasedPath + "]\n\n").c_str());
}
// mark image clean (we need to do this due to our delayed handling
// of workspace restoration)
markImageClean();
return Success();
}
示例12: detectZipFileOverwrites
Error detectZipFileOverwrites(const FilePath& uploadedZipFile,
const FilePath& destDir,
json::Array* pOverwritesJson)
{
// query for all of the paths in the zip file
std::vector<std::string> zipFileListing;
r::exec::RFunction listZipFile(".rs.listZipFile",
uploadedZipFile.absolutePath());
Error unzipError = listZipFile.call(&zipFileListing);
if (unzipError)
return unzipError;
// check for overwrites
for (std::vector<std::string>::const_iterator
it = zipFileListing.begin();
it != zipFileListing.end();
++it)
{
FilePath filePath = destDir.complete(*it);
if (filePath.exists())
pOverwritesJson->push_back(module_context::createFileSystemItem(filePath));
}
return Success();
}
示例13: rs_pathInfo
SEXP rs_pathInfo(SEXP pathSEXP)
{
try
{
// validate
if (r::sexp::length(pathSEXP) != 1)
{
throw r::exec::RErrorException(
"must pass a single file to get path info for");
}
std::string path;
Error error = r::sexp::extract(pathSEXP, &path);
if (error)
throw r::exec::RErrorException(r::endUserErrorMessage(error));
// resolve aliased path
FilePath filePath = module_context::resolveAliasedPath(path);
if (filePath.empty())
throw r::exec::RErrorException("invalid path: " + path);
// create path info vector (use json repsesentation to force convertion
// to VECSXP rather than STRSXP)
json::Object pathInfo;
pathInfo["path"] = filePath.absolutePath();
std::string parent = filePath.absolutePath();
FilePath parentPath = filePath.parent();
if (!parentPath.empty())
parent = parentPath.absolutePath();
pathInfo["directory"] = parent;
pathInfo["name"] = filePath.filename();
pathInfo["stem"] = filePath.stem();
pathInfo["extension"] = filePath.extension();
// return it
r::sexp::Protect rProtect;
return r::sexp::create(pathInfo, &rProtect);
}
catch(r::exec::RErrorException e)
{
r::exec::error(e.message());
}
CATCH_UNEXPECTED_EXCEPTION
return R_NilValue;
}
示例14: save
Error PlotManipulator::save(const FilePath& filePath) const
{
// call manipulator save
r::exec::RFunction manipSave("manipulate:::manipulatorSave");
manipSave.addParam(sexp_.get());
manipSave.addParam(filePath.absolutePath());
return manipSave.call();
}
示例15: setWorkingDirectoryValue
void UserSettings::setWorkingDirectoryValue(const std::string& key,
const FilePath& filePath)
{
if (module_context::createAliasedPath(filePath) == "~")
settings_.set(key, std::string("~"));
else
settings_.set(key, filePath.absolutePath());
}