Skip to content

Commit 158465f

Browse files
authored
In RTDB, create app data directory if it doesn't exist. Modify AppDataDir to create the whole path if needed. (#992)
* RTDB: Create the app data directory if it doesn't already exist. * Add release note. * Modify AppDataDir to create the whole path if needed.
1 parent a2279e9 commit 158465f

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

app/src/filesystem_desktop_linux.cc

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ bool Mkdir(const std::string& path, std::string* out_error) {
7272
return true;
7373
}
7474

75+
bool PathExists(const std::string& path) {
76+
struct stat sb;
77+
78+
return (stat(path.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode));
79+
}
80+
7581
} // namespace
7682

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

96-
if (should_create) {
97-
std::string current_path = home;
98-
for (const std::string& nested_dir : SplitString(app_dir, '/')) {
99-
current_path += '/';
102+
std::string full_path = home + '/' + app_dir;
103+
if (should_create && !PathExists(full_path)) {
104+
std::string current_path = full_path[0] == '/' ? "/" : "";
105+
106+
for (const std::string& nested_dir : SplitString(full_path, '/')) {
100107
current_path += nested_dir;
101108

102-
bool created = Mkdir(current_path, out_error);
103-
if (!created) return "";
109+
if (!PathExists(current_path)) {
110+
bool created = Mkdir(current_path, out_error);
111+
if (!created) return "";
112+
}
113+
current_path += '/';
104114
}
105115
}
106116

database/src/desktop/core/repo.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,14 @@ void Repo::DeferredInitialization() {
474474
database_path += "/";
475475
database_path += url_domain;
476476

477-
std::string app_data_path = AppDataDir(database_path.c_str());
477+
std::string app_data_path_error;
478+
std::string app_data_path =
479+
AppDataDir(database_path.c_str(),
480+
/* should_create = */ true, &app_data_path_error);
478481
if (app_data_path.empty()) {
479482
logger_->LogError(
480-
"Could not initialize persistence: Unable to find app data "
481-
"directory.");
483+
"Could not initialize persistence: App data directory error: %s",
484+
app_data_path_error.c_str());
482485
return;
483486
}
484487

release_build_files/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,8 @@ code.
615615
- Changes
616616
- General (Android): Switched over to Android BoM (Bill of Materials)
617617
for dependency versions. This requires Gradle 5.
618+
- Database (Desktop): If the app data directory doesn't exist, create it.
619+
This fixes an issue with disk persistence on Linux.
618620
- Messaging (Android): Fixed #973. Make sure all the resources are closed in
619621
`RegistrationIntentService`.
620622

0 commit comments

Comments
 (0)