Advertisement
Guest User

xbmc/filesystem/NFSDirectory.cpp : GetDirectory

a guest
Jul 8th, 2011
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. bool CNFSDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
  2. {
  3. // We accept nfs://server/path[/file]]]]
  4. int ret = 0;
  5. FILETIME fileTime, localTime;
  6. CSingleLock lock(gNfsConnection);
  7.  
  8. CURL url(strPath);
  9.  
  10. if(!gNfsConnection.Connect(url))
  11. {
  12. return false;
  13. }
  14.  
  15. CStdString strDirName="//";//relative to the strPath we connected - we want to get the "/" directory then
  16.  
  17. vector<CStdString> vecEntries;
  18. struct nfsdir *nfsdir = NULL;
  19. struct nfsdirent *nfsdirent = NULL;
  20.  
  21. ret = gNfsConnection.GetImpl()->nfs_opendir_sync(gNfsConnection.GetNfsContext(), strDirName.c_str(), &nfsdir);
  22.  
  23. if(ret != 0)
  24. {
  25. CLog::Log(LOGERROR, "Failed to open(%s) %s\n", strDirName.c_str(), gNfsConnection.GetImpl()->nfs_get_error(gNfsConnection.GetNfsContext()));
  26. return false;
  27. }
  28. lock.Leave();
  29.  
  30. while((nfsdirent = gNfsConnection.GetImpl()->nfs_readdir(gNfsConnection.GetNfsContext(), nfsdir)) != NULL)
  31. {
  32. vecEntries.push_back(nfsdirent->name);
  33. }
  34.  
  35. lock.Enter();
  36. gNfsConnection.GetImpl()->nfs_closedir(gNfsConnection.GetNfsContext(), nfsdir);//close the dir
  37. lock.Leave();
  38.  
  39. for (size_t i=0; i<vecEntries.size(); i++)
  40. {
  41. CStdString strName = vecEntries[i];
  42.  
  43. if (!strName.Equals(".") && !strName.Equals("..")
  44. && !strName.Equals("lost+found"))
  45. {
  46. int64_t iSize = 0;
  47. bool bIsDir = false;
  48. int64_t lTimeDate = 0;
  49. struct stat info = {0};
  50.  
  51. CStdString strFullName = strDirName + strName;
  52.  
  53. lock.Enter();
  54. ret = gNfsConnection.GetImpl()->nfs_stat_sync(gNfsConnection.GetNfsContext(), strFullName.c_str(), &info);
  55. lock.Leave();
  56.  
  57. if( ret == 0 )
  58. {
  59. bIsDir = (info.st_mode & S_IFDIR) ? true : false;
  60. lTimeDate = info.st_mtime;
  61. if(lTimeDate == 0) // if modification date is missing, use create date
  62. lTimeDate = info.st_ctime;
  63. iSize = info.st_size;
  64. }
  65. else
  66. CLog::Log(LOGERROR, "NFS; Failed to stat(%s) %s\n", strFullName.c_str(), gNfsConnection.GetImpl()->nfs_get_error(gNfsConnection.GetNfsContext()));
  67.  
  68. LONGLONG ll = Int32x32To64(lTimeDate & 0xffffffff, 10000000) + 116444736000000000ll;
  69. fileTime.dwLowDateTime = (DWORD) (ll & 0xffffffff);
  70. fileTime.dwHighDateTime = (DWORD)(ll >> 32);
  71. FileTimeToLocalFileTime(&fileTime, &localTime);
  72.  
  73. CFileItemPtr pItem(new CFileItem(strName));
  74. pItem->m_strPath = strPath + strName;
  75. pItem->m_dateTime=localTime;
  76.  
  77. if (bIsDir)
  78. {
  79. URIUtils::AddSlashAtEnd(pItem->m_strPath);
  80. pItem->m_bIsFolder = true;
  81. }
  82. else
  83. {
  84. pItem->m_bIsFolder = false;
  85. pItem->m_dwSize = iSize;
  86. }
  87. items.Add(pItem);
  88. }
  89. }
  90. return true;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement