Пример #1
0
int CFileAFP::Write(const void* lpBuf, int64_t uiBufSize)
{
  CSingleLock lock(gAfpConnection);
  if (m_pFp == NULL || !gAfpConnection.GetVolume())
   return -1;

  int numberOfBytesWritten = 0;
  uid_t uid;
  gid_t gid;

  // FIXME need a better way to get server's uid/gid
  uid = getuid();
  gid = getgid();
#ifdef USE_CVS_AFPFS
  char *name = m_pFp->basename;
#else
  char *name = m_pFp->name;
  if (strlen(name) == 0)
    name = m_pFp->basename;
#endif
  numberOfBytesWritten = gAfpConnection.GetImpl()->afp_wrap_write(gAfpConnection.GetVolume(),
    name, (const char *)lpBuf, (size_t)uiBufSize, m_fileOffset, m_pFp, uid, gid);

  return numberOfBytesWritten;
}
Пример #2
0
// TODO - maybe check returncode!
int CAFPFile::Stat(const CURL& url, struct __stat64* buffer)
{
    CSingleLock lock(gAfpConnection);
    if (gAfpConnection.Connect(url) != CAfpConnection::AfpOk || !gAfpConnection.GetVolume())
        return -1;

    std::string strPath = gAfpConnection.GetPath(url);

    struct stat tmpBuffer = {0};
    int iResult = gAfpConnection.GetImpl()->afp_wrap_getattr(gAfpConnection.GetVolume(), strPath.c_str(), &tmpBuffer);

    if (buffer)
    {
        memset(buffer, 0, sizeof(struct __stat64));
        buffer->st_dev   = tmpBuffer.st_dev;
        buffer->st_ino   = tmpBuffer.st_ino;
        buffer->st_mode  = tmpBuffer.st_mode;
        buffer->st_nlink = tmpBuffer.st_nlink;
        buffer->st_uid   = tmpBuffer.st_uid;
        buffer->st_gid   = tmpBuffer.st_gid;
        buffer->st_rdev  = tmpBuffer.st_rdev;
        buffer->st_size  = tmpBuffer.st_size;
        buffer->st_atime = tmpBuffer.st_atime;
        buffer->st_mtime = tmpBuffer.st_mtime;
        buffer->st_ctime = tmpBuffer.st_ctime;
    }

    return iResult;
}
Пример #3
0
unsigned int CFileAFP::Read(void *lpBuf, int64_t uiBufSize)
{
  CSingleLock lock(gAfpConnection);
  if (m_pFp == NULL || !gAfpConnection.GetVolume())
    return 0;

  if (uiBufSize > AFP_MAX_READ_SIZE)
    uiBufSize = AFP_MAX_READ_SIZE;

#ifdef USE_CVS_AFPFS
  char *name = m_pFp->basename;
#else
  char *name = m_pFp->name;
  if (strlen(name) == 0)
    name = m_pFp->basename;

#endif
  int eof = 0;
  int bytesRead = gAfpConnection.GetImpl()->afp_wrap_read(gAfpConnection.GetVolume(),
    name, (char *)lpBuf,(size_t)uiBufSize, m_fileOffset, m_pFp, &eof);
  if (bytesRead > 0)
    m_fileOffset += bytesRead;

  if (bytesRead < 0)
  {
    CLog::Log(LOGERROR, "%s - Error( %d, %d, %s )", __FUNCTION__, bytesRead, errno, strerror(errno));
    return 0;
  }

  return (unsigned int)bytesRead;
}
Пример #4
0
bool CAFPFile::Delete(const CURL& url)
{
    CSingleLock lock(gAfpConnection);
    if (gAfpConnection.Connect(url) != CAfpConnection::AfpOk || !gAfpConnection.GetVolume())
        return false;

    std::string strPath = gAfpConnection.GetPath(url);

    int result = gAfpConnection.GetImpl()->afp_wrap_unlink(gAfpConnection.GetVolume(), strPath.c_str());

    if (result != 0)
        CLog::Log(LOGERROR, "%s - Error( %s )", __FUNCTION__, strerror(errno));

    return (result == 0);
}
Пример #5
0
CAFPFile::CAFPFile()
    : m_fileSize(0)
    , m_fileOffset(0)
    , m_pFp(NULL)
    , m_pAfpVol(NULL)
{
    gAfpConnection.AddActiveConnection();
}
Пример #6
0
void CFileAFP::Close()
{
  CSingleLock lock(gAfpConnection);
  if (m_pFp != NULL && gAfpConnection.GetVolume())
  {
    CLog::Log(LOGDEBUG, "CFileAFP::Close closing fd %d", m_pFp->fileid);
#ifdef USE_CVS_AFPFS
    char *name = m_pFp->basename;
#else
    char *name = m_pFp->name;
    if (strlen(name) == 0)
      name = m_pFp->basename;
#endif
    gAfpConnection.GetImpl()->afp_wrap_close(gAfpConnection.GetVolume(), name, m_pFp);
    delete m_pFp;
    m_pFp = NULL;
  }
}
Пример #7
0
bool CFileAFP::Open(const CURL& url)
{
  Close();
  // we can't open files like afp://file.f or afp://server/file.f
  // if a file matches the if below return false, it can't exist on a afp share.
  if (!IsValidFile(url.GetFileName()))
  {
    CLog::Log(LOGNOTICE, "FileAfp: Bad URL : '%s'", url.GetFileName().c_str());
    return false;
  }

  CSingleLock lock(gAfpConnection);
  if (gAfpConnection.Connect(url) != CAfpConnection::AfpOk || !gAfpConnection.GetVolume())
    return false;

  CStdString strPath = gAfpConnection.GetPath(url);

  if (gAfpConnection.GetImpl()->afp_wrap_open(gAfpConnection.GetVolume(), strPath.c_str(), O_RDONLY, &m_pFp))
  {
    if (gAfpConnection.GetImpl()->afp_wrap_open(gAfpConnection.GetVolume(), URLEncode(strPath.c_str()).c_str(), O_RDONLY, &m_pFp))
    {
      // write error to logfile
      CLog::Log(LOGINFO, "CFileAFP::Open: Unable to open file : '%s'\nunix_err:'%x' error : '%s'", strPath.c_str(), errno, strerror(errno));
      return false;
    }
  }
  
  CLog::Log(LOGDEBUG,"CFileAFP::Open - opened %s, fd=%d",url.GetFileName().c_str(), m_pFp ? m_pFp->fileid:-1);
  m_url = url;
  
#ifdef _LINUX
  struct __stat64 tmpBuffer;
#else
  struct stat tmpBuffer;
#endif  
  if(Stat(&tmpBuffer))
  {
    m_url.Reset();
    Close();
    return false;
  }

  m_fileSize = tmpBuffer.st_size;
  m_fileOffset = 0;
  // We've successfully opened the file!
  return true;
}
Пример #8
0
bool CAFPFile::Rename(const CURL& url, const CURL& urlnew)
{
  CSingleLock lock(gAfpConnection);
  if (gAfpConnection.Connect(url) != CAfpConnection::AfpOk || !gAfpConnection.GetVolume())
    return false;

  CStdString strFile = gAfpConnection.GetPath(url);
  CStdString strFileNew = gAfpConnection.GetPath(urlnew);

  int result = gAfpConnection.GetImpl()->afp_wrap_rename(gAfpConnection.GetVolume(), strFile.c_str(), strFileNew.c_str());

  if (result != 0)
    CLog::Log(LOGERROR, "%s - Error( %s )", __FUNCTION__, strerror(errno));

  return (result == 0);
}
Пример #9
0
bool CFileAFP::OpenForWrite(const CURL& url, bool bOverWrite)
{

  int ret = 0;
  m_fileSize = 0;
  m_fileOffset = 0;

  Close();
  CSingleLock lock(gAfpConnection);
  if (gAfpConnection.Connect(url) != CAfpConnection::AfpOk || !gAfpConnection.GetVolume())
    return false;

  // we can't open files like afp://file.f or afp://server/file.f
  // if a file matches the if below return false, it can't exist on a afp share.
  if (!IsValidFile(url.GetFileName()))
    return false;

  CStdString strPath = gAfpConnection.GetPath(url);

  if (bOverWrite)
  {
    CLog::Log(LOGWARNING, "FileAFP::OpenForWrite() called with overwriting enabled! - %s", strPath.c_str());
    ret = gAfpConnection.GetImpl()->afp_wrap_creat(gAfpConnection.GetVolume(), strPath.c_str(), 0);
  }

  ret = gAfpConnection.GetImpl()->afp_wrap_open(gAfpConnection.GetVolume(), strPath.c_str(), O_RDWR, &m_pFp);

  if (ret || m_pFp == NULL)
  {
    // write error to logfile
    CLog::Log(LOGERROR, "CFileAFP::Open: Unable to open file : '%s'\nunix_err:'%x' error : '%s'", strPath.c_str(), errno, strerror(errno));
    return false;
  }

  // We've successfully opened the file!
  return true;
}
Пример #10
0
CAFPFile::~CAFPFile()
{
    gAfpConnection.AddIdleConnection();
    Close();
}