-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework workspace paths, reorganize modules, add comments
- Loading branch information
1 parent
99a91d4
commit bf1a876
Showing
8 changed files
with
166 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use miette::Result; | ||
|
||
use crate::{error::GTWError, path::GTWPath}; | ||
|
||
#[derive(Debug, Clone, Hash, Eq, PartialEq)] | ||
pub enum GTWFileKind { | ||
Config, | ||
Module, | ||
} | ||
|
||
impl GTWFileKind { | ||
pub fn detect(path: >WPath) -> Result<Self> { | ||
let path = path.as_path(); | ||
let ext = path.extension().and_then(|ext| ext.to_str()); | ||
match ext { | ||
Some("toml") => { | ||
if path.starts_with("genotype") { | ||
return Ok(GTWFileKind::Config); | ||
} | ||
} | ||
Some("type") => { | ||
return Ok(GTWFileKind::Module); | ||
} | ||
_ => {} | ||
} | ||
Err(GTWError::DetectKind(path.display().to_string()).into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use genotype_config::GTConfig; | ||
use indexmap::IndexMap; | ||
use miette::Result; | ||
use std::sync::{Arc, Mutex}; | ||
|
||
use crate::path::GTWPath; | ||
|
||
pub mod source; | ||
pub use source::*; | ||
|
||
pub mod payload; | ||
pub use payload::*; | ||
|
||
pub mod kind; | ||
pub use kind::*; | ||
|
||
pub type GTWFiles = Arc<Mutex<IndexMap<GTWPath, GTWFile>>>; | ||
|
||
pub struct GTWFile { | ||
source: GTWFileSource, | ||
payload: GTWFilePayload, | ||
} | ||
|
||
impl GTWFile { | ||
pub fn load(path: >WPath, source: GTWFileSource) -> Result<Self> { | ||
match GTWFileKind::detect(path)? { | ||
GTWFileKind::Config => {} | ||
|
||
GTWFileKind::Module => {} | ||
} | ||
|
||
Ok(GTWFile { | ||
source, | ||
payload: GTWFilePayload::Config(GTConfig::default()), | ||
}) | ||
} | ||
|
||
pub fn same_hash(&self, source: >WFileSource) -> bool { | ||
self.source.same_hash(source) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use genotype_config::GTConfig; | ||
use genotype_parser::GTModuleParse; | ||
|
||
pub enum GTWFilePayload { | ||
Config(GTConfig), | ||
Module(GTModuleParse), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::fs::read_to_string; | ||
|
||
use miette::Result; | ||
use sha2::{Digest, Sha256}; | ||
|
||
use crate::{error::GTWError, path::GTWPath}; | ||
|
||
pub struct GTWFileSource { | ||
hash: String, | ||
content: String, | ||
} | ||
|
||
impl GTWFileSource { | ||
pub fn read(path: >WPath) -> Result<GTWFileSource> { | ||
let content = | ||
read_to_string(path.as_path()).map_err(|_| GTWError::ReadSource(path.into()))?; | ||
|
||
Ok(GTWFileSource { | ||
hash: Self::hash(&content), | ||
content, | ||
}) | ||
} | ||
|
||
pub fn hash(content: &String) -> String { | ||
let mut hasher = Sha256::new(); | ||
hasher.update(content.as_bytes()); | ||
let result = hasher.finalize(); | ||
format!("{:x}", result) | ||
} | ||
|
||
pub fn same_hash(&self, source: >WFileSource) -> bool { | ||
self.hash == source.hash | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters