Skip to content

In RTDB, create app data directory if it doesn't exist. Modify AppDataDir to create the whole path if needed. #992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions app/src/filesystem_desktop_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ bool Mkdir(const std::string& path, std::string* out_error) {
return true;
}

bool PathExists(const std::string& path) {
struct stat sb;

return (stat(path.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode));
}

} // namespace

std::string AppDataDir(const char* app_name, bool should_create,
Expand All @@ -93,14 +99,18 @@ std::string AppDataDir(const char* app_name, bool should_create,
app_dir = std::string(".local/share/") + app_name;
}

if (should_create) {
std::string current_path = home;
for (const std::string& nested_dir : SplitString(app_dir, '/')) {
current_path += '/';
std::string full_path = home + '/' + app_dir;
if (should_create && !PathExists(full_path)) {
std::string current_path = full_path[0] == '/' ? "/" : "";

for (const std::string& nested_dir : SplitString(full_path, '/')) {
current_path += nested_dir;

bool created = Mkdir(current_path, out_error);
if (!created) return "";
if (!PathExists(current_path)) {
bool created = Mkdir(current_path, out_error);
if (!created) return "";
}
current_path += '/';
}
}

Expand Down
9 changes: 6 additions & 3 deletions database/src/desktop/core/repo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,14 @@ void Repo::DeferredInitialization() {
database_path += "/";
database_path += url_domain;

std::string app_data_path = AppDataDir(database_path.c_str());
std::string app_data_path_error;
std::string app_data_path =
AppDataDir(database_path.c_str(),
/* should_create = */ true, &app_data_path_error);
if (app_data_path.empty()) {
logger_->LogError(
"Could not initialize persistence: Unable to find app data "
"directory.");
"Could not initialize persistence: App data directory error: %s",
app_data_path_error.c_str());
return;
}

Expand Down
2 changes: 2 additions & 0 deletions release_build_files/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,8 @@ code.
- Changes
- General (Android): Switched over to Android BoM (Bill of Materials)
for dependency versions. This requires Gradle 5.
- Database (Desktop): If the app data directory doesn't exist, create it.
This fixes an issue with disk persistence on Linux.

### 9.1.0
- Changes
Expand Down