Permalink
Browse files

Io: Prevent cur/parent dir in listing of root.

See #9344.  Matches tests.
  • Loading branch information...
unknownbrackets committed Aug 13, 2018
1 parent 1fdb1f7 commit 7a058180bbfd2d9080a8587b8640f5fbd02d78aa
Showing with 7 additions and 3 deletions.
  1. +7 −3 Core/FileSystems/DirectoryFileSystem.cpp
@@ -825,6 +825,8 @@ static std::string SimulateVFATBug(std::string filename) {
std::vector<PSPFileInfo> DirectoryFileSystem::GetDirListing(std::string path) {
std::vector<PSPFileInfo> myVector;
bool listingRoot = path == "/" || path == "\\";
#ifdef _WIN32
WIN32_FIND_DATA findData;
HANDLE hFind;
@@ -849,15 +851,16 @@ std::vector<PSPFileInfo> DirectoryFileSystem::GetDirListing(std::string path) {
entry.access = entry.type == FILETYPE_NORMAL ? 0666 : 0777;
// TODO: is this just for .. or all subdirectories? Need to add a directory to the test
// to find out. Also why so different than the old test results?
if (!wcscmp(findData.cFileName, L"..") )
if (!wcscmp(findData.cFileName, L".."))
entry.size = 4096;
else
entry.size = findData.nFileSizeLow | ((u64)findData.nFileSizeHigh<<32);
entry.name = SimulateVFATBug(ConvertWStringToUTF8(findData.cFileName));
tmFromFiletime(entry.atime, findData.ftLastAccessTime);
tmFromFiletime(entry.ctime, findData.ftCreationTime);
tmFromFiletime(entry.mtime, findData.ftLastWriteTime);
myVector.push_back(entry);
if (!listingRoot || (wcscmp(findData.cFileName, L"..") && wcscmp(findData.cFileName, L".")))
myVector.push_back(entry);
int retval = FindNextFile(hFind, &findData);
if (!retval)
@@ -897,7 +900,8 @@ std::vector<PSPFileInfo> DirectoryFileSystem::GetDirListing(std::string path) {
localtime_r((time_t*)&s.st_atime,&entry.atime);
localtime_r((time_t*)&s.st_ctime,&entry.ctime);
localtime_r((time_t*)&s.st_mtime,&entry.mtime);
myVector.push_back(entry);
if (!listingRoot || (wcscmp(findData.cFileName, L"..") && wcscmp(findData.cFileName, L".")))
myVector.push_back(entry);
}
closedir(dp);
#endif

0 comments on commit 7a05818

Please sign in to comment.