本文整理汇总了C++中CNfsConnection::GetContextMapId方法的典型用法代码示例。如果您正苦于以下问题:C++ CNfsConnection::GetContextMapId方法的具体用法?C++ CNfsConnection::GetContextMapId怎么用?C++ CNfsConnection::GetContextMapId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CNfsConnection
的用法示例。
在下文中一共展示了CNfsConnection::GetContextMapId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Open
bool CNFSFile::Open(const CURL& url)
{
int ret = 0;
Close();
// we can't open files like nfs://file.f or nfs://server/file.f
// if a file matches the if below return false, it can't exist on a nfs share.
if (!IsValidFile(url.GetFileName()))
{
CLog::Log(LOGNOTICE,"NFS: Bad URL : '%s'",url.GetFileName().c_str());
return false;
}
CStdString filename = "";
CSingleLock lock(gNfsConnection);
if(!gNfsConnection.Connect(url, filename))
return false;
m_pNfsContext = gNfsConnection.GetNfsContext();
m_exportPath = gNfsConnection.GetContextMapId();
ret = gNfsConnection.GetImpl()->nfs_open(m_pNfsContext, filename.c_str(), O_RDONLY, &m_pFileHandle);
if (ret != 0)
{
CLog::Log(LOGINFO, "CNFSFile::Open: Unable to open file : '%s' error : '%s'", url.GetFileName().c_str(), gNfsConnection.GetImpl()->nfs_get_error(m_pNfsContext));
m_pNfsContext = NULL;
m_exportPath.clear();
return false;
}
CLog::Log(LOGDEBUG,"CNFSFile::Open - opened %s",url.GetFileName().c_str());
m_url=url;
struct __stat64 tmpBuffer;
if( Stat(&tmpBuffer) )
{
m_url.Reset();
Close();
return false;
}
m_fileSize = tmpBuffer.st_size;//cache the size of this file
// We've successfully opened the file!
return true;
}
示例2: OpenForWrite
bool CNFSFile::OpenForWrite(const CURL& url, bool bOverWrite)
{
int ret = 0;
// we can't open files like nfs://file.f or nfs://server/file.f
// if a file matches the if below return false, it can't exist on a nfs share.
if (!IsValidFile(url.GetFileName())) return false;
Close();
CSingleLock lock(gNfsConnection);
CStdString filename = "";
if(!gNfsConnection.Connect(url,filename))
return false;
m_pNfsContext = gNfsConnection.GetNfsContext();
m_exportPath = gNfsConnection.GetContextMapId();
if (bOverWrite)
{
CLog::Log(LOGWARNING, "FileNFS::OpenForWrite() called with overwriting enabled! - %s", filename.c_str());
//create file with proper permissions
ret = gNfsConnection.GetImpl()->nfs_creat(m_pNfsContext, filename.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, &m_pFileHandle);
//if file was created the file handle isn't valid ... so close it and open later
if(ret == 0)
{
gNfsConnection.GetImpl()->nfs_close(m_pNfsContext,m_pFileHandle);
m_pFileHandle = NULL;
}
}
ret = gNfsConnection.GetImpl()->nfs_open(m_pNfsContext, filename.c_str(), O_RDWR, &m_pFileHandle);
if (ret || m_pFileHandle == NULL)
{
// write error to logfile
CLog::Log(LOGERROR, "CNFSFile::Open: Unable to open file : '%s' error : '%s'", filename.c_str(), gNfsConnection.GetImpl()->nfs_get_error(gNfsConnection.GetNfsContext()));
m_pNfsContext = NULL;
m_exportPath.clear();
return false;
}
m_url=url;
struct __stat64 tmpBuffer = {0};
//only stat if file was not created
if(!bOverWrite)
{
if(Stat(&tmpBuffer))
{
m_url.Reset();
Close();
return false;
}
m_fileSize = tmpBuffer.st_size;//cache filesize of this file
}
else//file was created - filesize is zero
{
m_fileSize = 0;
}
// We've successfully opened the file!
return true;
}