summaryrefslogtreecommitdiff
path: root/indra/llvfs
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llvfs')
-rwxr-xr-xindra/llvfs/lldir.cpp88
-rwxr-xr-xindra/llvfs/lldir.h8
-rwxr-xr-xindra/llvfs/lldir_mac.cpp2
-rwxr-xr-xindra/llvfs/lldiriterator.cpp23
-rwxr-xr-xindra/llvfs/llpidlock.cpp5
-rwxr-xr-xindra/llvfs/llpidlock.h31
-rwxr-xr-xindra/llvfs/llvfile.cpp2
-rwxr-xr-xindra/llvfs/llvfs.cpp2
-rwxr-xr-xindra/llvfs/tests/lldiriterator_test.cpp6
9 files changed, 137 insertions, 30 deletions
diff --git a/indra/llvfs/lldir.cpp b/indra/llvfs/lldir.cpp
index 6899e9a44a..0d65c3f8c3 100755
--- a/indra/llvfs/lldir.cpp
+++ b/indra/llvfs/lldir.cpp
@@ -42,6 +42,7 @@
#include "lldiriterator.h"
#include "stringize.h"
+#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
@@ -76,6 +77,7 @@ const char
*LLDir::SKINBASE = "";
static const char* const empty = "";
+std::string LLDir::sDumpDir = "";
LLDir::LLDir()
: mAppName(""),
@@ -99,7 +101,32 @@ LLDir::~LLDir()
{
}
-
+std::vector<std::string> LLDir::getFilesInDir(const std::string &dirname)
+{
+ //Returns a vector of fullpath filenames.
+
+ boost::filesystem::path p (dirname);
+ std::vector<std::string> v;
+
+ if (exists(p))
+ {
+ if (is_directory(p))
+ {
+ boost::filesystem::directory_iterator end_iter;
+ for (boost::filesystem::directory_iterator dir_itr(p);
+ dir_itr != end_iter;
+ ++dir_itr)
+ {
+ if (boost::filesystem::is_regular_file(dir_itr->status()))
+ {
+ v.push_back(dir_itr->path().filename().string());
+ }
+ }
+ }
+ }
+ return v;
+}
+
S32 LLDir::deleteFilesInDir(const std::string &dirname, const std::string &mask)
{
S32 count = 0;
@@ -158,6 +185,34 @@ S32 LLDir::deleteFilesInDir(const std::string &dirname, const std::string &mask)
return count;
}
+U32 LLDir::deleteDirAndContents(const std::string& dir_name)
+{
+ //Removes the directory and its contents. Returns number of files deleted.
+
+ U32 num_deleted = 0;
+
+ try
+ {
+ boost::filesystem::path dir_path(dir_name);
+ if (boost::filesystem::exists (dir_path))
+ {
+ if (!boost::filesystem::is_empty (dir_path))
+ { // Directory has content
+ num_deleted = boost::filesystem::remove_all (dir_path);
+ }
+ else
+ { // Directory is empty
+ boost::filesystem::remove (dir_path);
+ }
+ }
+ }
+ catch (boost::filesystem::filesystem_error &er)
+ {
+ llwarns << "Failed to delete " << dir_name << " with error " << er.code().message() << llendl;
+ }
+ return num_deleted;
+}
+
const std::string LLDir::findFile(const std::string &filename,
const std::string& searchPath1,
const std::string& searchPath2,
@@ -244,11 +299,36 @@ const std::string &LLDir::getLindenUserDir() const
return mLindenUserDir;
}
-const std::string &LLDir::getChatLogsDir() const
+const std::string& LLDir::getChatLogsDir() const
{
return mChatLogsDir;
}
+void LLDir::setDumpDir( const std::string& path )
+{
+ LLDir::sDumpDir = path;
+ if (! sDumpDir.empty() && sDumpDir.rbegin() == mDirDelimiter.rbegin() )
+ {
+ sDumpDir.erase(sDumpDir.size() -1);
+ }
+}
+
+const std::string &LLDir::getDumpDir() const
+{
+ if (sDumpDir.empty() )
+ {
+ LLUUID uid;
+ uid.generate();
+
+ sDumpDir = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "")
+ + "dump-" + uid.asString();
+
+ dir_exists_or_crash(sDumpDir);
+ }
+
+ return LLDir::sDumpDir;
+}
+
const std::string &LLDir::getPerAccountChatLogsDir() const
{
return mPerAccountChatLogsDir;
@@ -420,6 +500,10 @@ std::string LLDir::getExpandedFilename(ELLPath location, const std::string& subd
prefix = getCacheDir();
break;
+ case LL_PATH_DUMP:
+ prefix=getDumpDir();
+ break;
+
case LL_PATH_USER_SETTINGS:
prefix = add(getOSUserAppDir(), "user_settings");
break;
diff --git a/indra/llvfs/lldir.h b/indra/llvfs/lldir.h
index e02bf552aa..b219c6e29f 100755
--- a/indra/llvfs/lldir.h
+++ b/indra/llvfs/lldir.h
@@ -53,6 +53,7 @@ typedef enum ELLPath
LL_PATH_EXECUTABLE = 16,
LL_PATH_DEFAULT_SKIN = 17,
LL_PATH_FONTS = 18,
+ LL_PATH_DUMP = 19,
LL_PATH_LAST
} ELLPath;
@@ -71,7 +72,8 @@ class LLDir
const std::string& app_read_only_data_dir = "") = 0;
virtual S32 deleteFilesInDir(const std::string &dirname, const std::string &mask);
-
+ U32 deleteDirAndContents(const std::string& dir_name);
+ std::vector<std::string> getFilesInDir(const std::string &dirname);
// pure virtual functions
virtual std::string getCurPath() = 0;
virtual bool fileExists(const std::string &filename) const = 0;
@@ -92,6 +94,7 @@ class LLDir
const std::string &getOSUserAppDir() const; // Location of the os-specific user app dir
const std::string &getLindenUserDir() const; // Location of the Linden user dir.
const std::string &getChatLogsDir() const; // Location of the chat logs dir.
+ const std::string &getDumpDir() const; // Location of the per-run dump dir.
const std::string &getPerAccountChatLogsDir() const; // Location of the per account chat logs dir.
const std::string &getTempDir() const; // Common temporary directory
const std::string getCacheDir(bool get_default = false) const; // Location of the cache.
@@ -179,6 +182,8 @@ class LLDir
// For producing safe download file names from potentially unsafe ones
static std::string getScrubbedFileName(const std::string uncleanFileName);
static std::string getForbiddenFileChars();
+ void setDumpDir( const std::string& path );
+
virtual void setChatLogsDir(const std::string &path); // Set the chat logs dir to this user's dir
virtual void setPerAccountChatLogsDir(const std::string &username); // Set the per user chat log directory.
@@ -245,6 +250,7 @@ protected:
std::vector<std::string> mSearchSkinDirs;
std::string mLanguage; // Current viewer language
std::string mLLPluginDir; // Location for plugins and plugin shell
+ static std::string sDumpDir; // Per-run crash report subdir of log directory.
std::string mUserName; // Current user name
};
diff --git a/indra/llvfs/lldir_mac.cpp b/indra/llvfs/lldir_mac.cpp
index e00596cdb5..2f47ab3507 100755
--- a/indra/llvfs/lldir_mac.cpp
+++ b/indra/llvfs/lldir_mac.cpp
@@ -134,7 +134,7 @@ LLDir_Mac::LLDir_Mac()
{
mOSCacheDir = *cachedir;
- //Aura TODO: This changes from ~/Library/Cache/Secondlife to ~/Library/Cache/com.app.secondlife/Secondlife. Last dir level could go away.
+ //TODO: This changes from ~/Library/Cache/Secondlife to ~/Library/Cache/com.app.secondlife/Secondlife. Last dir level could go away.
CreateDirectory(mOSCacheDir, secondLifeString, NULL);
}
diff --git a/indra/llvfs/lldiriterator.cpp b/indra/llvfs/lldiriterator.cpp
index 460d2a8b4f..229608231c 100755
--- a/indra/llvfs/lldiriterator.cpp
+++ b/indra/llvfs/lldiriterator.cpp
@@ -119,16 +119,25 @@ bool LLDirIterator::Impl::next(std::string &fname)
fs::directory_iterator end_itr; // default construction yields past-the-end
bool found = false;
- while (mIter != end_itr && !found)
+
+ // Check if path is a directory.
+ try
{
- boost::smatch match;
- std::string name = mIter->path().filename().string();
- if (found = boost::regex_match(name, match, mFilterExp))
+ while (mIter != end_itr && !found)
{
- fname = name;
+ boost::smatch match;
+ std::string name = mIter->path().filename().string();
+ if (found = boost::regex_match(name, match, mFilterExp))
+ {
+ fname = name;
+ }
+
+ ++mIter;
}
-
- ++mIter;
+ }
+ catch (const fs::filesystem_error& e)
+ {
+ llwarns << e.what() << llendl;
}
return found;
diff --git a/indra/llvfs/llpidlock.cpp b/indra/llvfs/llpidlock.cpp
index 0424f2379e..b5fd3673a6 100755
--- a/indra/llvfs/llpidlock.cpp
+++ b/indra/llvfs/llpidlock.cpp
@@ -274,3 +274,8 @@ void LLPidLock::setSaveName(std::string savename)
{
LLPidLockFile::instance().mSaveName=savename;
}
+
+S32 LLPidLock::getPID()
+{
+ return (S32)getpid();
+}
diff --git a/indra/llvfs/llpidlock.h b/indra/llvfs/llpidlock.h
index d3295f4911..334f26bb29 100755
--- a/indra/llvfs/llpidlock.h
+++ b/indra/llvfs/llpidlock.h
@@ -39,21 +39,22 @@ namespace LLPidLock
{
void initClass(); // { (void) LLPidLockFile::instance(); }
- bool requestLock( LLNameTable<void *> *name_table=NULL, bool autosave=TRUE,
- bool force_immediate=FALSE, F32 timeout=300.0);
- bool checkLock();
- void releaseLock();
- bool isClean();
-
- //getters
- LLNameTable<void *> * getNameTable();
- bool getAutosave();
- bool getClean();
- std::string getSaveName();
-
- //setters
- void setClean(bool clean);
- void setSaveName(std::string savename);
+ bool requestLock( LLNameTable<void *> *name_table=NULL, bool autosave=TRUE,
+ bool force_immediate=FALSE, F32 timeout=300.0);
+ bool checkLock();
+ void releaseLock();
+ bool isClean();
+
+ //getters
+ LLNameTable<void *> * getNameTable();
+ bool getAutosave();
+ bool getClean();
+ std::string getSaveName();
+ S32 getPID();
+
+ //setters
+ void setClean(bool clean);
+ void setSaveName(std::string savename);
};
#endif // LL_PIDLOCK_H
diff --git a/indra/llvfs/llvfile.cpp b/indra/llvfs/llvfile.cpp
index 306d7d8ec7..983e7c3b59 100755
--- a/indra/llvfs/llvfile.cpp
+++ b/indra/llvfs/llvfile.cpp
@@ -104,7 +104,7 @@ BOOL LLVFile::read(U8 *buffer, S32 bytes, BOOL async, F32 priority)
// We can't do a read while there are pending async writes
waitForLock(VFSLOCK_APPEND);
- // *FIX: (???)
+ // *FIX: (?)
if (async)
{
mHandle = sVFSThread->read(mVFS, mFileID, mFileType, buffer, mPosition, bytes, threadPri());
diff --git a/indra/llvfs/llvfs.cpp b/indra/llvfs/llvfs.cpp
index 82c926620a..7b589f5b96 100755
--- a/indra/llvfs/llvfs.cpp
+++ b/indra/llvfs/llvfs.cpp
@@ -578,6 +578,7 @@ LLVFS::~LLVFS()
mFreeBlocksByLength.clear();
for_each(mFreeBlocksByLocation.begin(), mFreeBlocksByLocation.end(), DeletePairedPointer());
+ mFreeBlocksByLocation.clear();
unlockAndClose(mDataFP);
mDataFP = NULL;
@@ -1835,6 +1836,7 @@ void LLVFS::audit()
}
for_each(audit_blocks.begin(), audit_blocks.end(), DeletePointer());
+ audit_blocks.clear();
}
diff --git a/indra/llvfs/tests/lldiriterator_test.cpp b/indra/llvfs/tests/lldiriterator_test.cpp
index 505d86faa7..a65e3dada5 100755
--- a/indra/llvfs/tests/lldiriterator_test.cpp
+++ b/indra/llvfs/tests/lldiriterator_test.cpp
@@ -51,9 +51,9 @@ namespace tut
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^__??-??.*");
+ LLDirIterator iter(".","+bad-group-name]+?\?-??.*");
+ LLDirIterator iter1(".","))--@---bad-group-name2((?\?-??.*\\.txt");
+ LLDirIterator iter2(".","__^v--x)Cuide d sua vida(x--v^__?\?-??.*");
}
template<> template<>