本文整理汇总了C++中Path_t::parent_path方法的典型用法代码示例。如果您正苦于以下问题:C++ Path_t::parent_path方法的具体用法?C++ Path_t::parent_path怎么用?C++ Path_t::parent_path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Path_t
的用法示例。
在下文中一共展示了Path_t::parent_path方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rmdir
int FuseContext::rmdir (const char *path)
{
namespace fs = boost::filesystem;
Path_t wrapped = m_realRoot / path;
// first we make sure that the parent directory exists
Path_t parent = wrapped.parent_path();
Path_t filename = wrapped.filename();
if( !fs::exists(parent) )
return -ENOENT;
// unlink the directory holding the file contents, the meta file,
// and the staged file
fs::remove_all( wrapped );
try
{
// remove the entry from the parent
m_backend->db().unlink( Path_t(path) );
}
catch( const std::exception& ex )
{
std::cerr << "FuseContext::rmdir: "
<< "\n path: " << path
<< "\n real: " << wrapped
<< "\n err: " << ex.what()
<< "\n";
}
return 0;
}
示例2: mkdir
int FuseContext::mkdir (const char *path, mode_t mode)
{
namespace fs = boost::filesystem;
Path_t wrapped = m_realRoot / path;
// first we make sure that the parent directory exists
Path_t parent = wrapped.parent_path();
Path_t filename = wrapped.filename();
if( !fs::exists(parent) )
return -ENOENT;
try
{
m_backend->db().mknod( Path_t(path) );
}
catch( const std::exception& ex )
{
std::cerr << "FuseContext::mkdir: "
<< "\n path: " << path
<< "\n real: " << wrapped
<< "\n err: " << ex.what()
<< "\n";
return -EINVAL;
}
// create the directory
int result = ::mkdir( wrapped.c_str(), mode );
if( result )
return -errno;
return 0;
}
示例3: open
int FuseContext::open (const char *path, struct fuse_file_info *fi)
{
namespace fs = boost::filesystem;
Path_t wrapped = m_realRoot / path;
// first we make sure that the file exists
Path_t parent = wrapped.parent_path();
Path_t filename = wrapped.filename();
if( !fs::exists(parent) )
return -ENOENT;
// make sure that the file exists, if it doesn't exist check for the
// O_CREAT flag
if( !fs::exists(wrapped) )
{
if( fi->flags | O_CREAT )
return this->create(path,0777,fi);
else
return -EEXIST;
}
// open the file
int result = ::open( wrapped.c_str(), fi->flags );
if( result < 0 )
return -errno;
// create a file descriptor for the opened file
int os_fd = result;
int my_fd = -1;
try
{
my_fd = m_openedFiles.registerFile( Path_t(path) ,os_fd);
result = 0;
}
catch( const std::exception& ex )
{
my_fd = -1;
result = -ENOMEM;
::close(os_fd);
std::cerr << "FuseContext::open"
<< "\n path: " << path
<< "\n real: " << wrapped
<< "\n err: " << ex.what();
}
fi->fh = my_fd;
return result;
}
示例4:
MetaFile::MetaFile( const Path_t& path )
{
namespace fs = boost::filesystem;
Path_t metapath;
if( fs::is_directory(path) )
{
metapath = path / "obfs.sqlite";
m_subpath = ".";
}
else
{
metapath = path.parent_path() / "obfs.sqlite";
m_subpath = path.filename().string();
}
m_sql.open( soci::sqlite3, metapath.string() );
}
示例5: create
int FuseContext::create (const char *path,
mode_t mode,
struct fuse_file_info *fi)
{
namespace fs = boost::filesystem;
Path_t wrapped = (m_realRoot / path);
// first we make sure that the parent directory exists
Path_t parent = wrapped.parent_path();
Path_t filename = wrapped.filename();
if( !fs::exists(parent) || !fs::is_directory(parent) )
return -ENOENT;
// create the local version of the file
int result = ::creat( wrapped.c_str(), mode );
if( result < 0 )
return -errno;
// create a file descriptor for the opened file
int os_fd = result;
int my_fd = -1;
try
{
// add an entry to the directory listing
m_backend->db().mknod( Path_t(path) );
my_fd = m_openedFiles.registerFile( Path_t(path) ,os_fd);
result = 0;
}
catch( const std::exception& ex )
{
my_fd = -1;
result = -EIO;
::close(os_fd);
std::cerr << "FuseContext::create: "
<< "\n path: " << path
<< "\n real: " << wrapped
<< "\n mode: " << std::hex << mode << std::dec
<< "\n";
}
fi->fh = my_fd;
return result;
}
示例6: mknod
int FuseContext::mknod (const char *path, mode_t mode, dev_t dev)
{
namespace fs = boost::filesystem;
Path_t wrapped = (m_realRoot / path);
// we do not allow special files
if( mode & ( S_IFCHR | S_IFBLK ) )
return -EINVAL;
// first we make sure that the parent directory exists
Path_t parent = wrapped.parent_path();
Path_t filename = wrapped.filename();
if( !fs::exists(parent) || !fs::is_directory(parent) )
return -ENOENT;
// create the local version of the file
int result = ::mknod( wrapped.c_str(), mode, 0 );
if( result )
return -errno;
// add an entry to the directory listing
try
{
mode_t modeMask = 0777;
mode_t typeMask = ~modeMask;
m_backend->db().mknod( Path_t(path) );
}
catch( const std::exception& ex )
{
std::cerr << "FuseContext::mknod: "
<< "\n path: " << path
<< "\n real: " << wrapped
<< "\n err: " << ex.what()
<< "\n";
}
return 0;
}
示例7: CreateDiffFile
bool rab::CreateDiffFile( Options const& options, DiffEncoders const &diffEncoders, FileInfo& fileInfo,
Path_t const& fullNew, Path_t const& fullOld, Path_t const& relativeTemp,
dung::MemoryBlock const& newFile, dung::MemoryBlock const& oldFile, PackageOutput_t &package, LogOutput_t& out )
{
Path_t fullTemp = relativeTemp.filename();
if( options.produceTemp )
{
fullTemp = options.pathToTemp / relativeTemp;
fs::create_directories( fullTemp.parent_path() );
}
dung::DiffEncoder_i* pEncoder = diffEncoders.FindEncoder( fileInfo.name, fileInfo.diffMethod );
if( pEncoder != NULL )
{
out << "Encoding " << fileInfo.diffMethod << " diff file " << GenericString( relativeTemp ) << std::endl;
dung::MemoryBlock deltaFile;
if( !pEncoder->EncodeDiffMemoryBlock( newFile.pBlock, newFile.size, oldFile.pBlock, oldFile.size, deltaFile.pBlock, deltaFile.size ) )
{
_tstring errorMessage;
pEncoder->GetErrorMessage( errorMessage );
out << "Encoding error: " << errorMessage << std::endl;
return false;
}
if( options.produceTemp )
{
if( !WriteWholeFile( fullTemp.wstring(), deltaFile ) )
{
out << "Can't write file " << GenericString( fullTemp ) << std::endl;
return false;
}
}
if( !package.WriteFile( GenericString( relativeTemp ), deltaFile.pBlock, deltaFile.size ) )
{
out << "Can't write file " << GenericString( relativeTemp ) << " to package. Size=" << deltaFile.size << std::endl;
return false;
}
}
else
{
dung::DiffEncoderExternal_i* pExternalEncoder = diffEncoders.FindExternalEncoder( fileInfo.name, fileInfo.diffMethod );
if( pExternalEncoder != NULL )
{
out << "Encoding " << fileInfo.diffMethod << " diff file " << GenericString( relativeTemp ) << std::endl;
if( !pExternalEncoder->EncodeDiffFile( GenericString(fullNew).c_str(), GenericString(fullOld).c_str(), GenericString(fullTemp).c_str() ) )
{
_tstring errorMessage;
pExternalEncoder->GetErrorMessage( errorMessage );
out << "Encoding error: " << errorMessage << std::endl;
return false;
}
dung::MemoryBlock deltaFile;
if( !ReadWholeFile( fullTemp.generic_string(), deltaFile ) )
{
out << "Can't read file " << GenericString(fullTemp) << std::endl;
return false;
}
if( !options.produceTemp )
fs::remove( fullTemp );
if( !package.WriteFile( GenericString(relativeTemp), deltaFile.pBlock, deltaFile.size ) )
{
out << "Can't write file " << GenericString(relativeTemp) << " to package. Size=" << deltaFile.size << std::endl;
return false;
}
}
else
{
out << "Can't file encoder for file " << fileInfo.name << std::endl;
return false;
}
}
return true;
}