Skip to content

Commit

Permalink
Allow BASE_PATH "" as alternative to "."
Browse files Browse the repository at this point in the history
  • Loading branch information
SciLor committed Mar 24, 2024
1 parent 46b8be0 commit 9ee38e5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 0 additions & 1 deletion include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define SETTINGS_H

#ifndef BASE_PATH
// #define BASE_PATH "./" // TODO, until path is resolved
#define BASE_PATH ""
#endif

Expand Down
20 changes: 17 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,34 @@ void main_init_settings(const char *cwd, const char *base_path)
/* try to find base path */
bool settings_initialized = false;

const char *base_path_resolved;
if (osStrcmp(".", base_path) == 0)
{
base_path_resolved = cwd;
}
else
{
base_path_resolved = base_path;
}

const char *base_paths[] = {
base_path,
base_path_resolved
#ifndef _WIN32
,
"/usr/local/etc/teddycloud",
"/usr/local/lib/teddycloud",
"/usr/etc/teddycloud",
"/usr/lib/teddycloud",
"/etc/teddycloud",
"/opt/teddycloud"};
"/opt/teddycloud"
#endif
};

for (int pos = 0; pos < COUNT(base_paths); pos++)
{
const char *path = base_paths[pos];

if (fsDirExists(path))
if (fsDirExists(path) || (fsDirExists(".") && path[0] == '\0'))
{
error = settings_init(cwd, path);
if (error == NO_ERROR)
Expand Down
2 changes: 1 addition & 1 deletion src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ uint8_t get_overlay_id(const char *overlay_unique_id)

void settings_resolve_dir(char **resolvedPath, char *path, char *basePath)
{
if (path[0] == PATH_SEPARATOR_LINUX || (path[1] == ':' && path[2] == PATH_SEPARATOR_WINDOWS))
if (path[0] == PATH_SEPARATOR_LINUX || (osStrlen(path) > 1 && path[1] == ':' && path[2] == PATH_SEPARATOR_WINDOWS))
{
snprintf(*resolvedPath, 255, "%s", path);
}
Expand Down

0 comments on commit 9ee38e5

Please sign in to comment.