Skip to content

Commit

Permalink
Change file utility functions to return std::filesystem::path
Browse files Browse the repository at this point in the history
  • Loading branch information
timoore committed Feb 23, 2024
1 parent 80dc2c2 commit 4b2ec9b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/core/include/cesium/omniverse/FilesystemUtil.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <string>
#include <filesystem>

namespace cesium::omniverse::FilesystemUtil {
std::string getCesiumCacheDirectory();
std::string getUserHomeDirectory();
std::filesystem::path getCesiumCacheDirectory();
std::filesystem::path getUserHomeDirectory();
} // namespace cesium::omniverse::FilesystemUtil
7 changes: 3 additions & 4 deletions src/core/src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ namespace cesium::omniverse {
namespace {

std::string getCacheDatabaseName() {
std::string cacheDir = FilesystemUtil::getCesiumCacheDirectory();
if (!cacheDir.empty()) {
std::filesystem::path cacheDirPath(cacheDir);
auto cacheDirPath = FilesystemUtil::getCesiumCacheDirectory();
if (!cacheDirPath.empty()) {
auto cacheFilePath = cacheDirPath / "cesium-request-cache.sqlite";
return cacheFilePath.generic_string();
}
Expand All @@ -54,7 +53,7 @@ std::shared_ptr<CesiumAsync::ICacheDatabase> makeCacheDatabase(const std::shared
return {};
} else if (auto dbName = getCacheDatabaseName(); !dbName.empty()) {
logger->oneTimeWarning(fmt::format("Cesium cache file: {}", dbName));
return std::make_shared<CesiumAsync::SqliteCache>(logger, getCacheDatabaseName(), maxCacheItems);
return std::make_shared<CesiumAsync::SqliteCache>(logger, dbName, maxCacheItems);
}
logger->oneTimeWarning("could not get name for cache database");
return {};
Expand Down
8 changes: 4 additions & 4 deletions src/core/src/FilesystemUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace cesium::omniverse::FilesystemUtil {

std::string getCesiumCacheDirectory() {
std::filesystem::path getCesiumCacheDirectory() {
auto f = carb::getFramework();
auto* tokensInterface = f->tryAcquireInterface<carb::tokens::ITokens>();
std::string cacheDir;
Expand All @@ -27,7 +27,7 @@ std::string getCesiumCacheDirectory() {
if (!cacheDir.empty()) {
std::filesystem::path cacheDirPath(cacheDir);
if (exists(cacheDirPath)) {
return cacheDirPath.generic_string();
return cacheDirPath;
}
// Should we create the directory if it doesn't exist? It's hard to believe that Omniverse
// won't have already created it.
Expand All @@ -37,15 +37,15 @@ std::string getCesiumCacheDirectory() {
std::filesystem::path homeDirPath(homeDir);
auto cacheDirPath = homeDirPath / ".nvidia-omniverse";
if (exists(cacheDirPath)) {
return cacheDirPath.generic_string();
return cacheDirPath;
}
}
return {};
}

// Quite a lot of ceremony to get the home directory.

std::string getUserHomeDirectory() {
std::filesystem::path getUserHomeDirectory() {
std::string homeDir;
#if defined(__linux__)
if (char* cString = std::getenv("HOME")) {
Expand Down

0 comments on commit 4b2ec9b

Please sign in to comment.