Example #1
0
bool CAFPFile::Rename(const CURL& url, const CURL& urlnew)
{
    CSingleLock lock(gAfpConnection);
    if (gAfpConnection.Connect(url) != CAfpConnection::AfpOk || !gAfpConnection.GetVolume())
        return false;

    std::string strFile = gAfpConnection.GetPath(url);
    std::string 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);
}
Example #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;
}
Example #3
0
bool CAFPFile::Delete(const CURL& url)
{
  CSingleLock lock(gAfpConnection);
  if (gAfpConnection.Connect(url) != CAfpConnection::AfpOk || !gAfpConnection.GetVolume())
    return false;

  CStdString 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);
}
Example #4
0
bool CAFPFile::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;
    m_pAfpVol = gAfpConnection.GetVolume();

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

    if (gAfpConnection.GetImpl()->afp_wrap_open(m_pAfpVol, strPath.c_str(), O_RDONLY, &m_pFp))
    {
        if (gAfpConnection.GetImpl()->afp_wrap_open(m_pAfpVol, CURL::Encode(strPath.c_str()).c_str(), O_RDONLY, &m_pFp))
        {
            // write error to logfile
            CLog::Log(LOGINFO, "CAFPFile::Open: Unable to open file : '%s'\nunix_err:'%x' error : '%s'", strPath.c_str(), errno, strerror(errno));
            return false;
        }
    }

    CLog::Log(LOGDEBUG,"CAFPFile::Open - opened %s, fd=%d",url.GetFileName().c_str(), m_pFp ? m_pFp->fileid:-1);
    m_url = url;

#ifdef TARGET_POSIX
    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;
}
Example #5
0
bool CAFPFile::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;

    m_pAfpVol = gAfpConnection.GetVolume();

    std::string 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(m_pAfpVol, strPath.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
    }

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

    if (ret || m_pFp == NULL)
    {
        // write error to logfile
        CLog::Log(LOGERROR, "CAFPFile::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;
}