From 1ceb8d95d74e60b30ce3680325425a1507f9302e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Alejandro=20Montoya=20Corte=CC=81s?= Date: Fri, 20 Sep 2024 09:04:48 -0500 Subject: [PATCH] Adding warning to config file --- crates/platforms/src/files.rs | 11 ++++------- crates/platforms/src/metadata.rs | 4 +++- crates/platforms/src/toml.rs | 10 ++++++++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/crates/platforms/src/files.rs b/crates/platforms/src/files.rs index ba2a7990e5b..e61785d3011 100644 --- a/crates/platforms/src/files.rs +++ b/crates/platforms/src/files.rs @@ -799,9 +799,6 @@ pub struct SpacetimeFs { impl SpacetimeFs { /// Resolve the directories & files from the given [FsOptions]. /// - /// * Directories: `root`, `data`, `config` - /// * Files: `config_client`, `config_server` - /// /// Resolution order: /// /// The following is the order of precedence for a value defined in multiple places @@ -812,7 +809,7 @@ impl SpacetimeFs { /// 3. The value in the `.spacetime.toml` file (TODO) /// 4. The value specified in an environment variable (TODO) /// 5. The value specified as a CLI argument - pub fn resolve(options: FsOptions) -> Result { + pub fn resolve(options: FsOptions) -> Directories { let FsOptions { edition: _, root, @@ -829,7 +826,7 @@ impl SpacetimeFs { dirs = dirs.data(data); } - Ok(dirs) + dirs } /// Open an existing spacetime file system. @@ -840,7 +837,7 @@ impl SpacetimeFs { pub fn open(options: FsOptions) -> Result { let edition = options.edition; let use_logs = options.use_logs; - let dirs = Self::resolve(options)?; + let dirs = Self::resolve(options); let fs = Self { paths: SpacetimePaths::new(edition, dirs, use_logs), @@ -859,7 +856,7 @@ impl SpacetimeFs { let edition = options.edition; let use_logs = options.use_logs; - let dirs = Self::resolve(options)?; + let dirs = Self::resolve(options); let fs = Self { paths: SpacetimePaths::new(edition, dirs, use_logs), diff --git a/crates/platforms/src/metadata.rs b/crates/platforms/src/metadata.rs index b946124853c..a4cad0f374d 100644 --- a/crates/platforms/src/metadata.rs +++ b/crates/platforms/src/metadata.rs @@ -9,6 +9,8 @@ use crate::errors::ErrorPlatform; use crate::toml::{read_toml, write_toml}; use spacetimedb_lib::Address; +pub const NOT_MODIFYING: &str = "# THIS FILE IS GENERATED BY SPACETIMEDB, DO NOT MODIFY!"; + /// Enum representing different binaries. pub enum Bin { Spacetime, @@ -225,6 +227,6 @@ impl Metadata { }, }; let raw = RawMetadata { edition }; - write_toml(path, &raw) + write_toml(path, &raw, NOT_MODIFYING) } } diff --git a/crates/platforms/src/toml.rs b/crates/platforms/src/toml.rs index 6a9b261315a..420a454c49b 100644 --- a/crates/platforms/src/toml.rs +++ b/crates/platforms/src/toml.rs @@ -19,12 +19,18 @@ pub fn read_toml>(path: P) -> Result>(path: P, value: &T) -> Result<(), ErrorPlatform> { +pub fn write_toml>(path: P, value: &T, comment: &str) -> Result<(), ErrorPlatform> { let path = path.as_ref(); - let content = toml::to_string(value).map_err(|error| ErrorPlatform::TomlSer { + let mut content = String::new(); + if !comment.is_empty() { + content.push_str(&format!("# {}\n\n", comment)); + } + let toml_content = toml::to_string(value).map_err(|error| ErrorPlatform::TomlSer { path: path.to_path_buf(), error, })?; + content.push_str(&toml_content); + std::fs::write(path, content).map_err(|error| ErrorPlatform::IO { path: path.to_path_buf(), error,