Beispiel #1
0
//---------------------------------------------------------------------------
bool SMBSlave::browse_stat_path(const SMBUrl& _url, UDSEntry& udsentry, bool ignore_errors)
  // Returns: true on success, false on failure
{
   SMBUrl url = _url;

   int cacheStatErr = cache_stat(url, &st);
   if(cacheStatErr == 0)
   {
      if(!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
      {
         qCDebug(KIO_SMB) << "mode: "<< st.st_mode;
         warning(i18n("%1:\n"
                      "Unknown file type, neither directory or file.", url.toDisplayString()));
         return false;
      }

      udsentry.insert(KIO::UDSEntry::UDS_FILE_TYPE, st.st_mode & S_IFMT);
      udsentry.insert(KIO::UDSEntry::UDS_SIZE, st.st_size);

      QString str;
      uid_t uid = st.st_uid;
      struct passwd *user = getpwuid( uid );
      if ( user )
          str = user->pw_name;
      else
          str = QString::number( uid );
      udsentry.insert(KIO::UDSEntry::UDS_USER, str);

      gid_t gid = st.st_gid;
      struct group *grp = getgrgid( gid );
      if ( grp )
          str = grp->gr_name;
      else
          str = QString::number( gid );
      udsentry.insert(KIO::UDSEntry::UDS_GROUP, str);

      udsentry.insert(KIO::UDSEntry::UDS_ACCESS, st.st_mode & 07777);
      udsentry.insert(KIO::UDSEntry::UDS_MODIFICATION_TIME, st.st_mtime);
      udsentry.insert(KIO::UDSEntry::UDS_ACCESS_TIME, st.st_atime);
      // No, st_ctime is not UDS_CREATION_TIME...
   }
   else
   {
       if (!ignore_errors) {
           if (cacheStatErr == EPERM || cacheStatErr == EACCES)
               if (checkPassword(url)) {
                   redirection( url );
                   return false;
               }

           reportError(url, cacheStatErr);
       } else if (cacheStatErr == ENOENT || cacheStatErr == ENOTDIR) {
           warning(i18n("File does not exist: %1", url.url()));
       }
       qCDebug(KIO_SMB) << "ERROR!!";
       return false;
   }

   return true;
}
//---------------------------------------------------------------------------
bool SMBSlave::browse_stat_path(const SMBUrl &_url, UDSEntry &udsentry, bool ignore_errors)
// Returns: true on success, false on failure
{
    UDSAtom udsatom;

    SMBUrl url = _url;

    if(cache_stat(url, &st) == 0)
    {
        if(!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
        {
            kdDebug(KIO_SMB) << "SMBSlave::browse_stat_path mode: " << st.st_mode << endl;
            warning(i18n("%1:\n"
                         "Unknown file type, neither directory or file.")
                        .arg(url.prettyURL()));
            return false;
        }

        udsatom.m_uds = KIO::UDS_FILE_TYPE;
        udsatom.m_long = st.st_mode & S_IFMT;
        udsentry.append(udsatom);

        udsatom.m_uds = KIO::UDS_SIZE;
        udsatom.m_long = st.st_size;
        udsentry.append(udsatom);

        udsatom.m_uds = KIO::UDS_USER;
        uid_t uid = st.st_uid;
        struct passwd *user = getpwuid(uid);
        if(user)
            udsatom.m_str = user->pw_name;
        else
            udsatom.m_str = QString::number(uid);
        udsentry.append(udsatom);

        udsatom.m_uds = KIO::UDS_GROUP;
        gid_t gid = st.st_gid;
        struct group *grp = getgrgid(gid);
        if(grp)
            udsatom.m_str = grp->gr_name;
        else
            udsatom.m_str = QString::number(gid);
        udsentry.append(udsatom);

        udsatom.m_uds = KIO::UDS_ACCESS;
        udsatom.m_long = st.st_mode & 07777;
        udsentry.append(udsatom);

        udsatom.m_uds = UDS_MODIFICATION_TIME;
        udsatom.m_long = st.st_mtime;
        udsentry.append(udsatom);

        udsatom.m_uds = UDS_ACCESS_TIME;
        udsatom.m_long = st.st_atime;
        udsentry.append(udsatom);

        udsatom.m_uds = UDS_CREATION_TIME;
        udsatom.m_long = st.st_ctime;
        udsentry.append(udsatom);
    }
    else
    {
        if(!ignore_errors)
        {
            if(errno == EPERM || errno == EACCES)
                if(checkPassword(url))
                {
                    redirection(url);
                    return false;
                }

            reportError(url);
        }
        else if(errno == ENOENT || errno == ENOTDIR)
        {
            warning(i18n("File does not exist: %1").arg(url.url()));
        }
        kdDebug(KIO_SMB) << "SMBSlave::browse_stat_path ERROR!!" << endl;
        return false;
    }

    return true;
}