Skip to content

Commit

Permalink
Adding warning to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
mamcx committed Sep 23, 2024
1 parent 4454031 commit 1ceb8d9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
11 changes: 4 additions & 7 deletions crates/platforms/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Directories, ErrorPlatform> {
pub fn resolve(options: FsOptions) -> Directories {
let FsOptions {
edition: _,
root,
Expand All @@ -829,7 +826,7 @@ impl SpacetimeFs {
dirs = dirs.data(data);
}

Ok(dirs)
dirs
}

/// Open an existing spacetime file system.
Expand All @@ -840,7 +837,7 @@ impl SpacetimeFs {
pub fn open(options: FsOptions) -> Result<Self, ErrorPlatform> {
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),
Expand All @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion crates/platforms/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -225,6 +227,6 @@ impl Metadata {
},
};
let raw = RawMetadata { edition };
write_toml(path, &raw)
write_toml(path, &raw, NOT_MODIFYING)
}
}
10 changes: 8 additions & 2 deletions crates/platforms/src/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ pub fn read_toml<T: DeserializeOwned, P: AsRef<Path>>(path: P) -> Result<T, Erro
})
}

pub fn write_toml<T: Serialize, P: AsRef<Path>>(path: P, value: &T) -> Result<(), ErrorPlatform> {
pub fn write_toml<T: Serialize, P: AsRef<Path>>(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,
Expand Down

0 comments on commit 1ceb8d9

Please sign in to comment.