diff options
Diffstat (limited to 'linden/indra/llvfs/lldir.cpp')
-rw-r--r-- | linden/indra/llvfs/lldir.cpp | 115 |
1 files changed, 88 insertions, 27 deletions
diff --git a/linden/indra/llvfs/lldir.cpp b/linden/indra/llvfs/lldir.cpp index 246595a..0e014d9 100644 --- a/linden/indra/llvfs/lldir.cpp +++ b/linden/indra/llvfs/lldir.cpp | |||
@@ -59,8 +59,19 @@ LLDir_Linux gDirUtil; | |||
59 | 59 | ||
60 | LLDir *gDirUtilp = (LLDir *)&gDirUtil; | 60 | LLDir *gDirUtilp = (LLDir *)&gDirUtil; |
61 | 61 | ||
62 | LLDir::LLDir() | 62 | LLDir::LLDir() |
63 | : mDirDelimiter("/") // fallback to forward slash if not overridden | 63 | : mAppName(""), |
64 | mExecutablePathAndName(""), | ||
65 | mExecutableFilename(""), | ||
66 | mExecutableDir(""), | ||
67 | mAppRODataDir(""), | ||
68 | mOSUserDir(""), | ||
69 | mOSUserAppDir(""), | ||
70 | mLindenUserDir(""), | ||
71 | mOSCacheDir(""), | ||
72 | mCAFile(""), | ||
73 | mTempDir(""), | ||
74 | mDirDelimiter("/") // fallback to forward slash if not overridden | ||
64 | { | 75 | { |
65 | } | 76 | } |
66 | 77 | ||
@@ -90,7 +101,7 @@ S32 LLDir::deleteFilesInDir(const std::string &dirname, const std::string &mask) | |||
90 | S32 retry_count = 0; | 101 | S32 retry_count = 0; |
91 | while (retry_count < 5) | 102 | while (retry_count < 5) |
92 | { | 103 | { |
93 | if (0 != LLFile::remove(fullpath.c_str())) | 104 | if (0 != LLFile::remove(fullpath)) |
94 | { | 105 | { |
95 | result = errno; | 106 | result = errno; |
96 | llwarns << "Problem removing " << fullpath << " - errorcode: " | 107 | llwarns << "Problem removing " << fullpath << " - errorcode: " |
@@ -205,13 +216,20 @@ const std::string LLDir::getCacheDir(bool get_default) const | |||
205 | if (mCacheDir.empty() || get_default) | 216 | if (mCacheDir.empty() || get_default) |
206 | { | 217 | { |
207 | std::string res; | 218 | std::string res; |
208 | if (getOSUserAppDir().empty()) | 219 | if (getOSCacheDir().empty()) |
209 | { | 220 | { |
210 | res = "data"; | 221 | if (getOSUserAppDir().empty()) |
222 | { | ||
223 | res = "data"; | ||
224 | } | ||
225 | else | ||
226 | { | ||
227 | res = getOSUserAppDir() + mDirDelimiter + "cache"; | ||
228 | } | ||
211 | } | 229 | } |
212 | else | 230 | else |
213 | { | 231 | { |
214 | res = getOSUserAppDir() + mDirDelimiter + "cache"; | 232 | res = getOSCacheDir() + mDirDelimiter + "SecondLife"; |
215 | } | 233 | } |
216 | return res; | 234 | return res; |
217 | } | 235 | } |
@@ -221,6 +239,12 @@ const std::string LLDir::getCacheDir(bool get_default) const | |||
221 | } | 239 | } |
222 | } | 240 | } |
223 | 241 | ||
242 | const std::string &LLDir::getOSCacheDir() const | ||
243 | { | ||
244 | return mOSCacheDir; | ||
245 | } | ||
246 | |||
247 | |||
224 | const std::string &LLDir::getCAFile() const | 248 | const std::string &LLDir::getCAFile() const |
225 | { | 249 | { |
226 | return mCAFile; | 250 | return mCAFile; |
@@ -350,7 +374,11 @@ std::string LLDir::getExpandedFilename(ELLPath location, const std::string& subd | |||
350 | prefix += mDirDelimiter; | 374 | prefix += mDirDelimiter; |
351 | prefix += "browser_profile"; | 375 | prefix += "browser_profile"; |
352 | break; | 376 | break; |
353 | 377 | ||
378 | case LL_PATH_EXECUTABLE: | ||
379 | prefix = getExecutableDir(); | ||
380 | break; | ||
381 | |||
354 | default: | 382 | default: |
355 | llassert(0); | 383 | llassert(0); |
356 | } | 384 | } |
@@ -395,6 +423,40 @@ std::string LLDir::getExpandedFilename(ELLPath location, const std::string& subd | |||
395 | return expanded_filename; | 423 | return expanded_filename; |
396 | } | 424 | } |
397 | 425 | ||
426 | std::string LLDir::getBaseFileName(const std::string& filepath, bool strip_exten) const | ||
427 | { | ||
428 | std::size_t offset = filepath.find_last_of(getDirDelimiter()); | ||
429 | offset = (offset == std::string::npos) ? 0 : offset+1; | ||
430 | std::string res = filepath.substr(offset, std::string::npos); | ||
431 | if (strip_exten) | ||
432 | { | ||
433 | offset = res.find_last_of('.'); | ||
434 | if (offset != std::string::npos && | ||
435 | offset != 0) // if basename STARTS with '.', don't strip | ||
436 | { | ||
437 | res = res.substr(0, offset); | ||
438 | } | ||
439 | } | ||
440 | return res; | ||
441 | } | ||
442 | |||
443 | std::string LLDir::getDirName(const std::string& filepath) const | ||
444 | { | ||
445 | std::size_t offset = filepath.find_last_of(getDirDelimiter()); | ||
446 | S32 len = (offset == std::string::npos) ? 0 : offset; | ||
447 | std::string dirname = filepath.substr(0, len); | ||
448 | return dirname; | ||
449 | } | ||
450 | |||
451 | std::string LLDir::getExtension(const std::string& filepath) const | ||
452 | { | ||
453 | std::string basename = getBaseFileName(filepath, false); | ||
454 | std::size_t offset = basename.find_last_of('.'); | ||
455 | std::string exten = (offset == std::string::npos || offset == 0) ? "" : basename.substr(offset+1); | ||
456 | LLStringUtil::toLower(exten); | ||
457 | return exten; | ||
458 | } | ||
459 | |||
398 | std::string LLDir::findSkinnedFilename(const std::string &filename) const | 460 | std::string LLDir::findSkinnedFilename(const std::string &filename) const |
399 | { | 461 | { |
400 | return findSkinnedFilename("", "", filename); | 462 | return findSkinnedFilename("", "", filename); |
@@ -419,11 +481,10 @@ std::string LLDir::findSkinnedFilename(const std::string &subdir1, const std::st | |||
419 | return found_file; | 481 | return found_file; |
420 | } | 482 | } |
421 | 483 | ||
422 | |||
423 | std::string LLDir::getTempFilename() const | 484 | std::string LLDir::getTempFilename() const |
424 | { | 485 | { |
425 | LLUUID random_uuid; | 486 | LLUUID random_uuid; |
426 | char uuid_str[64]; /* Flawfinder: ignore */ | 487 | std::string uuid_str; |
427 | 488 | ||
428 | random_uuid.generate(); | 489 | random_uuid.generate(); |
429 | random_uuid.toString(uuid_str); | 490 | random_uuid.toString(uuid_str); |
@@ -443,15 +504,15 @@ void LLDir::setLindenUserDir(const std::string &first, const std::string &last) | |||
443 | { | 504 | { |
444 | // some platforms have case-sensitive filesystems, so be | 505 | // some platforms have case-sensitive filesystems, so be |
445 | // utterly consistent with our firstname/lastname case. | 506 | // utterly consistent with our firstname/lastname case. |
446 | LLString firstlower(first); | 507 | std::string firstlower(first); |
447 | LLString::toLower(firstlower); | 508 | LLStringUtil::toLower(firstlower); |
448 | LLString lastlower(last); | 509 | std::string lastlower(last); |
449 | LLString::toLower(lastlower); | 510 | LLStringUtil::toLower(lastlower); |
450 | mLindenUserDir = getOSUserAppDir(); | 511 | mLindenUserDir = getOSUserAppDir(); |
451 | mLindenUserDir += mDirDelimiter; | 512 | mLindenUserDir += mDirDelimiter; |
452 | mLindenUserDir += firstlower.c_str(); | 513 | mLindenUserDir += firstlower; |
453 | mLindenUserDir += "_"; | 514 | mLindenUserDir += "_"; |
454 | mLindenUserDir += lastlower.c_str(); | 515 | mLindenUserDir += lastlower; |
455 | } | 516 | } |
456 | else | 517 | else |
457 | { | 518 | { |
@@ -480,15 +541,15 @@ void LLDir::setPerAccountChatLogsDir(const std::string &first, const std::string | |||
480 | { | 541 | { |
481 | // some platforms have case-sensitive filesystems, so be | 542 | // some platforms have case-sensitive filesystems, so be |
482 | // utterly consistent with our firstname/lastname case. | 543 | // utterly consistent with our firstname/lastname case. |
483 | LLString firstlower(first); | 544 | std::string firstlower(first); |
484 | LLString::toLower(firstlower); | 545 | LLStringUtil::toLower(firstlower); |
485 | LLString lastlower(last); | 546 | std::string lastlower(last); |
486 | LLString::toLower(lastlower); | 547 | LLStringUtil::toLower(lastlower); |
487 | mPerAccountChatLogsDir = getChatLogsDir(); | 548 | mPerAccountChatLogsDir = getChatLogsDir(); |
488 | mPerAccountChatLogsDir += mDirDelimiter; | 549 | mPerAccountChatLogsDir += mDirDelimiter; |
489 | mPerAccountChatLogsDir += firstlower.c_str(); | 550 | mPerAccountChatLogsDir += firstlower; |
490 | mPerAccountChatLogsDir += "_"; | 551 | mPerAccountChatLogsDir += "_"; |
491 | mPerAccountChatLogsDir += lastlower.c_str(); | 552 | mPerAccountChatLogsDir += lastlower; |
492 | } | 553 | } |
493 | else | 554 | else |
494 | { | 555 | { |
@@ -531,13 +592,13 @@ bool LLDir::setCacheDir(const std::string &path) | |||
531 | } | 592 | } |
532 | else | 593 | else |
533 | { | 594 | { |
534 | LLFile::mkdir(path.c_str()); | 595 | LLFile::mkdir(path); |
535 | std::string tempname = path + mDirDelimiter + "temp"; | 596 | std::string tempname = path + mDirDelimiter + "temp"; |
536 | LLFILE* file = LLFile::fopen(tempname.c_str(),"wt"); | 597 | LLFILE* file = LLFile::fopen(tempname,"wt"); |
537 | if (file) | 598 | if (file) |
538 | { | 599 | { |
539 | fclose(file); | 600 | fclose(file); |
540 | LLFile::remove(tempname.c_str()); | 601 | LLFile::remove(tempname); |
541 | mCacheDir = path; | 602 | mCacheDir = path; |
542 | return true; | 603 | return true; |
543 | } | 604 | } |
@@ -570,15 +631,15 @@ void dir_exists_or_crash(const std::string &dir_name) | |||
570 | #if LL_WINDOWS | 631 | #if LL_WINDOWS |
571 | // *FIX: lame - it doesn't do the same thing on windows. not so | 632 | // *FIX: lame - it doesn't do the same thing on windows. not so |
572 | // important since we don't deploy simulator to windows boxes. | 633 | // important since we don't deploy simulator to windows boxes. |
573 | LLFile::mkdir(dir_name.c_str(), 0700); | 634 | LLFile::mkdir(dir_name, 0700); |
574 | #else | 635 | #else |
575 | struct stat dir_stat; | 636 | struct stat dir_stat; |
576 | if(0 != LLFile::stat(dir_name.c_str(), &dir_stat)) | 637 | if(0 != LLFile::stat(dir_name, &dir_stat)) |
577 | { | 638 | { |
578 | S32 stat_rv = errno; | 639 | S32 stat_rv = errno; |
579 | if(ENOENT == stat_rv) | 640 | if(ENOENT == stat_rv) |
580 | { | 641 | { |
581 | if(0 != LLFile::mkdir(dir_name.c_str(), 0700)) // octal | 642 | if(0 != LLFile::mkdir(dir_name, 0700)) // octal |
582 | { | 643 | { |
583 | llerrs << "Unable to create directory: " << dir_name << llendl; | 644 | llerrs << "Unable to create directory: " << dir_name << llendl; |
584 | } | 645 | } |