From 7d53ee933c4ac75f94e3edc65128e09953e3cdde Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Thu, 28 Oct 2010 16:29:21 -0400 Subject: STORM-477 add unit test for LLDir::getNetFileInDir --HG-- branch : storm-102 --- indra/llvfs/lldir.h | 18 ++++- indra/llvfs/tests/lldir_test.cpp | 171 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+), 1 deletion(-) (limited to 'indra/llvfs') diff --git a/indra/llvfs/lldir.h b/indra/llvfs/lldir.h index 4f63c04aab..0730b0fa79 100644 --- a/indra/llvfs/lldir.h +++ b/indra/llvfs/lldir.h @@ -74,7 +74,23 @@ class LLDir // pure virtual functions virtual U32 countFilesInDir(const std::string &dirname, const std::string &mask) = 0; - virtual BOOL getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname, BOOL wrap) = 0; + + /// Walk the files in a directory, with file pattern matching + virtual BOOL getNextFileInDir(const std::string &dirname, ///< directory path - must end in trailing slash! + const std::string &mask, ///< file pattern string (use "*" for all) + std::string &fname, ///< found file name + BOOL wrap ///< DEPRECATED - set to FALSE + ) = 0; + /**< + * @returns true if a file was found, false if the entire directory has been scanned. + * + * @note that this function is NOT thread safe + * + * This function may not be used to scan part of a directory, then start a new search of a different + * directory, and then restart the first search where it left off. + * + * @todo this really should be rewritten as an iterator object. + */ virtual void getRandomFileInDir(const std::string &dirname, const std::string &mask, std::string &fname) = 0; virtual std::string getCurPath() = 0; virtual BOOL fileExists(const std::string &filename) const = 0; diff --git a/indra/llvfs/tests/lldir_test.cpp b/indra/llvfs/tests/lldir_test.cpp index bcffa449c8..3247e0ab83 100644 --- a/indra/llvfs/tests/lldir_test.cpp +++ b/indra/llvfs/tests/lldir_test.cpp @@ -256,5 +256,176 @@ namespace tut gDirUtilp->getExtension(dottedPathExt), "ext"); } + + std::string makeTestFile( const std::string& dir, const std::string& file ) + { + std::string delim = gDirUtilp->getDirDelimiter(); + std::string path = dir + delim + file; + LLFILE* handle = LLFile::fopen( path, "w" ); + ensure("failed to open test file '"+path+"'", handle != NULL ); + ensure("failed to write to test file '"+path+"'", !fputs("test file", handle) ); + fclose(handle); + return path; + } + + std::string makeTestDir( const std::string& dirbase ) + { + int counter; + std::string uniqueDir; + bool foundUnused; + std::string delim = gDirUtilp->getDirDelimiter(); + + for (counter=0, foundUnused=false; !foundUnused; counter++ ) + { + char counterStr[3]; + sprintf(counterStr, "%02d", counter); + uniqueDir = dirbase + counterStr; + foundUnused = ! ( LLFile::isdir(uniqueDir) || LLFile::isfile(uniqueDir) ); + } + ensure("test directory '" + uniqueDir + "' creation failed", !LLFile::mkdir(uniqueDir)); + + return uniqueDir + delim; // HACK - apparently, the trailing delimiter is needed... + } + + template<> template<> + void LLDirTest_object_t::test<5>() + // getNextFileInDir + { + std::string delim = gDirUtilp->getDirDelimiter(); + std::string dirTemp = LLFile::tmpdir(); + + // Create the same 5 file names of the two directories + const char* filenames[5] = { "file1.abc", "file2.abc", "file1.xyz", "file2.xyz", "file1.mno" }; + std::string dir1 = makeTestDir(dirTemp + "getNextFileInDir"); + std::string dir2 = makeTestDir(dirTemp + "getNextFileInDir"); + std::string dir1files[5]; + std::string dir2files[5]; + for (int i=0; i<5; i++) + { + dir1files[i] = makeTestFile(dir1, filenames[i]); + dir2files[i] = makeTestFile(dir2, filenames[i]); + } + + // Scan dir1 and see if each of the 5 files is found exactly once + std::string scan1result; + int found1 = 0; + bool filesFound1[5] = { false, false, false, false, false }; + // std::cerr << "searching '"+dir1+"' for *\n"; + while ( found1 <= 5 && gDirUtilp->getNextFileInDir(dir1, "*", scan1result, false) ) + { + found1++; + // std::cerr << " found '"+scan1result+"'\n"; + int check; + for (check=0; check < 5 && ! ( scan1result == filenames[check] ); check++) + { + } + // check is now either 5 (not found) or the index of the matching name + if (check < 5) + { + ensure( "found file '"+(std::string)filenames[check]+"' twice", ! filesFound1[check] ); + filesFound1[check] = true; + } + else + { + ensure( "found unknown file '"+(std::string)filenames[check]+"'", false); + } + } + ensure("wrong number of files found in '"+dir1+"'", found1 == 5); + + // Scan dir2 and see if only the 2 *.xyz files are found + std::string scan2result; + int found2 = 0; + bool filesFound2[5] = { false, false, false, false, false }; + // std::cerr << "searching '"+dir2+"' for *.xyz\n"; + + while ( found2 <= 5 && gDirUtilp->getNextFileInDir(dir2, "*.xyz", scan2result, false) ) + { + found2++; + // std::cerr << " found '"+scan2result+"'\n"; + int check; + for (check=0; check < 5 && ! ( scan2result == filenames[check] ); check++) + { + } + // check is now either 5 (not found) or the index of the matching name + if (check < 5) + { + ensure( "found file '"+(std::string)filenames[check]+"' twice", ! filesFound2[check] ); + filesFound2[check] = true; + } + else // check is 5 - should not happen + { + ensure( "found unknown file '"+(std::string)filenames[check]+"'", false); + } + } + ensure("wrong files found in '"+dir2+"'", + !filesFound2[0] && !filesFound2[1] && filesFound2[2] && filesFound2[3] && !filesFound2[4] ); + + + // Scan dir2 and see if only the 1 *.mno file is found + std::string scan3result; + int found3 = 0; + bool filesFound3[5] = { false, false, false, false, false }; + // std::cerr << "searching '"+dir2+"' for *.mno\n"; + + while ( found3 <= 5 && gDirUtilp->getNextFileInDir(dir2, "*.mno", scan3result, false) ) + { + found3++; + // std::cerr << " found '"+scan3result+"'\n"; + int check; + for (check=0; check < 5 && ! ( scan3result == filenames[check] ); check++) + { + } + // check is now either 5 (not found) or the index of the matching name + if (check < 5) + { + ensure( "found file '"+(std::string)filenames[check]+"' twice", ! filesFound3[check] ); + filesFound3[check] = true; + } + else // check is 5 - should not happen + { + ensure( "found unknown file '"+(std::string)filenames[check]+"'", false); + } + } + ensure("wrong files found in '"+dir2+"'", + !filesFound3[0] && !filesFound3[1] && !filesFound3[2] && !filesFound3[3] && filesFound3[4] ); + + + // Scan dir1 and see if any *.foo files are found + std::string scan4result; + int found4 = 0; + bool filesFound4[5] = { false, false, false, false, false }; + // std::cerr << "searching '"+dir1+"' for *.foo\n"; + + while ( found4 <= 5 && gDirUtilp->getNextFileInDir(dir1, "*.foo", scan4result, false) ) + { + found4++; + // std::cerr << " found '"+scan4result+"'\n"; + int check; + for (check=0; check < 5 && ! ( scan4result == filenames[check] ); check++) + { + } + // check is now either 5 (not found) or the index of the matching name + if (check < 5) + { + ensure( "found file '"+(std::string)filenames[check]+"' twice", ! filesFound4[check] ); + filesFound4[check] = true; + } + else // check is 5 - should not happen + { + ensure( "found unknown file '"+(std::string)filenames[check]+"'", false); + } + } + ensure("wrong files found in '"+dir1+"'", + !filesFound4[0] && !filesFound4[1] && !filesFound4[2] && !filesFound4[3] && !filesFound4[4] ); + + // clean up all test files and directories + for (int i=0; i<5; i++) + { + LLFile::remove(dir1files[i]); + LLFile::remove(dir2files[i]); + } + LLFile::rmdir(dir1); + LLFile::rmdir(dir2); + } } -- cgit v1.2.3 From 4fa6500b5107f9d300a6ab7b6f011fb19621b05c Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Thu, 28 Oct 2010 18:09:09 -0400 Subject: STORM-480 remove unused "wrap" parameter from LLDir::getNetFileInDir --HG-- branch : storm-102 --- indra/llvfs/lldir.cpp | 2 +- indra/llvfs/lldir.h | 3 +-- indra/llvfs/lldir_linux.cpp | 9 +-------- indra/llvfs/lldir_linux.h | 2 +- indra/llvfs/lldir_mac.cpp | 8 +------- indra/llvfs/lldir_mac.h | 2 +- indra/llvfs/lldir_solaris.cpp | 9 +-------- indra/llvfs/lldir_solaris.h | 2 +- indra/llvfs/lldir_win32.cpp | 18 +++++------------- indra/llvfs/lldir_win32.h | 2 +- indra/llvfs/tests/lldir_test.cpp | 8 ++++---- 11 files changed, 18 insertions(+), 47 deletions(-) (limited to 'indra/llvfs') diff --git a/indra/llvfs/lldir.cpp b/indra/llvfs/lldir.cpp index 938fb008c9..1179180da2 100644 --- a/indra/llvfs/lldir.cpp +++ b/indra/llvfs/lldir.cpp @@ -83,7 +83,7 @@ S32 LLDir::deleteFilesInDir(const std::string &dirname, const std::string &mask) std::string filename; std::string fullpath; S32 result; - while (getNextFileInDir(dirname, mask, filename, FALSE)) + while (getNextFileInDir(dirname, mask, filename)) { fullpath = dirname; fullpath += getDirDelimiter(); diff --git a/indra/llvfs/lldir.h b/indra/llvfs/lldir.h index 0730b0fa79..643b89199b 100644 --- a/indra/llvfs/lldir.h +++ b/indra/llvfs/lldir.h @@ -78,8 +78,7 @@ class LLDir /// Walk the files in a directory, with file pattern matching virtual BOOL getNextFileInDir(const std::string &dirname, ///< directory path - must end in trailing slash! const std::string &mask, ///< file pattern string (use "*" for all) - std::string &fname, ///< found file name - BOOL wrap ///< DEPRECATED - set to FALSE + std::string &fname ///< found file name ) = 0; /**< * @returns true if a file was found, false if the entire directory has been scanned. diff --git a/indra/llvfs/lldir_linux.cpp b/indra/llvfs/lldir_linux.cpp index a1c6669b97..cf5fdd3b4a 100644 --- a/indra/llvfs/lldir_linux.cpp +++ b/indra/llvfs/lldir_linux.cpp @@ -243,8 +243,7 @@ U32 LLDir_Linux::countFilesInDir(const std::string &dirname, const std::string & } // get the next file in the directory -// automatically wrap if we've hit the end -BOOL LLDir_Linux::getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname, BOOL wrap) +BOOL LLDir_Linux::getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname) { glob_t g; BOOL result = FALSE; @@ -276,11 +275,6 @@ BOOL LLDir_Linux::getNextFileInDir(const std::string &dirname, const std::string mCurrentDirIndex++; - if((mCurrentDirIndex >= (int)g.gl_pathc) && wrap) - { - mCurrentDirIndex = 0; - } - if(mCurrentDirIndex < (int)g.gl_pathc) { // llinfos << "getNextFileInDir: returning number " << mCurrentDirIndex << ", path is " << g.gl_pathv[mCurrentDirIndex] << llendl; @@ -309,7 +303,6 @@ BOOL LLDir_Linux::getNextFileInDir(const std::string &dirname, const std::string // get a random file in the directory -// automatically wrap if we've hit the end void LLDir_Linux::getRandomFileInDir(const std::string &dirname, const std::string &mask, std::string &fname) { S32 num_files; diff --git a/indra/llvfs/lldir_linux.h b/indra/llvfs/lldir_linux.h index 809959e873..ef4495a627 100644 --- a/indra/llvfs/lldir_linux.h +++ b/indra/llvfs/lldir_linux.h @@ -43,7 +43,7 @@ public: public: virtual std::string getCurPath(); virtual U32 countFilesInDir(const std::string &dirname, const std::string &mask); - virtual BOOL getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname, BOOL wrap); + virtual BOOL getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname); virtual void getRandomFileInDir(const std::string &dirname, const std::string &mask, std::string &fname); /*virtual*/ BOOL fileExists(const std::string &filename) const; diff --git a/indra/llvfs/lldir_mac.cpp b/indra/llvfs/lldir_mac.cpp index b41b0ec5dd..290b3bd0db 100644 --- a/indra/llvfs/lldir_mac.cpp +++ b/indra/llvfs/lldir_mac.cpp @@ -259,8 +259,7 @@ U32 LLDir_Mac::countFilesInDir(const std::string &dirname, const std::string &ma } // get the next file in the directory -// automatically wrap if we've hit the end -BOOL LLDir_Mac::getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname, BOOL wrap) +BOOL LLDir_Mac::getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname) { glob_t g; BOOL result = FALSE; @@ -292,11 +291,6 @@ BOOL LLDir_Mac::getNextFileInDir(const std::string &dirname, const std::string & mCurrentDirIndex++; - if((mCurrentDirIndex >= g.gl_pathc) && wrap) - { - mCurrentDirIndex = 0; - } - if(mCurrentDirIndex < g.gl_pathc) { // llinfos << "getNextFileInDir: returning number " << mCurrentDirIndex << ", path is " << g.gl_pathv[mCurrentDirIndex] << llendl; diff --git a/indra/llvfs/lldir_mac.h b/indra/llvfs/lldir_mac.h index 04c52dc940..f80ca47d92 100644 --- a/indra/llvfs/lldir_mac.h +++ b/indra/llvfs/lldir_mac.h @@ -43,7 +43,7 @@ public: virtual S32 deleteFilesInDir(const std::string &dirname, const std::string &mask); virtual std::string getCurPath(); virtual U32 countFilesInDir(const std::string &dirname, const std::string &mask); - virtual BOOL getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname, BOOL wrap); + virtual BOOL getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname); virtual void getRandomFileInDir(const std::string &dirname, const std::string &ask, std::string &fname); virtual BOOL fileExists(const std::string &filename) const; diff --git a/indra/llvfs/lldir_solaris.cpp b/indra/llvfs/lldir_solaris.cpp index 4323dfd44a..09a96ef6b3 100644 --- a/indra/llvfs/lldir_solaris.cpp +++ b/indra/llvfs/lldir_solaris.cpp @@ -261,8 +261,7 @@ U32 LLDir_Solaris::countFilesInDir(const std::string &dirname, const std::string } // get the next file in the directory -// automatically wrap if we've hit the end -BOOL LLDir_Solaris::getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname, BOOL wrap) +BOOL LLDir_Solaris::getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname) { glob_t g; BOOL result = FALSE; @@ -294,11 +293,6 @@ BOOL LLDir_Solaris::getNextFileInDir(const std::string &dirname, const std::stri mCurrentDirIndex++; - if((mCurrentDirIndex >= (int)g.gl_pathc) && wrap) - { - mCurrentDirIndex = 0; - } - if(mCurrentDirIndex < (int)g.gl_pathc) { // llinfos << "getNextFileInDir: returning number " << mCurrentDirIndex << ", path is " << g.gl_pathv[mCurrentDirIndex] << llendl; @@ -327,7 +321,6 @@ BOOL LLDir_Solaris::getNextFileInDir(const std::string &dirname, const std::stri // get a random file in the directory -// automatically wrap if we've hit the end void LLDir_Solaris::getRandomFileInDir(const std::string &dirname, const std::string &mask, std::string &fname) { S32 num_files; diff --git a/indra/llvfs/lldir_solaris.h b/indra/llvfs/lldir_solaris.h index 6e0c5cfc69..1c21397c38 100644 --- a/indra/llvfs/lldir_solaris.h +++ b/indra/llvfs/lldir_solaris.h @@ -43,7 +43,7 @@ public: public: virtual std::string getCurPath(); virtual U32 countFilesInDir(const std::string &dirname, const std::string &mask); - virtual BOOL getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname, BOOL wrap); + virtual BOOL getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname); virtual void getRandomFileInDir(const std::string &dirname, const std::string &mask, std::string &fname); /*virtual*/ BOOL fileExists(const std::string &filename) const; diff --git a/indra/llvfs/lldir_win32.cpp b/indra/llvfs/lldir_win32.cpp index 52d864e26f..ecfa4a07d4 100644 --- a/indra/llvfs/lldir_win32.cpp +++ b/indra/llvfs/lldir_win32.cpp @@ -247,14 +247,14 @@ U32 LLDir_Win32::countFilesInDir(const std::string &dirname, const std::string & // get the next file in the directory // automatically wrap if we've hit the end -BOOL LLDir_Win32::getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname, BOOL wrap) +BOOL LLDir_Win32::getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname) { llutf16string dirnamew = utf8str_to_utf16str(dirname); - return getNextFileInDir(dirnamew, mask, fname, wrap); + return getNextFileInDir(dirnamew, mask, fname); } -BOOL LLDir_Win32::getNextFileInDir(const llutf16string &dirname, const std::string &mask, std::string &fname, BOOL wrap) +BOOL LLDir_Win32::getNextFileInDir(const llutf16string &dirname, const std::string &mask, std::string &fname) { WIN32_FIND_DATAW FileData; @@ -290,15 +290,8 @@ BOOL LLDir_Win32::getNextFileInDir(const llutf16string &dirname, const std::stri FindClose(mDirSearch_h); mCurrentDir[0] = NULL; - if (wrap) - { - return(getNextFileInDir(pathname,"",fname,TRUE)); - } - else - { - fname[0] = 0; - return(FALSE); - } + fname[0] = 0; + return(FALSE); } else { @@ -318,7 +311,6 @@ BOOL LLDir_Win32::getNextFileInDir(const llutf16string &dirname, const std::stri // get a random file in the directory -// automatically wrap if we've hit the end void LLDir_Win32::getRandomFileInDir(const std::string &dirname, const std::string &mask, std::string &fname) { S32 num_files; diff --git a/indra/llvfs/lldir_win32.h b/indra/llvfs/lldir_win32.h index d3e45dc1f3..2ec9025250 100644 --- a/indra/llvfs/lldir_win32.h +++ b/indra/llvfs/lldir_win32.h @@ -40,7 +40,7 @@ public: /*virtual*/ std::string getCurPath(); /*virtual*/ U32 countFilesInDir(const std::string &dirname, const std::string &mask); - /*virtual*/ BOOL getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname, BOOL wrap); + /*virtual*/ BOOL getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname); /*virtual*/ void getRandomFileInDir(const std::string &dirname, const std::string &mask, std::string &fname); /*virtual*/ BOOL fileExists(const std::string &filename) const; diff --git a/indra/llvfs/tests/lldir_test.cpp b/indra/llvfs/tests/lldir_test.cpp index 3247e0ab83..dc446ccbe5 100644 --- a/indra/llvfs/tests/lldir_test.cpp +++ b/indra/llvfs/tests/lldir_test.cpp @@ -311,7 +311,7 @@ namespace tut int found1 = 0; bool filesFound1[5] = { false, false, false, false, false }; // std::cerr << "searching '"+dir1+"' for *\n"; - while ( found1 <= 5 && gDirUtilp->getNextFileInDir(dir1, "*", scan1result, false) ) + while ( found1 <= 5 && gDirUtilp->getNextFileInDir(dir1, "*", scan1result) ) { found1++; // std::cerr << " found '"+scan1result+"'\n"; @@ -338,7 +338,7 @@ namespace tut bool filesFound2[5] = { false, false, false, false, false }; // std::cerr << "searching '"+dir2+"' for *.xyz\n"; - while ( found2 <= 5 && gDirUtilp->getNextFileInDir(dir2, "*.xyz", scan2result, false) ) + while ( found2 <= 5 && gDirUtilp->getNextFileInDir(dir2, "*.xyz", scan2result) ) { found2++; // std::cerr << " found '"+scan2result+"'\n"; @@ -367,7 +367,7 @@ namespace tut bool filesFound3[5] = { false, false, false, false, false }; // std::cerr << "searching '"+dir2+"' for *.mno\n"; - while ( found3 <= 5 && gDirUtilp->getNextFileInDir(dir2, "*.mno", scan3result, false) ) + while ( found3 <= 5 && gDirUtilp->getNextFileInDir(dir2, "*.mno", scan3result) ) { found3++; // std::cerr << " found '"+scan3result+"'\n"; @@ -396,7 +396,7 @@ namespace tut bool filesFound4[5] = { false, false, false, false, false }; // std::cerr << "searching '"+dir1+"' for *.foo\n"; - while ( found4 <= 5 && gDirUtilp->getNextFileInDir(dir1, "*.foo", scan4result, false) ) + while ( found4 <= 5 && gDirUtilp->getNextFileInDir(dir1, "*.foo", scan4result) ) { found4++; // std::cerr << " found '"+scan4result+"'\n"; -- cgit v1.2.3 From 330978decd15e02d7cd23dcead52dc2373d7e5d5 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Thu, 28 Oct 2010 22:40:37 -0400 Subject: STORM-480 remove (unused) LLDir::getRandomFileInDir --HG-- branch : storm-102 --- indra/llvfs/lldir.h | 2 +- indra/llvfs/lldir_linux.cpp | 39 --------------------------------------- indra/llvfs/lldir_linux.h | 1 - indra/llvfs/lldir_mac.cpp | 34 ---------------------------------- indra/llvfs/lldir_mac.h | 1 - indra/llvfs/lldir_solaris.cpp | 39 --------------------------------------- indra/llvfs/lldir_solaris.h | 1 - indra/llvfs/lldir_win32.cpp | 41 ----------------------------------------- indra/llvfs/lldir_win32.h | 1 - 9 files changed, 1 insertion(+), 158 deletions(-) (limited to 'indra/llvfs') diff --git a/indra/llvfs/lldir.h b/indra/llvfs/lldir.h index 643b89199b..71743d960c 100644 --- a/indra/llvfs/lldir.h +++ b/indra/llvfs/lldir.h @@ -90,7 +90,7 @@ class LLDir * * @todo this really should be rewritten as an iterator object. */ - virtual void getRandomFileInDir(const std::string &dirname, const std::string &mask, std::string &fname) = 0; + virtual std::string getCurPath() = 0; virtual BOOL fileExists(const std::string &filename) const = 0; diff --git a/indra/llvfs/lldir_linux.cpp b/indra/llvfs/lldir_linux.cpp index cf5fdd3b4a..73f2336f94 100644 --- a/indra/llvfs/lldir_linux.cpp +++ b/indra/llvfs/lldir_linux.cpp @@ -302,46 +302,7 @@ BOOL LLDir_Linux::getNextFileInDir(const std::string &dirname, const std::string } -// get a random file in the directory -void LLDir_Linux::getRandomFileInDir(const std::string &dirname, const std::string &mask, std::string &fname) -{ - S32 num_files; - S32 which_file; - DIR *dirp; - dirent *entryp = NULL; - - fname = ""; - - num_files = countFilesInDir(dirname,mask); - if (!num_files) - { - return; - } - - which_file = ll_rand(num_files); - -// llinfos << "Random select file #" << which_file << llendl; - // which_file now indicates the (zero-based) index to which file to play - - if (!((dirp = opendir(dirname.c_str())))) - { - while (which_file--) - { - if (!((entryp = readdir(dirp)))) - { - return; - } - } - - if ((!which_file) && entryp) - { - fname = entryp->d_name; - } - - closedir(dirp); - } -} std::string LLDir_Linux::getCurPath() { diff --git a/indra/llvfs/lldir_linux.h b/indra/llvfs/lldir_linux.h index ef4495a627..451e81ae93 100644 --- a/indra/llvfs/lldir_linux.h +++ b/indra/llvfs/lldir_linux.h @@ -44,7 +44,6 @@ public: virtual std::string getCurPath(); virtual U32 countFilesInDir(const std::string &dirname, const std::string &mask); virtual BOOL getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname); - virtual void getRandomFileInDir(const std::string &dirname, const std::string &mask, std::string &fname); /*virtual*/ BOOL fileExists(const std::string &filename) const; /*virtual*/ std::string getLLPluginLauncher(); diff --git a/indra/llvfs/lldir_mac.cpp b/indra/llvfs/lldir_mac.cpp index 290b3bd0db..445285aa43 100644 --- a/indra/llvfs/lldir_mac.cpp +++ b/indra/llvfs/lldir_mac.cpp @@ -317,41 +317,7 @@ BOOL LLDir_Mac::getNextFileInDir(const std::string &dirname, const std::string & return(result); } -// get a random file in the directory -void LLDir_Mac::getRandomFileInDir(const std::string &dirname, const std::string &mask, std::string &fname) -{ - S32 which_file; - glob_t g; - fname = ""; - - std::string tmp_str; - tmp_str = dirname; - tmp_str += mask; - - if(glob(tmp_str.c_str(), GLOB_NOSORT, NULL, &g) == 0) - { - if(g.gl_pathc > 0) - { - - which_file = ll_rand(g.gl_pathc); - -// llinfos << "getRandomFileInDir: returning number " << which_file << ", path is " << g.gl_pathv[which_file] << llendl; - // The API wants just the filename, not the full path. - //fname = g.gl_pathv[which_file]; - char *s = strrchr(g.gl_pathv[which_file], '/'); - - if(s == NULL) - s = g.gl_pathv[which_file]; - else if(s[0] == '/') - s++; - - fname = s; - } - - globfree(&g); - } -} S32 LLDir_Mac::deleteFilesInDir(const std::string &dirname, const std::string &mask) { diff --git a/indra/llvfs/lldir_mac.h b/indra/llvfs/lldir_mac.h index f80ca47d92..4eac3c3ae6 100644 --- a/indra/llvfs/lldir_mac.h +++ b/indra/llvfs/lldir_mac.h @@ -44,7 +44,6 @@ public: virtual std::string getCurPath(); virtual U32 countFilesInDir(const std::string &dirname, const std::string &mask); virtual BOOL getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname); - virtual void getRandomFileInDir(const std::string &dirname, const std::string &ask, std::string &fname); virtual BOOL fileExists(const std::string &filename) const; /*virtual*/ std::string getLLPluginLauncher(); diff --git a/indra/llvfs/lldir_solaris.cpp b/indra/llvfs/lldir_solaris.cpp index 09a96ef6b3..515fd66b6e 100644 --- a/indra/llvfs/lldir_solaris.cpp +++ b/indra/llvfs/lldir_solaris.cpp @@ -320,46 +320,7 @@ BOOL LLDir_Solaris::getNextFileInDir(const std::string &dirname, const std::stri } -// get a random file in the directory -void LLDir_Solaris::getRandomFileInDir(const std::string &dirname, const std::string &mask, std::string &fname) -{ - S32 num_files; - S32 which_file; - DIR *dirp; - dirent *entryp = NULL; - - fname = ""; - - num_files = countFilesInDir(dirname,mask); - if (!num_files) - { - return; - } - - which_file = ll_rand(num_files); - -// llinfos << "Random select file #" << which_file << llendl; - - // which_file now indicates the (zero-based) index to which file to play - - if (!((dirp = opendir(dirname.c_str())))) - { - while (which_file--) - { - if (!((entryp = readdir(dirp)))) - { - return; - } - } - if ((!which_file) && entryp) - { - fname = entryp->d_name; - } - - closedir(dirp); - } -} std::string LLDir_Solaris::getCurPath() { diff --git a/indra/llvfs/lldir_solaris.h b/indra/llvfs/lldir_solaris.h index 1c21397c38..4a1794f539 100644 --- a/indra/llvfs/lldir_solaris.h +++ b/indra/llvfs/lldir_solaris.h @@ -44,7 +44,6 @@ public: virtual std::string getCurPath(); virtual U32 countFilesInDir(const std::string &dirname, const std::string &mask); virtual BOOL getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname); - virtual void getRandomFileInDir(const std::string &dirname, const std::string &mask, std::string &fname); /*virtual*/ BOOL fileExists(const std::string &filename) const; private: diff --git a/indra/llvfs/lldir_win32.cpp b/indra/llvfs/lldir_win32.cpp index ecfa4a07d4..a721552999 100644 --- a/indra/llvfs/lldir_win32.cpp +++ b/indra/llvfs/lldir_win32.cpp @@ -310,47 +310,6 @@ BOOL LLDir_Win32::getNextFileInDir(const llutf16string &dirname, const std::stri } -// get a random file in the directory -void LLDir_Win32::getRandomFileInDir(const std::string &dirname, const std::string &mask, std::string &fname) -{ - S32 num_files; - S32 which_file; - HANDLE random_search_h; - - fname = ""; - - llutf16string pathname = utf8str_to_utf16str(dirname); - pathname += utf8str_to_utf16str(mask); - - WIN32_FIND_DATA FileData; - fname[0] = NULL; - - num_files = countFilesInDir(dirname,mask); - if (!num_files) - { - return; - } - - which_file = ll_rand(num_files); - -// llinfos << "Random select mp3 #" << which_file << llendl; - - // which_file now indicates the (zero-based) index to which file to play - - if ((random_search_h = FindFirstFile(pathname.c_str(), &FileData)) != INVALID_HANDLE_VALUE) - { - while (which_file--) - { - if (!FindNextFile(random_search_h, &FileData)) - { - return; - } - } - FindClose(random_search_h); - - fname = utf16str_to_utf8str(llutf16string(FileData.cFileName)); - } -} std::string LLDir_Win32::getCurPath() { diff --git a/indra/llvfs/lldir_win32.h b/indra/llvfs/lldir_win32.h index 2ec9025250..38ae690d89 100644 --- a/indra/llvfs/lldir_win32.h +++ b/indra/llvfs/lldir_win32.h @@ -41,7 +41,6 @@ public: /*virtual*/ std::string getCurPath(); /*virtual*/ U32 countFilesInDir(const std::string &dirname, const std::string &mask); /*virtual*/ BOOL getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname); - /*virtual*/ void getRandomFileInDir(const std::string &dirname, const std::string &mask, std::string &fname); /*virtual*/ BOOL fileExists(const std::string &filename) const; /*virtual*/ std::string getLLPluginLauncher(); -- cgit v1.2.3 From a2bb621f3b74bdb49bf8b6fc3eb6141cf0d8b27a Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Fri, 29 Oct 2010 07:17:41 -0400 Subject: fix private member declaration in windows implementation of LLDir::getNextFileInDir for STORM-480 --HG-- branch : storm-102 --- indra/llvfs/lldir_win32.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llvfs') diff --git a/indra/llvfs/lldir_win32.h b/indra/llvfs/lldir_win32.h index 38ae690d89..4c932c932c 100644 --- a/indra/llvfs/lldir_win32.h +++ b/indra/llvfs/lldir_win32.h @@ -47,7 +47,7 @@ public: /*virtual*/ std::string getLLPluginFilename(std::string base_name); private: - BOOL LLDir_Win32::getNextFileInDir(const llutf16string &dirname, const std::string &mask, std::string &fname, BOOL wrap); + BOOL LLDir_Win32::getNextFileInDir(const llutf16string &dirname, const std::string &mask, std::string &fname); void* mDirSearch_h; llutf16string mCurrentDir; -- cgit v1.2.3 From 2ab60cd988eba05ad6a3cfadb89c2cc5018f5885 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Fri, 29 Oct 2010 16:52:54 -0400 Subject: factor directory scanning and results check out, and add some more tests for getNextFileInDir --HG-- branch : storm-102 --- indra/llvfs/lldir.h | 5 +- indra/llvfs/tests/lldir_test.cpp | 183 +++++++++++++++++---------------------- 2 files changed, 84 insertions(+), 104 deletions(-) (limited to 'indra/llvfs') diff --git a/indra/llvfs/lldir.h b/indra/llvfs/lldir.h index 71743d960c..883e87a8fd 100644 --- a/indra/llvfs/lldir.h +++ b/indra/llvfs/lldir.h @@ -87,7 +87,10 @@ class LLDir * * This function may not be used to scan part of a directory, then start a new search of a different * directory, and then restart the first search where it left off. - * + * @bug: this is known to fail at least on MacOS with patterns that have both: + * a wildcard left of the . and more than one sequential ? right of the . + * the pattern foo.??x appears to work + * but *.??x or foo?.??x do not * @todo this really should be rewritten as an iterator object. */ diff --git a/indra/llvfs/tests/lldir_test.cpp b/indra/llvfs/tests/lldir_test.cpp index dc446ccbe5..d76823b409 100644 --- a/indra/llvfs/tests/lldir_test.cpp +++ b/indra/llvfs/tests/lldir_test.cpp @@ -287,136 +287,113 @@ namespace tut return uniqueDir + delim; // HACK - apparently, the trailing delimiter is needed... } - template<> template<> - void LLDirTest_object_t::test<5>() - // getNextFileInDir + static const char* DirScanFilename[5] = { "file1.abc", "file2.abc", "file1.xyz", "file2.xyz", "file1.mno" }; + + void scanTest(const std::string directory, const std::string pattern, bool correctResult[5]) { - std::string delim = gDirUtilp->getDirDelimiter(); - std::string dirTemp = LLFile::tmpdir(); - // Create the same 5 file names of the two directories - const char* filenames[5] = { "file1.abc", "file2.abc", "file1.xyz", "file2.xyz", "file1.mno" }; - std::string dir1 = makeTestDir(dirTemp + "getNextFileInDir"); - std::string dir2 = makeTestDir(dirTemp + "getNextFileInDir"); - std::string dir1files[5]; - std::string dir2files[5]; - for (int i=0; i<5; i++) - { - dir1files[i] = makeTestFile(dir1, filenames[i]); - dir2files[i] = makeTestFile(dir2, filenames[i]); - } + // Scan directory and see if any file1.* files are found + std::string scanResult; + int found = 0; + bool filesFound[5] = { false, false, false, false, false }; + std::cerr << "searching '"+directory+"' for '"+pattern+"'\n"; - // Scan dir1 and see if each of the 5 files is found exactly once - std::string scan1result; - int found1 = 0; - bool filesFound1[5] = { false, false, false, false, false }; - // std::cerr << "searching '"+dir1+"' for *\n"; - while ( found1 <= 5 && gDirUtilp->getNextFileInDir(dir1, "*", scan1result) ) + while ( found <= 5 && gDirUtilp->getNextFileInDir(directory, pattern, scanResult) ) { - found1++; - // std::cerr << " found '"+scan1result+"'\n"; + found++; + std::cerr << " found '"+scanResult+"'\n"; int check; - for (check=0; check < 5 && ! ( scan1result == filenames[check] ); check++) + for (check=0; check < 5 && ! ( scanResult == DirScanFilename[check] ); check++) { } // check is now either 5 (not found) or the index of the matching name if (check < 5) { - ensure( "found file '"+(std::string)filenames[check]+"' twice", ! filesFound1[check] ); - filesFound1[check] = true; + ensure( "found file '"+(std::string)DirScanFilename[check]+"' twice", ! filesFound[check] ); + filesFound[check] = true; } - else + else // check is 5 - should not happen { - ensure( "found unknown file '"+(std::string)filenames[check]+"'", false); + ensure( "found unknown file '"+(std::string)DirScanFilename[check]+"'", false); } } - ensure("wrong number of files found in '"+dir1+"'", found1 == 5); - - // Scan dir2 and see if only the 2 *.xyz files are found - std::string scan2result; - int found2 = 0; - bool filesFound2[5] = { false, false, false, false, false }; - // std::cerr << "searching '"+dir2+"' for *.xyz\n"; - - while ( found2 <= 5 && gDirUtilp->getNextFileInDir(dir2, "*.xyz", scan2result) ) + for (int i=0; i<5; i++) { - found2++; - // std::cerr << " found '"+scan2result+"'\n"; - int check; - for (check=0; check < 5 && ! ( scan2result == filenames[check] ); check++) + if (correctResult[i]) { + ensure("scan of '"+directory+"' using '"+pattern+"' did not return '"+DirScanFilename[i]+"'", filesFound[i]); } - // check is now either 5 (not found) or the index of the matching name - if (check < 5) - { - ensure( "found file '"+(std::string)filenames[check]+"' twice", ! filesFound2[check] ); - filesFound2[check] = true; - } - else // check is 5 - should not happen + else { - ensure( "found unknown file '"+(std::string)filenames[check]+"'", false); + ensure("scan of '"+directory+"' using '"+pattern+"' incorrectly returned '"+DirScanFilename[i]+"'", !filesFound[i]); } } - ensure("wrong files found in '"+dir2+"'", - !filesFound2[0] && !filesFound2[1] && filesFound2[2] && filesFound2[3] && !filesFound2[4] ); - + } + + template<> template<> + void LLDirTest_object_t::test<5>() + // getNextFileInDir + { + std::string delim = gDirUtilp->getDirDelimiter(); + std::string dirTemp = LLFile::tmpdir(); - // Scan dir2 and see if only the 1 *.mno file is found - std::string scan3result; - int found3 = 0; - bool filesFound3[5] = { false, false, false, false, false }; - // std::cerr << "searching '"+dir2+"' for *.mno\n"; + // Create the same 5 file names of the two directories - while ( found3 <= 5 && gDirUtilp->getNextFileInDir(dir2, "*.mno", scan3result) ) + std::string dir1 = makeTestDir(dirTemp + "getNextFileInDir"); + std::string dir2 = makeTestDir(dirTemp + "getNextFileInDir"); + std::string dir1files[5]; + std::string dir2files[5]; + for (int i=0; i<5; i++) { - found3++; - // std::cerr << " found '"+scan3result+"'\n"; - int check; - for (check=0; check < 5 && ! ( scan3result == filenames[check] ); check++) - { - } - // check is now either 5 (not found) or the index of the matching name - if (check < 5) - { - ensure( "found file '"+(std::string)filenames[check]+"' twice", ! filesFound3[check] ); - filesFound3[check] = true; - } - else // check is 5 - should not happen - { - ensure( "found unknown file '"+(std::string)filenames[check]+"'", false); - } + dir1files[i] = makeTestFile(dir1, DirScanFilename[i]); + dir2files[i] = makeTestFile(dir2, DirScanFilename[i]); } - ensure("wrong files found in '"+dir2+"'", - !filesFound3[0] && !filesFound3[1] && !filesFound3[2] && !filesFound3[3] && filesFound3[4] ); + // Scan dir1 and see if each of the 5 files is found exactly once + bool expected1[5] = { true, true, true, true, true }; + scanTest(dir1, "*", expected1); - // Scan dir1 and see if any *.foo files are found - std::string scan4result; - int found4 = 0; - bool filesFound4[5] = { false, false, false, false, false }; - // std::cerr << "searching '"+dir1+"' for *.foo\n"; + // Scan dir2 and see if only the 2 *.xyz files are found + bool expected2[5] = { false, false, true, true, false }; + scanTest(dir1, "*.xyz", expected2); - while ( found4 <= 5 && gDirUtilp->getNextFileInDir(dir1, "*.foo", scan4result) ) - { - found4++; - // std::cerr << " found '"+scan4result+"'\n"; - int check; - for (check=0; check < 5 && ! ( scan4result == filenames[check] ); check++) - { - } - // check is now either 5 (not found) or the index of the matching name - if (check < 5) - { - ensure( "found file '"+(std::string)filenames[check]+"' twice", ! filesFound4[check] ); - filesFound4[check] = true; - } - else // check is 5 - should not happen - { - ensure( "found unknown file '"+(std::string)filenames[check]+"'", false); - } - } - ensure("wrong files found in '"+dir1+"'", - !filesFound4[0] && !filesFound4[1] && !filesFound4[2] && !filesFound4[3] && !filesFound4[4] ); + // Scan dir2 and see if only the 1 *.mno file is found + bool expected3[5] = { false, false, false, false, true }; + scanTest(dir2, "*.mno", expected3); + + // Scan dir1 and see if any *.foo files are found + bool expected4[5] = { false, false, false, false, false }; + scanTest(dir1, "*.foo", expected4); + + // Scan dir1 and see if any file1.* files are found + bool expected5[5] = { true, false, true, false, true }; + scanTest(dir1, "file1.*", expected5); + + // Scan dir1 and see if any file1.* files are found + bool expected6[5] = { true, true, false, false, false }; + scanTest(dir1, "file?.abc", expected6); + + // Scan dir2 and see if any file?.x?z files are found + bool expected7[5] = { false, false, true, true, false }; + scanTest(dir2, "file?.x?z", expected7); + + // Scan dir2 and see if any file?.??c files are found - THESE FAIL AND SO ARE COMMENTED OUT FOR NOW + // bool expected8[5] = { true, true, false, false, false }; + // scanTest(dir2, "file?.??c", expected8); + // bool expected8[5] = { true, true, false, false, false }; + // scanTest(dir2, "*.??c", expected8); + + // Scan dir1 and see if any *.?n? files are found + bool expected9[5] = { false, false, false, false, true }; + scanTest(dir1, "*.?n?", expected9); + + // Scan dir1 and see if any *.???? files are found + bool expected10[5] = { false, false, false, false, false }; + scanTest(dir1, "*.????", expected10); + + // Scan dir1 and see if any ?????.* files are found + bool expected11[5] = { true, true, true, true, true }; + scanTest(dir1, "?????.*", expected11); // clean up all test files and directories for (int i=0; i<5; i++) -- cgit v1.2.3 From 0ecb46bf4660b1bab8fa31e4dadfd2e31fa6c7a9 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Tue, 2 Nov 2010 16:16:48 -0400 Subject: STORM-477 fix for test code - intermediate checkin to trigger Windows test on TeamCity --HG-- branch : storm-102 --- indra/llvfs/tests/lldir_test.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'indra/llvfs') diff --git a/indra/llvfs/tests/lldir_test.cpp b/indra/llvfs/tests/lldir_test.cpp index d76823b409..30976e7661 100644 --- a/indra/llvfs/tests/lldir_test.cpp +++ b/indra/llvfs/tests/lldir_test.cpp @@ -289,7 +289,7 @@ namespace tut static const char* DirScanFilename[5] = { "file1.abc", "file2.abc", "file1.xyz", "file2.xyz", "file1.mno" }; - void scanTest(const std::string directory, const std::string pattern, bool correctResult[5]) + void scanTest(const std::string& directory, const std::string& pattern, bool correctResult[5]) { // Scan directory and see if any file1.* files are found @@ -314,7 +314,7 @@ namespace tut } else // check is 5 - should not happen { - ensure( "found unknown file '"+(std::string)DirScanFilename[check]+"'", false); + fail( "found unknown file '"+scanResult+"'"); } } for (int i=0; i<5; i++) @@ -380,7 +380,6 @@ namespace tut // Scan dir2 and see if any file?.??c files are found - THESE FAIL AND SO ARE COMMENTED OUT FOR NOW // bool expected8[5] = { true, true, false, false, false }; // scanTest(dir2, "file?.??c", expected8); - // bool expected8[5] = { true, true, false, false, false }; // scanTest(dir2, "*.??c", expected8); // Scan dir1 and see if any *.?n? files are found -- cgit v1.2.3 From 96112dfa2628569dea42bcf968eb7566d97e85f7 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Wed, 3 Nov 2010 13:33:29 -0400 Subject: STORM-477: fixed getNextFileInDir on Windows7, improved test cases and documentation --HG-- branch : storm-102 --- indra/llvfs/lldir.h | 20 ++++++---- indra/llvfs/lldir_win32.cpp | 80 +++++++++++++++++++--------------------- indra/llvfs/tests/lldir_test.cpp | 16 +++++--- 3 files changed, 61 insertions(+), 55 deletions(-) (limited to 'indra/llvfs') diff --git a/indra/llvfs/lldir.h b/indra/llvfs/lldir.h index 883e87a8fd..42996fd051 100644 --- a/indra/llvfs/lldir.h +++ b/indra/llvfs/lldir.h @@ -76,9 +76,9 @@ class LLDir virtual U32 countFilesInDir(const std::string &dirname, const std::string &mask) = 0; /// Walk the files in a directory, with file pattern matching - virtual BOOL getNextFileInDir(const std::string &dirname, ///< directory path - must end in trailing slash! - const std::string &mask, ///< file pattern string (use "*" for all) - std::string &fname ///< found file name + virtual BOOL getNextFileInDir(const std::string& dirname, ///< directory path - must end in trailing slash! + const std::string& mask, ///< file pattern string (use "*" for all) + std::string& fname ///< output: found file name ) = 0; /**< * @returns true if a file was found, false if the entire directory has been scanned. @@ -86,12 +86,18 @@ class LLDir * @note that this function is NOT thread safe * * This function may not be used to scan part of a directory, then start a new search of a different - * directory, and then restart the first search where it left off. - * @bug: this is known to fail at least on MacOS with patterns that have both: - * a wildcard left of the . and more than one sequential ? right of the . + * directory, and then restart the first search where it left off; the entire search must run to + * completion or be abandoned - there is no restart. + * + * @bug: See http://jira.secondlife.com/browse/VWR-23697 + * and/or the tests in test/lldir_test.cpp + * This is known to fail with patterns that have both: + * a wildcard left of a . and more than one sequential ? right of a . * the pattern foo.??x appears to work * but *.??x or foo?.??x do not - * @todo this really should be rewritten as an iterator object. + * + * @todo this really should be rewritten as an iterator object, and the + * filtering should be done in a platform-independent way. */ virtual std::string getCurPath() = 0; diff --git a/indra/llvfs/lldir_win32.cpp b/indra/llvfs/lldir_win32.cpp index a721552999..4a8526cc96 100644 --- a/indra/llvfs/lldir_win32.cpp +++ b/indra/llvfs/lldir_win32.cpp @@ -246,21 +246,13 @@ U32 LLDir_Win32::countFilesInDir(const std::string &dirname, const std::string & // get the next file in the directory -// automatically wrap if we've hit the end BOOL LLDir_Win32::getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname) { - llutf16string dirnamew = utf8str_to_utf16str(dirname); - return getNextFileInDir(dirnamew, mask, fname); - -} + BOOL fileFound = FALSE; + fname = ""; -BOOL LLDir_Win32::getNextFileInDir(const llutf16string &dirname, const std::string &mask, std::string &fname) -{ WIN32_FIND_DATAW FileData; - - fname = ""; - llutf16string pathname = dirname; - pathname += utf8str_to_utf16str(mask); + llutf16string pathname = utf8str_to_utf16str(dirname) + utf8str_to_utf16str(mask); if (pathname != mCurrentDir) { @@ -273,43 +265,45 @@ BOOL LLDir_Win32::getNextFileInDir(const llutf16string &dirname, const std::stri // and open new one // Check error opening Directory structure - if ((mDirSearch_h = FindFirstFile(pathname.c_str(), &FileData)) == INVALID_HANDLE_VALUE) - { -// llinfos << "Unable to locate first file" << llendl; - return(FALSE); - } - } - else // get next file in list - { - // Find next entry - if (!FindNextFile(mDirSearch_h, &FileData)) + if ((mDirSearch_h = FindFirstFile(pathname.c_str(), &FileData)) != INVALID_HANDLE_VALUE) { - if (GetLastError() == ERROR_NO_MORE_FILES) - { - // No more files, so reset to beginning of directory - FindClose(mDirSearch_h); - mCurrentDir[0] = NULL; - - fname[0] = 0; - return(FALSE); - } - else - { - // Error -// llinfos << "Unable to locate next file" << llendl; - return(FALSE); - } + fileFound = TRUE; } } - // convert from TCHAR to char - fname = utf16str_to_utf8str(FileData.cFileName); - - // fname now first name in list - return(TRUE); -} - + // Loop to skip over the current (.) and parent (..) directory entries + // (apparently returned in Win7 but not XP) + do + { + if ( fileFound + && ( (lstrcmp(FileData.cFileName, (LPCTSTR)TEXT(".")) == 0) + ||(lstrcmp(FileData.cFileName, (LPCTSTR)TEXT("..")) == 0) + ) + ) + { + fileFound = FALSE; + } + } while ( mDirSearch_h != INVALID_HANDLE_VALUE + && !fileFound + && (fileFound = FindNextFile(mDirSearch_h, &FileData) + ) + ); + + if (!fileFound && GetLastError() == ERROR_NO_MORE_FILES) + { + // No more files, so reset to beginning of directory + FindClose(mDirSearch_h); + mCurrentDir[0] = '\000'; + } + if (fileFound) + { + // convert from TCHAR to char + fname = utf16str_to_utf8str(FileData.cFileName); + } + + return fileFound; +} std::string LLDir_Win32::getCurPath() { diff --git a/indra/llvfs/tests/lldir_test.cpp b/indra/llvfs/tests/lldir_test.cpp index 30976e7661..83ccb277b3 100644 --- a/indra/llvfs/tests/lldir_test.cpp +++ b/indra/llvfs/tests/lldir_test.cpp @@ -296,12 +296,12 @@ namespace tut std::string scanResult; int found = 0; bool filesFound[5] = { false, false, false, false, false }; - std::cerr << "searching '"+directory+"' for '"+pattern+"'\n"; + //std::cerr << "searching '"+directory+"' for '"+pattern+"'\n"; while ( found <= 5 && gDirUtilp->getNextFileInDir(directory, pattern, scanResult) ) { found++; - std::cerr << " found '"+scanResult+"'\n"; + //std::cerr << " found '"+scanResult+"'\n"; int check; for (check=0; check < 5 && ! ( scanResult == DirScanFilename[check] ); check++) { @@ -377,7 +377,8 @@ namespace tut bool expected7[5] = { false, false, true, true, false }; scanTest(dir2, "file?.x?z", expected7); - // Scan dir2 and see if any file?.??c files are found - THESE FAIL AND SO ARE COMMENTED OUT FOR NOW + // Scan dir2 and see if any file?.??c files are found + // THESE FAIL ON Mac and Windows, SO ARE COMMENTED OUT FOR NOW // bool expected8[5] = { true, true, false, false, false }; // scanTest(dir2, "file?.??c", expected8); // scanTest(dir2, "*.??c", expected8); @@ -387,13 +388,18 @@ namespace tut scanTest(dir1, "*.?n?", expected9); // Scan dir1 and see if any *.???? files are found - bool expected10[5] = { false, false, false, false, false }; - scanTest(dir1, "*.????", expected10); + // THIS ONE FAILS ON WINDOWS (returns three charater suffixes) SO IS COMMENTED OUT FOR NOW + // bool expected10[5] = { false, false, false, false, false }; + // scanTest(dir1, "*.????", expected10); // Scan dir1 and see if any ?????.* files are found bool expected11[5] = { true, true, true, true, true }; scanTest(dir1, "?????.*", expected11); + // Scan dir1 and see if any ??l??.xyz files are found + bool expected12[5] = { false, false, true, true, false }; + scanTest(dir1, "??l??.xyz", expected12); + // clean up all test files and directories for (int i=0; i<5; i++) { -- cgit v1.2.3 From b9d9a84f74ff0c2ef99e4300041a0fec22e4c710 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 19 Nov 2010 16:59:28 -0500 Subject: Fix test failure due to erroneous validation of fputs() return value. --- indra/llvfs/tests/lldir_test.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/llvfs') diff --git a/indra/llvfs/tests/lldir_test.cpp b/indra/llvfs/tests/lldir_test.cpp index 83ccb277b3..8788bd63e8 100644 --- a/indra/llvfs/tests/lldir_test.cpp +++ b/indra/llvfs/tests/lldir_test.cpp @@ -263,7 +263,9 @@ namespace tut std::string path = dir + delim + file; LLFILE* handle = LLFile::fopen( path, "w" ); ensure("failed to open test file '"+path+"'", handle != NULL ); - ensure("failed to write to test file '"+path+"'", !fputs("test file", handle) ); + // Harbison & Steele, 4th ed., p. 366: "If an error occurs, fputs + // returns EOF; otherwise, it returns some other, nonnegative value." + ensure("failed to write to test file '"+path+"'", fputs("test file", handle) >= 0); fclose(handle); return path; } -- cgit v1.2.3