v0.2.18 - Clean up configuration system: remove active_config VIEW, database_location field, fix double slash in paths, and ensure database_path reflects actual path used
This commit is contained in:
Binary file not shown.
34
src/main.c
34
src/main.c
@@ -3132,7 +3132,7 @@ int main(int argc, char* argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store metadata about actual paths used (for reference, not for configuration lookup)
|
// Update database_path field to reflect actual database path used
|
||||||
if (database_path_override) {
|
if (database_path_override) {
|
||||||
// Convert to absolute path and normalize
|
// Convert to absolute path and normalize
|
||||||
char actual_db_path[1024];
|
char actual_db_path[1024];
|
||||||
@@ -3148,26 +3148,34 @@ int main(int argc, char* argv[]) {
|
|||||||
if (strncmp(database_path_override, "./", 2) == 0) {
|
if (strncmp(database_path_override, "./", 2) == 0) {
|
||||||
clean_path = database_path_override + 2;
|
clean_path = database_path_override + 2;
|
||||||
}
|
}
|
||||||
snprintf(actual_db_path, sizeof(actual_db_path), "%s/%s", cwd, clean_path);
|
|
||||||
|
// Ensure we don't exceed buffer size
|
||||||
|
int written = snprintf(actual_db_path, sizeof(actual_db_path), "%s/%s", cwd, clean_path);
|
||||||
|
if (written >= (int)sizeof(actual_db_path)) {
|
||||||
|
log_warning("Database path too long, using original path");
|
||||||
|
strncpy(actual_db_path, database_path_override, sizeof(actual_db_path) - 1);
|
||||||
|
actual_db_path[sizeof(actual_db_path) - 1] = '\0';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
strncpy(actual_db_path, database_path_override, sizeof(actual_db_path) - 1);
|
strncpy(actual_db_path, database_path_override, sizeof(actual_db_path) - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
actual_db_path[sizeof(actual_db_path) - 1] = '\0';
|
actual_db_path[sizeof(actual_db_path) - 1] = '\0';
|
||||||
|
|
||||||
if (set_database_config("database_location", actual_db_path, "system") == 0) {
|
// Update the database_path configuration to reflect actual path used
|
||||||
log_info("Stored database location metadata");
|
if (set_database_config("database_path", actual_db_path, "system") == 0) {
|
||||||
|
log_info("Updated database_path configuration with actual path used");
|
||||||
} else {
|
} else {
|
||||||
log_warning("Failed to store database location metadata");
|
log_warning("Failed to update database_path configuration");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store metadata about configuration file path used
|
// Store metadata about configuration file path used
|
||||||
if (strlen(g_config_manager.config_file_path) > 0) {
|
if (strlen(g_config_manager.config_file_path) > 0) {
|
||||||
// Convert to absolute path and normalize
|
// Convert to absolute path and normalize (fix double slash issue)
|
||||||
char actual_config_path[1024];
|
char actual_config_path[1024];
|
||||||
if (g_config_manager.config_file_path[0] == '/') {
|
if (g_config_manager.config_file_path[0] == '/') {
|
||||||
// Already absolute
|
// Already absolute - use as-is
|
||||||
strncpy(actual_config_path, g_config_manager.config_file_path, sizeof(actual_config_path) - 1);
|
strncpy(actual_config_path, g_config_manager.config_file_path, sizeof(actual_config_path) - 1);
|
||||||
} else {
|
} else {
|
||||||
// Make absolute by prepending current working directory
|
// Make absolute by prepending current working directory
|
||||||
@@ -3178,6 +3186,18 @@ int main(int argc, char* argv[]) {
|
|||||||
if (strncmp(g_config_manager.config_file_path, "./", 2) == 0) {
|
if (strncmp(g_config_manager.config_file_path, "./", 2) == 0) {
|
||||||
clean_path = g_config_manager.config_file_path + 2;
|
clean_path = g_config_manager.config_file_path + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove any trailing slash from cwd to avoid double slash
|
||||||
|
size_t cwd_len = strlen(cwd);
|
||||||
|
if (cwd_len > 0 && cwd[cwd_len - 1] == '/') {
|
||||||
|
cwd[cwd_len - 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove any leading slash from clean_path to avoid double slash
|
||||||
|
if (clean_path[0] == '/') {
|
||||||
|
clean_path++;
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(actual_config_path, sizeof(actual_config_path), "%s/%s", cwd, clean_path);
|
snprintf(actual_config_path, sizeof(actual_config_path), "%s/%s", cwd, clean_path);
|
||||||
} else {
|
} else {
|
||||||
strncpy(actual_config_path, g_config_manager.config_file_path, sizeof(actual_config_path) - 1);
|
strncpy(actual_config_path, g_config_manager.config_file_path, sizeof(actual_config_path) - 1);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#define SQL_SCHEMA_H
|
#define SQL_SCHEMA_H
|
||||||
|
|
||||||
/* Schema version constant */
|
/* Schema version constant */
|
||||||
#define EMBEDDED_SCHEMA_VERSION "3"
|
#define EMBEDDED_SCHEMA_VERSION "4"
|
||||||
|
|
||||||
/* Embedded SQL schema as C string literal */
|
/* Embedded SQL schema as C string literal */
|
||||||
static const char* const EMBEDDED_SCHEMA_SQL =
|
static const char* const EMBEDDED_SCHEMA_SQL =
|
||||||
@@ -14,7 +14,7 @@ static const char* const EMBEDDED_SCHEMA_SQL =
|
|||||||
-- SQLite schema for storing Nostr events with JSON tags support\n\
|
-- SQLite schema for storing Nostr events with JSON tags support\n\
|
||||||
\n\
|
\n\
|
||||||
-- Schema version tracking\n\
|
-- Schema version tracking\n\
|
||||||
PRAGMA user_version = 3;\n\
|
PRAGMA user_version = 4;\n\
|
||||||
\n\
|
\n\
|
||||||
-- Enable foreign key support\n\
|
-- Enable foreign key support\n\
|
||||||
PRAGMA foreign_keys = ON;\n\
|
PRAGMA foreign_keys = ON;\n\
|
||||||
@@ -267,20 +267,6 @@ BEGIN\n\
|
|||||||
VALUES (NEW.key, OLD.value, NEW.value, 'system', 'configuration update');\n\
|
VALUES (NEW.key, OLD.value, NEW.value, 'system', 'configuration update');\n\
|
||||||
END;\n\
|
END;\n\
|
||||||
\n\
|
\n\
|
||||||
-- Active Configuration View\n\
|
|
||||||
CREATE VIEW active_config AS\n\
|
|
||||||
SELECT\n\
|
|
||||||
key,\n\
|
|
||||||
value,\n\
|
|
||||||
description,\n\
|
|
||||||
config_type,\n\
|
|
||||||
data_type,\n\
|
|
||||||
requires_restart,\n\
|
|
||||||
updated_at\n\
|
|
||||||
FROM config\n\
|
|
||||||
WHERE config_type IN ('system', 'user')\n\
|
|
||||||
ORDER BY config_type, key;\n\
|
|
||||||
\n\
|
|
||||||
-- Runtime Statistics View\n\
|
-- Runtime Statistics View\n\
|
||||||
CREATE VIEW runtime_stats AS\n\
|
CREATE VIEW runtime_stats AS\n\
|
||||||
SELECT\n\
|
SELECT\n\
|
||||||
|
|||||||
BIN
test_override.db-shm
Normal file
BIN
test_override.db-shm
Normal file
Binary file not shown.
BIN
test_override.db-wal
Normal file
BIN
test_override.db-wal
Normal file
Binary file not shown.
Reference in New Issue
Block a user