summaryrefslogtreecommitdiff
path: root/indra/llvfs
diff options
context:
space:
mode:
authorXiaohong Bao <bao@lindenlab.com>2011-07-15 12:14:34 -0600
committerXiaohong Bao <bao@lindenlab.com>2011-07-15 12:14:34 -0600
commitd9512674678bbb80b8d0d9c5105f56dbd1b2252b (patch)
treec3c8d64c683cd46d9d1e5d953dc6caca22213db4 /indra/llvfs
parentd31e6735370711088f01cff448aa22f71c4c10c4 (diff)
parent44c7c6feaa824f4049d326965cb066e76ebefee3 (diff)
Merge from viewer-development
Diffstat (limited to 'indra/llvfs')
-rw-r--r--indra/llvfs/CMakeLists.txt45
-rw-r--r--indra/llvfs/lldir.cpp12
-rw-r--r--indra/llvfs/lldir.h25
-rw-r--r--indra/llvfs/lldir_linux.cpp68
-rw-r--r--indra/llvfs/lldir_linux.h11
-rw-r--r--indra/llvfs/lldir_mac.cpp99
-rw-r--r--indra/llvfs/lldir_mac.h8
-rw-r--r--indra/llvfs/lldir_solaris.cpp62
-rw-r--r--indra/llvfs/lldir_solaris.h9
-rw-r--r--indra/llvfs/lldir_win32.cpp103
-rw-r--r--indra/llvfs/lldir_win32.h7
-rw-r--r--indra/llvfs/lldiriterator.cpp216
-rw-r--r--indra/llvfs/lldiriterator.h87
-rw-r--r--indra/llvfs/llvfile.cpp4
-rw-r--r--indra/llvfs/llvfs.cpp10
-rw-r--r--indra/llvfs/tests/lldir_test.cpp38
-rw-r--r--indra/llvfs/tests/lldiriterator_test.cpp65
17 files changed, 492 insertions, 377 deletions
diff --git a/indra/llvfs/CMakeLists.txt b/indra/llvfs/CMakeLists.txt
index 722f4e2bfd..2c581cf8d6 100644
--- a/indra/llvfs/CMakeLists.txt
+++ b/indra/llvfs/CMakeLists.txt
@@ -12,6 +12,7 @@ include_directories(
set(llvfs_SOURCE_FILES
lldir.cpp
+ lldiriterator.cpp
lllfsthread.cpp
llpidlock.cpp
llvfile.cpp
@@ -24,6 +25,7 @@ set(llvfs_HEADER_FILES
lldir.h
lldirguard.h
+ lldiriterator.h
lllfsthread.h
llpidlock.h
llvfile.h
@@ -60,6 +62,15 @@ list(APPEND llvfs_SOURCE_FILES ${llvfs_HEADER_FILES})
add_library (llvfs ${llvfs_SOURCE_FILES})
+set(vfs_BOOST_LIBRARIES
+ ${BOOST_FILESYSTEM_LIBRARY}
+ ${BOOST_SYSTEM_LIBRARY}
+ )
+
+target_link_libraries(llvfs
+ ${vfs_BOOST_LIBRARIES}
+ )
+
if (DARWIN)
include(CMakeFindFrameworks)
find_library(CARBON_LIBRARY Carbon)
@@ -67,17 +78,23 @@ if (DARWIN)
endif (DARWIN)
-if(LL_TESTS)
- # Add tests
- include(LLAddBuildTest)
- # UNIT TESTS
- SET(llvfs_TEST_SOURCE_FILES
- # none so far
- )
- LL_ADD_PROJECT_UNIT_TESTS(llvfs "${llvfs_TEST_SOURCE_FILES}")
-
- # INTEGRATION TESTS
- set(test_libs llmath llcommon llvfs ${LLCOMMON_LIBRARIES} ${WINDOWS_LIBRARIES})
- # TODO: Some of these need refactoring to be proper Unit tests rather than Integration tests.
- LL_ADD_INTEGRATION_TEST(lldir "" "${test_libs}")
-endif(LL_TESTS)
+# Add tests
+if (LL_TESTS)
+ include(LLAddBuildTest)
+ # UNIT TESTS
+ SET(llvfs_TEST_SOURCE_FILES
+ lldiriterator.cpp
+ )
+
+ set_source_files_properties(lldiriterator.cpp
+ PROPERTIES
+ LL_TEST_ADDITIONAL_LIBRARIES "${vfs_BOOST_LIBRARIES}"
+ )
+ LL_ADD_PROJECT_UNIT_TESTS(llvfs "${llvfs_TEST_SOURCE_FILES}")
+
+ # INTEGRATION TESTS
+ set(test_libs llmath llcommon llvfs ${LLCOMMON_LIBRARIES} ${WINDOWS_LIBRARIES})
+
+ # TODO: Some of these need refactoring to be proper Unit tests rather than Integration tests.
+ LL_ADD_INTEGRATION_TEST(lldir "" "${test_libs}")
+endif (LL_TESTS)
diff --git a/indra/llvfs/lldir.cpp b/indra/llvfs/lldir.cpp
index cb898e385f..f3ac17d612 100644
--- a/indra/llvfs/lldir.cpp
+++ b/indra/llvfs/lldir.cpp
@@ -40,6 +40,8 @@
#include "lltimer.h" // ms_sleep()
#include "lluuid.h"
+#include "lldiriterator.h"
+
#if LL_WINDOWS
#include "lldir_win32.h"
LLDir_Win32 gDirUtil;
@@ -83,7 +85,9 @@ S32 LLDir::deleteFilesInDir(const std::string &dirname, const std::string &mask)
std::string filename;
std::string fullpath;
S32 result;
- while (getNextFileInDir(dirname, mask, filename))
+
+ LLDirIterator iter(dirname, mask);
+ while (iter.next(filename))
{
fullpath = dirname;
fullpath += getDirDelimiter();
@@ -149,7 +153,11 @@ const std::string LLDir::findFile(const std::string& filename, const std::vector
{
if (!search_path_iter->empty())
{
- std::string filename_and_path = (*search_path_iter) + getDirDelimiter() + filename;
+ std::string filename_and_path = (*search_path_iter);
+ if (!filename.empty())
+ {
+ filename_and_path += getDirDelimiter() + filename;
+ }
if (fileExists(filename_and_path))
{
return filename_and_path;
diff --git a/indra/llvfs/lldir.h b/indra/llvfs/lldir.h
index 42996fd051..5ee8bdb542 100644
--- a/indra/llvfs/lldir.h
+++ b/indra/llvfs/lldir.h
@@ -75,31 +75,6 @@ class LLDir
// pure virtual functions
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 ///< output: found file name
- ) = 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; 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, and the
- * filtering should be done in a platform-independent way.
- */
-
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 73f2336f94..407f3b93fb 100644
--- a/indra/llvfs/lldir_linux.cpp
+++ b/indra/llvfs/lldir_linux.cpp
@@ -93,11 +93,11 @@ LLDir_Linux::LLDir_Linux()
#else
mAppRODataDir = tmp_str;
#endif
- std::string::size_type indra_pos = mExecutableDir.find("/indra");
- if (indra_pos != std::string::npos)
+ std::string::size_type build_dir_pos = mExecutableDir.rfind("/build-linux-");
+ if (build_dir_pos != std::string::npos)
{
// ...we're in a dev checkout
- mSkinBaseDir = mExecutableDir.substr(0, indra_pos) + "/indra/newview/skins";
+ mSkinBaseDir = mExecutableDir.substr(0, build_dir_pos) + "/indra/newview/skins";
llinfos << "Running in dev checkout with mSkinBaseDir "
<< mSkinBaseDir << llendl;
}
@@ -242,68 +242,6 @@ U32 LLDir_Linux::countFilesInDir(const std::string &dirname, const std::string &
return (file_count);
}
-// get the next file in the directory
-BOOL LLDir_Linux::getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname)
-{
- glob_t g;
- BOOL result = FALSE;
- fname = "";
-
- if(!(dirname == mCurrentDir))
- {
- // different dir specified, close old search
- mCurrentDirIndex = -1;
- mCurrentDirCount = -1;
- mCurrentDir = dirname;
- }
-
- 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)
- {
- if((int)g.gl_pathc != mCurrentDirCount)
- {
- // Number of matches has changed since the last search, meaning a file has been added or deleted.
- // Reset the index.
- mCurrentDirIndex = -1;
- mCurrentDirCount = g.gl_pathc;
- }
-
- mCurrentDirIndex++;
-
- if(mCurrentDirIndex < (int)g.gl_pathc)
- {
-// llinfos << "getNextFileInDir: returning number " << mCurrentDirIndex << ", path is " << g.gl_pathv[mCurrentDirIndex] << llendl;
-
- // The API wants just the filename, not the full path.
- //fname = g.gl_pathv[mCurrentDirIndex];
-
- char *s = strrchr(g.gl_pathv[mCurrentDirIndex], '/');
-
- if(s == NULL)
- s = g.gl_pathv[mCurrentDirIndex];
- else if(s[0] == '/')
- s++;
-
- fname = s;
-
- result = TRUE;
- }
- }
-
- globfree(&g);
- }
-
- return(result);
-}
-
-
-
-
std::string LLDir_Linux::getCurPath()
{
char tmp_str[LL_MAX_PATH]; /* Flawfinder: ignore */
diff --git a/indra/llvfs/lldir_linux.h b/indra/llvfs/lldir_linux.h
index 451e81ae93..7603239867 100644
--- a/indra/llvfs/lldir_linux.h
+++ b/indra/llvfs/lldir_linux.h
@@ -1,6 +1,6 @@
/**
* @file lldir_linux.h
- * @brief Definition of directory utilities class for linux
+ * @brief Definition of directory utilities class for linux
*
* $LicenseInfo:firstyear=2000&license=viewerlgpl$
* Second Life Viewer Source Code
@@ -24,6 +24,10 @@
* $/LicenseInfo$
*/
+#if !LL_LINUX
+#error This header must not be included when compiling for any target other than Linux. Consider including lldir.h instead.
+#endif // !LL_LINUX
+
#ifndef LL_LLDIR_LINUX_H
#define LL_LLDIR_LINUX_H
@@ -40,10 +44,9 @@ public:
/*virtual*/ void initAppDirs(const std::string &app_name,
const std::string& app_read_only_data_dir);
-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*/ BOOL fileExists(const std::string &filename) const;
/*virtual*/ std::string getLLPluginLauncher();
@@ -53,7 +56,7 @@ private:
DIR *mDirp;
int mCurrentDirIndex;
int mCurrentDirCount;
- std::string mCurrentDir;
+ std::string mCurrentDir;
};
#endif // LL_LLDIR_LINUX_H
diff --git a/indra/llvfs/lldir_mac.cpp b/indra/llvfs/lldir_mac.cpp
index 445285aa43..489bc3e4a7 100644
--- a/indra/llvfs/lldir_mac.cpp
+++ b/indra/llvfs/lldir_mac.cpp
@@ -150,11 +150,11 @@ LLDir_Mac::LLDir_Mac()
CFURLRef resourcesURLRef = CFBundleCopyResourcesDirectoryURL(mainBundleRef);
CFURLRefToLLString(resourcesURLRef, mAppRODataDir, true);
- U32 indra_pos = mExecutableDir.find("/indra");
- if (indra_pos != std::string::npos)
+ U32 build_dir_pos = mExecutableDir.rfind("/build-darwin-");
+ if (build_dir_pos != std::string::npos)
{
// ...we're in a dev checkout
- mSkinBaseDir = mExecutableDir.substr(0, indra_pos)
+ mSkinBaseDir = mExecutableDir.substr(0, build_dir_pos)
+ "/indra/newview/skins";
llinfos << "Running in dev checkout with mSkinBaseDir "
<< mSkinBaseDir << llendl;
@@ -258,99 +258,6 @@ U32 LLDir_Mac::countFilesInDir(const std::string &dirname, const std::string &ma
return (file_count);
}
-// get the next file in the directory
-BOOL LLDir_Mac::getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname)
-{
- glob_t g;
- BOOL result = FALSE;
- fname = "";
-
- if(!(dirname == mCurrentDir))
- {
- // different dir specified, close old search
- mCurrentDirIndex = -1;
- mCurrentDirCount = -1;
- mCurrentDir = dirname;
- }
-
- 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)
- {
- if(g.gl_pathc != mCurrentDirCount)
- {
- // Number of matches has changed since the last search, meaning a file has been added or deleted.
- // Reset the index.
- mCurrentDirIndex = -1;
- mCurrentDirCount = g.gl_pathc;
- }
-
- mCurrentDirIndex++;
-
- if(mCurrentDirIndex < g.gl_pathc)
- {
-// llinfos << "getNextFileInDir: returning number " << mCurrentDirIndex << ", path is " << g.gl_pathv[mCurrentDirIndex] << llendl;
-
- // The API wants just the filename, not the full path.
- //fname = g.gl_pathv[mCurrentDirIndex];
-
- char *s = strrchr(g.gl_pathv[mCurrentDirIndex], '/');
-
- if(s == NULL)
- s = g.gl_pathv[mCurrentDirIndex];
- else if(s[0] == '/')
- s++;
-
- fname = s;
-
- result = TRUE;
- }
- }
-
- globfree(&g);
- }
-
- return(result);
-}
-
-
-
-S32 LLDir_Mac::deleteFilesInDir(const std::string &dirname, const std::string &mask)
-{
- glob_t g;
- S32 result = 0;
-
- std::string tmp_str;
- tmp_str = dirname;
- tmp_str += mask;
-
- if(glob(tmp_str.c_str(), GLOB_NOSORT, NULL, &g) == 0)
- {
- int i;
-
- for(i = 0; i < g.gl_pathc; i++)
- {
-// llinfos << "deleteFilesInDir: deleting number " << i << ", path is " << g.gl_pathv[i] << llendl;
-
- if(unlink(g.gl_pathv[i]) != 0)
- {
- result = errno;
-
- llwarns << "Problem removing " << g.gl_pathv[i] << " - errorcode: "
- << result << llendl;
- }
- }
-
- globfree(&g);
- }
-
- return(result);
-}
-
std::string LLDir_Mac::getCurPath()
{
char tmp_str[LL_MAX_PATH]; /* Flawfinder: ignore */
diff --git a/indra/llvfs/lldir_mac.h b/indra/llvfs/lldir_mac.h
index 4eac3c3ae6..d190d70be4 100644
--- a/indra/llvfs/lldir_mac.h
+++ b/indra/llvfs/lldir_mac.h
@@ -24,6 +24,10 @@
* $/LicenseInfo$
*/
+#if !LL_DARWIN
+#error This header must not be included when compiling for any target other than Mac OS. Consider including lldir.h instead.
+#endif // !LL_DARWIN
+
#ifndef LL_LLDIR_MAC_H
#define LL_LLDIR_MAC_H
@@ -39,11 +43,9 @@ public:
/*virtual*/ void initAppDirs(const std::string &app_name,
const std::string& app_read_only_data_dir);
-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);
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 515fd66b6e..21f8c3acdb 100644
--- a/indra/llvfs/lldir_solaris.cpp
+++ b/indra/llvfs/lldir_solaris.cpp
@@ -260,68 +260,6 @@ U32 LLDir_Solaris::countFilesInDir(const std::string &dirname, const std::string
return (file_count);
}
-// get the next file in the directory
-BOOL LLDir_Solaris::getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname)
-{
- glob_t g;
- BOOL result = FALSE;
- fname = "";
-
- if(!(dirname == mCurrentDir))
- {
- // different dir specified, close old search
- mCurrentDirIndex = -1;
- mCurrentDirCount = -1;
- mCurrentDir = dirname;
- }
-
- 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)
- {
- if((int)g.gl_pathc != mCurrentDirCount)
- {
- // Number of matches has changed since the last search, meaning a file has been added or deleted.
- // Reset the index.
- mCurrentDirIndex = -1;
- mCurrentDirCount = g.gl_pathc;
- }
-
- mCurrentDirIndex++;
-
- if(mCurrentDirIndex < (int)g.gl_pathc)
- {
-// llinfos << "getNextFileInDir: returning number " << mCurrentDirIndex << ", path is " << g.gl_pathv[mCurrentDirIndex] << llendl;
-
- // The API wants just the filename, not the full path.
- //fname = g.gl_pathv[mCurrentDirIndex];
-
- char *s = strrchr(g.gl_pathv[mCurrentDirIndex], '/');
-
- if(s == NULL)
- s = g.gl_pathv[mCurrentDirIndex];
- else if(s[0] == '/')
- s++;
-
- fname = s;
-
- result = TRUE;
- }
- }
-
- globfree(&g);
- }
-
- return(result);
-}
-
-
-
-
std::string LLDir_Solaris::getCurPath()
{
char tmp_str[LL_MAX_PATH]; /* Flawfinder: ignore */
diff --git a/indra/llvfs/lldir_solaris.h b/indra/llvfs/lldir_solaris.h
index 4a1794f539..0b58a45b15 100644
--- a/indra/llvfs/lldir_solaris.h
+++ b/indra/llvfs/lldir_solaris.h
@@ -24,6 +24,10 @@
* $/LicenseInfo$
*/
+#if !LL_SOLARIS
+#error This header must not be included when compiling for any target other than Solaris. Consider including lldir.h instead.
+#endif // !LL_SOLARIS
+
#ifndef LL_LLDIR_SOLARIS_H
#define LL_LLDIR_SOLARIS_H
@@ -40,17 +44,16 @@ public:
/*virtual*/ void initAppDirs(const std::string &app_name,
const std::string& app_read_only_data_dir);
-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*/ BOOL fileExists(const std::string &filename) const;
private:
DIR *mDirp;
int mCurrentDirIndex;
int mCurrentDirCount;
- std::string mCurrentDir;
+ std::string mCurrentDir;
};
#endif // LL_LLDIR_SOLARIS_H
diff --git a/indra/llvfs/lldir_win32.cpp b/indra/llvfs/lldir_win32.cpp
index 33718e520d..7709945123 100644
--- a/indra/llvfs/lldir_win32.cpp
+++ b/indra/llvfs/lldir_win32.cpp
@@ -81,10 +81,11 @@ LLDir_Win32::LLDir_Win32()
// fprintf(stderr, "mTempDir = <%s>",mTempDir);
-#if 1
- // Don't use the real app path for now, as we'll have to add parsing to detect if
- // we're in a developer tree, which has a different structure from the installed product.
+ // Set working directory, for LLDir::getWorkingDir()
+ GetCurrentDirectory(MAX_PATH, w_str);
+ mWorkingDir = utf16str_to_utf8str(llutf16string(w_str));
+ // Set the executable directory
S32 size = GetModuleFileName(NULL, w_str, MAX_PATH);
if (size)
{
@@ -100,32 +101,35 @@ LLDir_Win32::LLDir_Win32()
{
mExecutableFilename = mExecutablePathAndName;
}
- GetCurrentDirectory(MAX_PATH, w_str);
- mWorkingDir = utf16str_to_utf8str(llutf16string(w_str));
}
else
{
fprintf(stderr, "Couldn't get APP path, assuming current directory!");
- GetCurrentDirectory(MAX_PATH, w_str);
- mExecutableDir = utf16str_to_utf8str(llutf16string(w_str));
+ mExecutableDir = mWorkingDir;
// Assume it's the current directory
}
-#else
- GetCurrentDirectory(MAX_PATH, w_str);
- mExecutableDir = utf16str_to_utf8str(llutf16string(w_str));
-#endif
- if (mExecutableDir.find("indra") == std::string::npos)
+ // mAppRODataDir = ".";
+
+ // Determine the location of the App-Read-Only-Data
+ // Try the working directory then the exe's dir.
+ mAppRODataDir = mWorkingDir;
+
+
+// if (mExecutableDir.find("indra") == std::string::npos)
+
+ // *NOTE:Mani - It is a mistake to put viewer specific code in
+ // the LLDir implementation. The references to 'skins' and
+ // 'llplugin' need to go somewhere else.
+ // alas... this also gets called during static initialization
+ // time due to the construction of gDirUtil in lldir.cpp.
+ if(! LLFile::isdir(mAppRODataDir + mDirDelimiter + "skins"))
{
- // Running from installed directory. Make sure current
- // directory isn't something crazy (e.g. if invoking from
- // command line).
- SetCurrentDirectory(utf8str_to_utf16str(mExecutableDir).c_str());
- GetCurrentDirectory(MAX_PATH, w_str);
- mWorkingDir = utf16str_to_utf8str(llutf16string(w_str));
+ // What? No skins in the working dir?
+ // Try the executable's directory.
+ mAppRODataDir = mExecutableDir;
}
- mAppRODataDir = mWorkingDir;
llinfos << "mAppRODataDir = " << mAppRODataDir << llendl;
@@ -236,67 +240,6 @@ U32 LLDir_Win32::countFilesInDir(const std::string &dirname, const std::string &
return (file_count);
}
-
-// get the next file in the directory
-BOOL LLDir_Win32::getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname)
-{
- BOOL fileFound = FALSE;
- fname = "";
-
- WIN32_FIND_DATAW FileData;
- llutf16string pathname = utf8str_to_utf16str(dirname) + utf8str_to_utf16str(mask);
-
- if (pathname != mCurrentDir)
- {
- // different dir specified, close old search
- if (mCurrentDir[0])
- {
- FindClose(mDirSearch_h);
- }
- mCurrentDir = pathname;
-
- // and open new one
- // Check error opening Directory structure
- if ((mDirSearch_h = FindFirstFile(pathname.c_str(), &FileData)) != INVALID_HANDLE_VALUE)
- {
- fileFound = 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()
{
WCHAR w_str[MAX_PATH];
diff --git a/indra/llvfs/lldir_win32.h b/indra/llvfs/lldir_win32.h
index 4c932c932c..62fb4713ab 100644
--- a/indra/llvfs/lldir_win32.h
+++ b/indra/llvfs/lldir_win32.h
@@ -24,6 +24,10 @@
* $/LicenseInfo$
*/
+#if !LL_WINDOWS
+#error This header must not be included when compiling for any target other than Windows. Consider including lldir.h instead.
+#endif // !LL_WINDOWS
+
#ifndef LL_LLDIR_WIN32_H
#define LL_LLDIR_WIN32_H
@@ -40,15 +44,12 @@ 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*/ BOOL fileExists(const std::string &filename) const;
/*virtual*/ std::string getLLPluginLauncher();
/*virtual*/ std::string getLLPluginFilename(std::string base_name);
private:
- BOOL LLDir_Win32::getNextFileInDir(const llutf16string &dirname, const std::string &mask, std::string &fname);
-
void* mDirSearch_h;
llutf16string mCurrentDir;
};
diff --git a/indra/llvfs/lldiriterator.cpp b/indra/llvfs/lldiriterator.cpp
new file mode 100644
index 0000000000..25550321f0
--- /dev/null
+++ b/indra/llvfs/lldiriterator.cpp
@@ -0,0 +1,216 @@
+/**
+ * @file lldiriterator.cpp
+ * @brief Iterator through directory entries matching the search pattern.
+ *
+ * $LicenseInfo:firstyear=2010&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2010, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#include "lldiriterator.h"
+
+#include <boost/filesystem.hpp>
+#include <boost/regex.hpp>
+
+namespace fs = boost::filesystem;
+
+static std::string glob_to_regex(const std::string& glob);
+
+class LLDirIterator::Impl
+{
+public:
+ Impl(const std::string &dirname, const std::string &mask);
+ ~Impl();
+
+ bool next(std::string &fname);
+
+private:
+ boost::regex mFilterExp;
+ fs::directory_iterator mIter;
+ bool mIsValid;
+};
+
+LLDirIterator::Impl::Impl(const std::string &dirname, const std::string &mask)
+ : mIsValid(false)
+{
+ fs::path dir_path(dirname);
+
+ // Check if path exists.
+ if (!fs::exists(dir_path))
+ {
+ llwarns << "Invalid path: \"" << dir_path.string() << "\"" << llendl;
+ return;
+ }
+
+ // Initialize the directory iterator for the given path.
+ try
+ {
+ mIter = fs::directory_iterator(dir_path);
+ }
+ catch (fs::basic_filesystem_error<fs::path>& e)
+ {
+ llerrs << e.what() << llendl;
+ return;
+ }
+
+ // Convert the glob mask to a regular expression
+ std::string exp = glob_to_regex(mask);
+
+ // Initialize boost::regex with the expression converted from
+ // the glob mask.
+ // An exception is thrown if the expression is not valid.
+ try
+ {
+ mFilterExp.assign(exp);
+ }
+ catch (boost::regex_error& e)
+ {
+ llerrs << "\"" << exp << "\" is not a valid regular expression: "
+ << e.what() << llendl;
+ return;
+ }
+
+ mIsValid = true;
+}
+
+LLDirIterator::Impl::~Impl()
+{
+}
+
+bool LLDirIterator::Impl::next(std::string &fname)
+{
+ fname = "";
+
+ if (!mIsValid)
+ {
+ llwarns << "The iterator is not correctly initialized." << llendl;
+ return false;
+ }
+
+ fs::directory_iterator end_itr; // default construction yields past-the-end
+ bool found = false;
+ while (mIter != end_itr && !found)
+ {
+ boost::smatch match;
+ std::string name = mIter->path().filename();
+ if (found = boost::regex_match(name, match, mFilterExp))
+ {
+ fname = name;
+ }
+
+ ++mIter;
+ }
+
+ return found;
+}
+
+/**
+Converts the incoming glob into a regex. This involves
+converting incoming glob expressions to regex equivilents and
+at the same time, escaping any regex meaningful characters which
+do not have glob meaning, i.e.
+ .()+|^$
+in the input.
+*/
+std::string glob_to_regex(const std::string& glob)
+{
+ std::string regex;
+ regex.reserve(glob.size()<<1);
+ S32 braces = 0;
+ bool escaped = false;
+ bool square_brace_open = false;
+
+ for (std::string::const_iterator i = glob.begin(); i != glob.end(); ++i)
+ {
+ char c = *i;
+
+ switch (c)
+ {
+ case '*':
+ if (glob.begin() == i)
+ {
+ regex+="[^.].*";
+ }
+ else
+ {
+ regex+= escaped ? "*" : ".*";
+ }
+ break;
+ case '?':
+ regex+= escaped ? '?' : '.';
+ break;
+ case '{':
+ braces++;
+ regex+='(';
+ break;
+ case '}':
+ if (!braces)
+ {
+ llerrs << "glob_to_regex: Closing brace without an equivalent opening brace: " << glob << llendl;
+ }
+
+ regex+=')';
+ braces--;
+ break;
+ case ',':
+ regex+= braces ? '|' : c;
+ break;
+ case '!':
+ regex+= square_brace_open ? '^' : c;
+ break;
+ case '.': // This collection have different regex meaning
+ case '^': // and so need escaping.
+ case '(':
+ case ')':
+ case '+':
+ case '|':
+ case '$':
+ regex += '\\';
+ default:
+ regex += c;
+ break;
+ }
+
+ escaped = ('\\' == c);
+ square_brace_open = ('[' == c);
+ }
+
+ if (braces)
+ {
+ llerrs << "glob_to_regex: Unterminated brace expression: " << glob << llendl;
+ }
+
+ return regex;
+}
+
+LLDirIterator::LLDirIterator(const std::string &dirname, const std::string &mask)
+{
+ mImpl = new Impl(dirname, mask);
+}
+
+LLDirIterator::~LLDirIterator()
+{
+ delete mImpl;
+}
+
+bool LLDirIterator::next(std::string &fname)
+{
+ return mImpl->next(fname);
+}
diff --git a/indra/llvfs/lldiriterator.h b/indra/llvfs/lldiriterator.h
new file mode 100644
index 0000000000..0b48be41b3
--- /dev/null
+++ b/indra/llvfs/lldiriterator.h
@@ -0,0 +1,87 @@
+/**
+ * @file lldiriterator.h
+ * @brief Iterator through directory entries matching the search pattern.
+ *
+ * $LicenseInfo:firstyear=2010&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2010, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#ifndef LL_LLDIRITERATOR_H
+#define LL_LLDIRITERATOR_H
+
+#include "linden_common.h"
+
+/**
+ * Class LLDirIterator
+ *
+ * Iterates through directory entries matching the search pattern.
+ */
+class LLDirIterator
+{
+public:
+ /**
+ * Constructs LLDirIterator object to search for glob pattern
+ * matches in a directory.
+ *
+ * @param dirname - name of a directory to search in.
+ * @param mask - search pattern, a glob expression
+ *
+ * Wildcards supported in glob expressions:
+ * --------------------------------------------------------------
+ * | Wildcard | Matches |
+ * --------------------------------------------------------------
+ * | * |zero or more characters |
+ * | ? |exactly one character |
+ * | [abcde] |exactly one character listed |
+ * | [a-e] |exactly one character in the given range |
+ * | [!abcde] |any character that is not listed |
+ * | [!a-e] |any character that is not in the given range |
+ * | {abc,xyz} |exactly one entire word in the options given |
+ * --------------------------------------------------------------
+ */
+ LLDirIterator(const std::string &dirname, const std::string &mask);
+
+ ~LLDirIterator();
+
+ /**
+ * Searches for the next directory entry matching the glob mask
+ * specified upon iterator construction.
+ * Returns true if a match is found, sets fname
+ * parameter to the name of the matched directory entry and
+ * increments the iterator position.
+ *
+ * Typical usage:
+ * <code>
+ * LLDirIterator iter(directory, pattern);
+ * if ( iter.next(scanResult) )
+ * </code>
+ *
+ * @param fname - name of the matched directory entry.
+ * @return true if a match is found, false otherwise.
+ */
+ bool next(std::string &fname);
+
+protected:
+ class Impl;
+ Impl* mImpl;
+};
+
+#endif //LL_LLDIRITERATOR_H
diff --git a/indra/llvfs/llvfile.cpp b/indra/llvfs/llvfile.cpp
index a8db7b235e..ca749c5eaf 100644
--- a/indra/llvfs/llvfile.cpp
+++ b/indra/llvfs/llvfile.cpp
@@ -314,7 +314,7 @@ BOOL LLVFile::setMaxSize(S32 size)
if (!mVFS->checkAvailable(size))
{
- LLFastTimer t(FTM_VFILE_WAIT);
+ //LLFastTimer t(FTM_VFILE_WAIT);
S32 count = 0;
while (sVFSThread->getPending() > 1000)
{
@@ -422,7 +422,7 @@ bool LLVFile::isLocked(EVFSLock lock)
void LLVFile::waitForLock(EVFSLock lock)
{
- LLFastTimer t(FTM_VFILE_WAIT);
+ //LLFastTimer t(FTM_VFILE_WAIT);
// spin until the lock clears
while (isLocked(lock))
{
diff --git a/indra/llvfs/llvfs.cpp b/indra/llvfs/llvfs.cpp
index 1a64623028..ade19f8103 100644
--- a/indra/llvfs/llvfs.cpp
+++ b/indra/llvfs/llvfs.cpp
@@ -26,6 +26,8 @@
#include "linden_common.h"
+#include "llvfs.h"
+
#include <sys/stat.h>
#include <set>
#include <map>
@@ -39,8 +41,6 @@
#include <sys/file.h>
#endif
-#include "llvfs.h"
-
#include "llstl.h"
#include "lltimer.h"
@@ -1711,7 +1711,8 @@ void LLVFS::audit()
BOOL vfs_corrupt = FALSE;
- std::vector<U8> buffer(index_size);
+ // since we take the address of element 0, we need to have at least one element.
+ std::vector<U8> buffer(llmax<size_t>(index_size,1U));
if (fread(&buffer[0], 1, index_size, mIndexFP) != index_size)
{
@@ -2035,6 +2036,9 @@ std::string get_extension(LLAssetType::EType type)
case LLAssetType::AT_ANIMATION:
extension = ".lla";
break;
+ case LLAssetType::AT_MESH:
+ extension = ".slm";
+ break;
default:
// Just use the asset server filename extension in most cases
extension += ".";
diff --git a/indra/llvfs/tests/lldir_test.cpp b/indra/llvfs/tests/lldir_test.cpp
index 8788bd63e8..ea321c5ae9 100644
--- a/indra/llvfs/tests/lldir_test.cpp
+++ b/indra/llvfs/tests/lldir_test.cpp
@@ -28,6 +28,7 @@
#include "linden_common.h"
#include "../lldir.h"
+#include "../lldiriterator.h"
#include "../test/lltut.h"
@@ -259,13 +260,12 @@ namespace tut
std::string makeTestFile( const std::string& dir, const std::string& file )
{
- std::string delim = gDirUtilp->getDirDelimiter();
- std::string path = dir + delim + file;
+ std::string path = dir + file;
LLFILE* handle = LLFile::fopen( path, "w" );
ensure("failed to open test file '"+path+"'", handle != NULL );
// 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);
+ ensure("failed to write to test file '"+path+"'", EOF != fputs("test file", handle) );
fclose(handle);
return path;
}
@@ -290,7 +290,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])
{
@@ -300,7 +300,8 @@ namespace tut
bool filesFound[5] = { false, false, false, false, false };
//std::cerr << "searching '"+directory+"' for '"+pattern+"'\n";
- while ( found <= 5 && gDirUtilp->getNextFileInDir(directory, pattern, scanResult) )
+ LLDirIterator iter(directory, pattern);
+ while ( found <= 5 && iter.next(scanResult) )
{
found++;
//std::cerr << " found '"+scanResult+"'\n";
@@ -334,15 +335,15 @@ namespace tut
template<> template<>
void LLDirTest_object_t::test<5>()
- // getNextFileInDir
+ // LLDirIterator::next
{
std::string delim = gDirUtilp->getDirDelimiter();
std::string dirTemp = LLFile::tmpdir();
// Create the same 5 file names of the two directories
- std::string dir1 = makeTestDir(dirTemp + "getNextFileInDir");
- std::string dir2 = makeTestDir(dirTemp + "getNextFileInDir");
+ std::string dir1 = makeTestDir(dirTemp + "LLDirIterator");
+ std::string dir2 = makeTestDir(dirTemp + "LLDirIterator");
std::string dir1files[5];
std::string dir2files[5];
for (int i=0; i<5; i++)
@@ -380,19 +381,17 @@ namespace tut
scanTest(dir2, "file?.x?z", expected7);
// 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);
+ bool expected8[5] = { true, true, false, false, false };
+ scanTest(dir2, "file?.??c", expected8);
+ 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
- // 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);
+ 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 };
@@ -402,6 +401,15 @@ namespace tut
bool expected12[5] = { false, false, true, true, false };
scanTest(dir1, "??l??.xyz", expected12);
+ bool expected13[5] = { true, false, true, false, false };
+ scanTest(dir1, "file1.{abc,xyz}", expected13);
+
+ bool expected14[5] = { true, true, false, false, false };
+ scanTest(dir1, "file[0-9].abc", expected14);
+
+ bool expected15[5] = { true, true, false, false, false };
+ scanTest(dir1, "file[!a-z].abc", expected15);
+
// clean up all test files and directories
for (int i=0; i<5; i++)
{
diff --git a/indra/llvfs/tests/lldiriterator_test.cpp b/indra/llvfs/tests/lldiriterator_test.cpp
new file mode 100644
index 0000000000..505d86faa7
--- /dev/null
+++ b/indra/llvfs/tests/lldiriterator_test.cpp
@@ -0,0 +1,65 @@
+/**
+ * @file lldiriterator_test.cpp
+ * @date 2011-06
+ * @brief LLDirIterator test cases.
+ *
+ * $LicenseInfo:firstyear=2011&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2011, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.,
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#include "linden_common.h"
+#include "lltut.h"
+#include "../lldiriterator.h"
+
+
+namespace tut
+{
+
+ struct LLDirIteratorFixture
+ {
+ LLDirIteratorFixture()
+ {
+ }
+ };
+ typedef test_group<LLDirIteratorFixture> LLDirIteratorTest_factory;
+ typedef LLDirIteratorTest_factory::object LLDirIteratorTest_t;
+ LLDirIteratorTest_factory tf("LLDirIterator");
+
+ /*
+ CHOP-662 was originally introduced to deal with crashes deleting files from
+ a directory (VWR-25500). However, this introduced a crash looking for
+ old chat logs as the glob_to_regex function in lldiriterator wasn't escaping lots of regexp characters
+ */
+ void test_chop_662(void)
+ {
+ // Check a selection of bad group names from the crash reports
+ LLDirIterator iter(".","+bad-group-name]+??-??.*");
+ LLDirIterator iter1(".","))--@---bad-group-name2((??-??.*\\.txt");
+ LLDirIterator iter2(".","__^v--x)Cuide d sua vida(x--v^__??-??.*");
+ }
+
+ template<> template<>
+ void LLDirIteratorTest_t::test<1>()
+ {
+ test_chop_662();
+ }
+
+}