本文整理汇总了C++中FilePath::removeIfExists方法的典型用法代码示例。如果您正苦于以下问题:C++ FilePath::removeIfExists方法的具体用法?C++ FilePath::removeIfExists怎么用?C++ FilePath::removeIfExists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilePath
的用法示例。
在下文中一共展示了FilePath::removeIfExists方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExecuteChunkOperation
ExecuteChunkOperation(const std::string& docId,
const std::string& chunkId,
const std::string& nbCtxId,
const ShellCommand& command,
const core::FilePath& scriptPath)
: terminationRequested_(false),
docId_(docId),
chunkId_(chunkId),
nbCtxId_(nbCtxId),
command_(command),
scriptPath_(scriptPath)
{
using namespace core;
Error error = Success();
// ensure regular directory
FilePath outputPath = chunkOutputPath(
docId_,
chunkId_,
ContextExact);
error = outputPath.removeIfExists();
if (error)
LOG_ERROR(error);
error = outputPath.ensureDirectory();
if (error)
LOG_ERROR(error);
// clean old chunk output
error = cleanChunkOutput(docId_, chunkId_, nbCtxId_, true);
if (error)
LOG_ERROR(error);
}
示例2: onShutdown
void onShutdown(bool terminatedNormally)
{
FilePath activeDocumentFile =
module_context::resolveAliasedPath("~/.active-rstudio-document");
Error error = activeDocumentFile.removeIfExists();
if (error)
LOG_ERROR(error);
}
示例3: removeContentUrl
Error removeContentUrl(const json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
// get content url
std::string contentUrl;
Error error = json::readParams(request.params, &contentUrl);
if (error)
return error;
// get content file info
std::string title;
FilePath contentFilePath;
error = contentFileInfo(contentUrl, &title, &contentFilePath);
if (error)
return error;
// remove it
return contentFilePath.removeIfExists();
}
示例4: completeUpload
Error completeUpload(const core::json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
// read params
json::Object token;
bool commit ;
Error error = json::readParams(request.params, &token, &commit);
if (error)
return error ;
// parse fields out of token object
std::string filename, uploadedTempFile, targetDirectory;
error = json::readObject(token,
kUploadFilename, &filename,
kUploadedTempFile, &uploadedTempFile,
kUploadTargetDirectory, &targetDirectory);
if (error)
return error;
// get path to temp file
FilePath uploadedTempFilePath(uploadedTempFile);
// commit or cancel
if (commit)
{
FilePath targetDirectoryPath(targetDirectory);
if (uploadedTempFilePath.extensionLowerCase() == ".zip")
{
// expand the archive
r::exec::RFunction unzip("unzip");
unzip.addParam("zipfile", uploadedTempFilePath.absolutePath());
unzip.addParam("exdir", targetDirectoryPath.absolutePath());
Error unzipError = unzip.call();
if (unzipError)
return unzipError;
// remove the __MACOSX folder if it exists
const std::string kMacOSXFolder("__MACOSX");
FilePath macOSXPath = targetDirectoryPath.complete(kMacOSXFolder);
Error removeError = macOSXPath.removeIfExists();
if (removeError)
LOG_ERROR(removeError);
}
else
{
// calculate target path
FilePath targetPath = targetDirectoryPath.childPath(filename);
// remove existing target path
Error removeError = targetPath.removeIfExists();
if (removeError)
return removeError;
// copy the source to the destination
Error copyError = uploadedTempFilePath.copy(targetPath);
if (copyError)
return copyError;
}
// remove the uploaded temp file
error = uploadedTempFilePath.remove();
if (error)
LOG_ERROR(error);
// check quota after uploads
quotas::checkQuotaStatus();
return Success();
}
else
{
// merely log failures to remove the temp file (not critical to the user)
Error error = uploadedTempFilePath.removeIfExists();
if (error)
LOG_ERROR(error);
return Success();
}
}
示例5: createSshKey
Error createSshKey(const json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
std::string path, type, passphrase;
bool overwrite;
Error error = json::readObjectParam(request.params, 0,
"path", &path,
"type", &type,
"passphrase", &passphrase,
"overwrite", &overwrite);
if (error)
return error;
#ifdef RSTUDIO_SERVER
// In server mode, passphrases are encrypted
using namespace rstudio::core::system::crypto;
error = rsaPrivateDecrypt(passphrase, &passphrase);
if (error)
return error;
#endif
// resolve key path
FilePath sshKeyPath = module_context::resolveAliasedPath(path);
FilePath sshPublicKeyPath = sshKeyPath.parent().complete(
sshKeyPath.stem() + ".pub");
if (sshKeyPath.exists() || sshPublicKeyPath.exists())
{
if (!overwrite)
{
json::Object resultJson;
resultJson["failed_key_exists"] = true;
pResponse->setResult(resultJson);
return Success();
}
else
{
Error error = sshKeyPath.removeIfExists();
if (error)
return error;
error = sshPublicKeyPath.removeIfExists();
if (error)
return error;
}
}
// compose a shell command to create the key
shell_utils::ShellCommand cmd("ssh-keygen");
// type
cmd << "-t" << type;
// passphrase (optional)
cmd << "-N";
if (!passphrase.empty())
cmd << passphrase;
else
cmd << std::string("");
// path
cmd << "-f" << sshKeyPath;
// process options
core::system::ProcessOptions options;
// detach the session so there is no terminal
#ifndef _WIN32
options.detachSession = true;
#endif
// customize the environment on Win32
#ifdef _WIN32
core::system::Options childEnv;
core::system::environment(&childEnv);
// set HOME to USERPROFILE
std::string userProfile = core::system::getenv(childEnv, "USERPROFILE");
core::system::setenv(&childEnv, "HOME", userProfile);
// add msys_ssh to path
core::system::addToPath(&childEnv,
session::options().msysSshPath().absolutePath());
options.environment = childEnv;
#endif
// run it
core::system::ProcessResult result;
error = runCommand(shell_utils::sendStdErrToStdOut(cmd),
options,
&result);
if (error)
return error;
// return exit code and output
json::Object resultJson;
resultJson["failed_key_exists"] = false;
resultJson["exit_status"] = result.exitStatus;
resultJson["output"] = result.stdOut;
pResponse->setResult(resultJson);
return Success();
//.........这里部分代码省略.........