Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool CNFSDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
- {
- // We accept nfs://server/path[/file]]]]
- int ret = 0;
- FILETIME fileTime, localTime;
- CSingleLock lock(gNfsConnection);
- CURL url(strPath);
- if(!gNfsConnection.Connect(url))
- {
- return false;
- }
- CStdString strDirName="//";//relative to the strPath we connected - we want to get the "/" directory then
- vector<CStdString> vecEntries;
- struct nfsdir *nfsdir = NULL;
- struct nfsdirent *nfsdirent = NULL;
- ret = gNfsConnection.GetImpl()->nfs_opendir_sync(gNfsConnection.GetNfsContext(), strDirName.c_str(), &nfsdir);
- if(ret != 0)
- {
- CLog::Log(LOGERROR, "Failed to open(%s) %s\n", strDirName.c_str(), gNfsConnection.GetImpl()->nfs_get_error(gNfsConnection.GetNfsContext()));
- return false;
- }
- lock.Leave();
- while((nfsdirent = gNfsConnection.GetImpl()->nfs_readdir(gNfsConnection.GetNfsContext(), nfsdir)) != NULL)
- {
- vecEntries.push_back(nfsdirent->name);
- }
- lock.Enter();
- gNfsConnection.GetImpl()->nfs_closedir(gNfsConnection.GetNfsContext(), nfsdir);//close the dir
- lock.Leave();
- for (size_t i=0; i<vecEntries.size(); i++)
- {
- CStdString strName = vecEntries[i];
- if (!strName.Equals(".") && !strName.Equals("..")
- && !strName.Equals("lost+found"))
- {
- int64_t iSize = 0;
- bool bIsDir = false;
- int64_t lTimeDate = 0;
- struct stat info = {0};
- CStdString strFullName = strDirName + strName;
- lock.Enter();
- ret = gNfsConnection.GetImpl()->nfs_stat_sync(gNfsConnection.GetNfsContext(), strFullName.c_str(), &info);
- lock.Leave();
- if( ret == 0 )
- {
- bIsDir = (info.st_mode & S_IFDIR) ? true : false;
- lTimeDate = info.st_mtime;
- if(lTimeDate == 0) // if modification date is missing, use create date
- lTimeDate = info.st_ctime;
- iSize = info.st_size;
- }
- else
- CLog::Log(LOGERROR, "NFS; Failed to stat(%s) %s\n", strFullName.c_str(), gNfsConnection.GetImpl()->nfs_get_error(gNfsConnection.GetNfsContext()));
- LONGLONG ll = Int32x32To64(lTimeDate & 0xffffffff, 10000000) + 116444736000000000ll;
- fileTime.dwLowDateTime = (DWORD) (ll & 0xffffffff);
- fileTime.dwHighDateTime = (DWORD)(ll >> 32);
- FileTimeToLocalFileTime(&fileTime, &localTime);
- CFileItemPtr pItem(new CFileItem(strName));
- pItem->m_strPath = strPath + strName;
- pItem->m_dateTime=localTime;
- if (bIsDir)
- {
- URIUtils::AddSlashAtEnd(pItem->m_strPath);
- pItem->m_bIsFolder = true;
- }
- else
- {
- pItem->m_bIsFolder = false;
- pItem->m_dwSize = iSize;
- }
- items.Add(pItem);
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement