예제 #1
0
status_t
ParseRequest(int32 code, void* buffer)
{
	switch (code) {
		case MsgNameToUID:
			return NameToUID(buffer);

		case MsgUIDToName:
			return UIDToName(buffer);

		case MsgNameToGID:
			return NameToGID(buffer);

		case MsgGIDToName:
			return GIDToName(buffer);

		default:
			return SendError(B_BAD_VALUE);
	}
}
예제 #2
0
파일: dirlist.cpp 프로젝트: cm277/ebftpd
void DirectoryList::ListPath(const fs::Path& path, std::queue<std::string> masks, int depth) const
{
  if (maxRecursion && depth > maxRecursion) return;

  fs::DirEnumerator dirEnum;
  try
  {
    Readdir(path, dirEnum);
  }
  catch (const util::SystemError& e)
  {
    // silent failure - gives empty directory list
    return;
  }

  if (depth > 1) Output("\r\n");
  
  std::ostringstream message;
  if (!path.Empty() && (options.Recursive() || !masks.empty() || depth > 1))
  {
    message << path << ":\r\n";
    Output(message.str());
    message.str("");
  }
  
  if (options.LongFormat())
  {
    message << "total "
            << std::floor(dirEnum.TotalBytes() / 1024)
            << "\r\n";
    Output(message.str());
    message.str("");
  }
  
  std::string mask;
  if (!masks.empty())
  {
    mask = masks.front();
    masks.pop();
  }

  if (masks.empty())
  {
    for (const auto& de : dirEnum)
    {
      const std::string& pathStr = de.Path();      
      if (pathStr[0] == '.' && !options.All()) continue;
      if (!mask.empty() && fnmatch(mask.c_str(), pathStr.c_str(), 0)) continue;
      
      if (options.LongFormat())
      {
        message << Permissions(de.Status()) << " "
                << std::setw(3) << de.Status().Native().st_nlink << " "
                << std::left << std::setw(10) 
                << UIDToName(de.Owner().UID()).substr(0, 10) << " "
                << std::left << std::setw(10) 
                << GIDToName(de.Owner().GID()).substr(0, 10) << " "
                << std::right << std::setw(8) << de.Status().Size() << " "
                << Timestamp(de.Status()) << " "
                << de.Path();
        if (options.SlashDirs() && de.Status().IsDirectory()) message << "/";
        message << "\r\n";
        Output(message.str());
        message.str("");
      }
      else
      {
        message << de.Path() << "\r\n";
        Output(message.str());
        message.str("");
      }
    }
  }
  
  if (options.Recursive() || !mask.empty())
  {
    for (const auto& de : dirEnum)
    {
      if (!de.Status().IsDirectory() ||
           de.Status().IsSymLink()) continue;
           
      const std::string& pathStr = de.Path();      
      if (pathStr[0] == '.' && !options.All()) continue;
      if (!mask.empty() && fnmatch(mask.c_str(), pathStr.c_str(), 0)) continue;

      fs::Path fullPath(path);
      fullPath /= de.Path();
   
      ListPath(fullPath, masks, depth + 1);
    }
  }
}