Repository: xbmc/xbmc
File: xbmc/filesystem/NFSDirectory.cpp (C++)

Code before:
{
  gNfsConnection.AddIdleConnection();
}

std::vector<CFileItemPtr> CNFSDirectory::GetDirectoryFromExportList(const CURL& inputURL)
{
  std::string pathWithSlash(inputURL.Get());
  URIUtils::AddSlashAtEnd(pathWithSlash); //be sure the dir ends with a slash

  CURL url(pathWithSlash);

  std::string pathWithoutSlash(pathWithSlash);
  URIUtils::RemoveSlashAtEnd(pathWithoutSlash);

  std::list<std::string> exportList=gNfsConnection.GetExportList(url);

  std::vector<CFileItemPtr> fileItems;
  for (const std::string& currentExport : exportList)
  {
    std::string path(pathWithoutSlash + currentExport);
    URIUtils::AddSlashAtEnd(path);

    CFileItemPtr& item = fileItems.emplace_back(std::make_shared<CFileItem>(currentExport));
    item->SetPath(path);
    item->SetDateTime(0);
    item->SetFolder(true);
  }
  return fileItems;
}

std::vector<CFileItemPtr> CNFSDirectory::GetServerList()
{
  struct nfs_server_list* srvrs = nfs_find_local_servers();
  std::vector<CFileItemPtr> fileItems;
  for (struct nfs_server_list* srv = srvrs; srv; srv = srv->next)
  {
    std::string serverAddress = srv->addr;

    std::string path("nfs://" + serverAddress);
    URIUtils::AddSlashAtEnd(path);

    CFileItemPtr& item = fileItems.emplace_back(std::make_shared<CFileItem>(serverAddress));
    item->SetPath(path);
    item->SetDateTime(0);
    item->SetFolder(true);
  }
  free_nfs_srvr_list(srvrs);

  return fileItems;
}


Review comment (suggestion):
As a suggestion: `CFileItem`has a ctor taking both path and folderflag and it also has a `SetLabel` method. so, we could save some code in the PR if we switch to that pattern:

```c++
    std::shared_ptr<CFileItem>& item{fileItems.emplace_back(std::make_shared<CFileItem>(path, true))};
    item->SetLabel(currentExport)
    item->SetDateTime(0);
```

Over time, we want to get rid of typedef for `CFileItemPtr. We want to use the native type instead.

Code after:
{
  gNfsConnection.AddIdleConnection();
}

std::vector<CFileItemPtr> CNFSDirectory::GetDirectoryFromExportList(const CURL& inputURL)
{
  std::string pathWithSlash(inputURL.Get());
  URIUtils::AddSlashAtEnd(pathWithSlash); //be sure the dir ends with a slash

  CURL url(pathWithSlash);

  std::string pathWithoutSlash(pathWithSlash);
  URIUtils::RemoveSlashAtEnd(pathWithoutSlash);

  std::list<std::string> exportList=gNfsConnection.GetExportList(url);

  std::vector<CFileItemPtr> fileItems;
  for (const std::string& currentExport : exportList)
  {
    std::string path(pathWithoutSlash + currentExport);
    URIUtils::AddSlashAtEnd(path);

    auto& item = fileItems.emplace_back(std::make_shared<CFileItem>(currentExport));
    item->SetPath(path);
    item->SetDateTime(0);
    item->SetFolder(true);
  }
  return fileItems;
}

std::vector<CFileItemPtr> CNFSDirectory::GetServerList()
{
  struct nfs_server_list* srvrs = nfs_find_local_servers();
  std::vector<CFileItemPtr> fileItems;
  for (struct nfs_server_list* srv = srvrs; srv; srv = srv->next)
  {
    std::string serverAddress = srv->addr;

    std::string path("nfs://" + serverAddress);
    URIUtils::AddSlashAtEnd(path);

    auto& item = fileItems.emplace_back(std::make_shared<CFileItem>(serverAddress));
    item->SetPath(path);
    item->SetDateTime(0);
    item->SetFolder(true);
  }
  free_nfs_srvr_list(srvrs);

  return fileItems;
}