diff options
| author | mo8it <mo8it@proton.me> | 2024-04-15 03:36:12 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-04-15 03:36:12 +0200 |
| commit | 6f04570dd080f3aedf2fdf4fac1e627abe3a5b27 (patch) | |
| tree | 10bf761c30c540d146433126dc25a35bc9638805 /src/trust.rs | |
| parent | 15ca847c37c170590abe6caa53dba5606d956341 (diff) | |
Revert "Implement third-party exercises trust handling"
This reverts commit 15ca847c37c170590abe6caa53dba5606d956341.
See https://rust-lang.zulipchat.com/#narrow/stream/334454-rustlings/topic/Proposal.3A.20Third-party.20exercises/near/433183449
Diffstat (limited to 'src/trust.rs')
| -rw-r--r-- | src/trust.rs | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/src/trust.rs b/src/trust.rs deleted file mode 100644 index 7e36f73..0000000 --- a/src/trust.rs +++ /dev/null @@ -1,72 +0,0 @@ -use anyhow::{Context, Error, Result}; -use std::{ - env, - fs::{self, OpenOptions}, - io::{ErrorKind, Write}, -}; - -const DATA_DIR_NAME: &str = "rustlings"; -const TRUSTED_DIRS_FILE_NAME: &str = "trusted-dirs.txt"; - -pub fn trust_current_dir() -> Result<()> { - let mut path = dirs::data_dir().context("Failed to determine the data directory")?; - path.push(DATA_DIR_NAME); - if !path.is_dir() { - fs::create_dir(&path) - .with_context(|| format!("Failed to create the directory {}", path.display()))?; - } - - path.push(TRUSTED_DIRS_FILE_NAME); - let mut file = OpenOptions::new() - .create(true) - .append(true) - .open(&path) - .with_context(|| { - format!( - "Failed to create/open the file {} in write mode", - path.display(), - ) - })?; - - let dir = env::current_dir().context("Failed to get the current directory path")?; - let dir = dir.to_string_lossy(); - let mut line = Vec::with_capacity(dir.as_bytes().len() + 1); - line.extend_from_slice(dir.as_bytes()); - line.push(b'\n'); - - file.write_all(&line) - .with_context(|| format!("Failed to append to the file {}", path.display())) -} - -pub fn current_dir_is_trusted() -> Result<bool> { - let mut path = dirs::data_dir().context("Failed to determine the data directory")?; - path.push(DATA_DIR_NAME); - path.push(TRUSTED_DIRS_FILE_NAME); - - let content = match fs::read(&path) { - Ok(v) => v, - Err(e) => match e.kind() { - ErrorKind::NotFound => return Ok(false), - _ => { - return Err( - Error::from(e).context(format!("Failed to read the file {}", path.display())) - ) - } - }, - }; - - let current_dir = env::current_dir().context("Failed to get the current directory path")?; - let current_dir = current_dir.to_string_lossy(); - - for line in content.split(|c| *c == b'\n') { - if line.is_empty() { - break; - } - - if line == current_dir.as_bytes() { - return Ok(true); - } - } - - Ok(false) -} |
