MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / load

Method load

atomic-repository/src/change_source/token.rs:58–90  ·  view source on GitHub ↗
(&self, source: ChangeSourceKind)

Source from the content-addressed store, hash-verified

56 }
57
58 pub fn load(&self, source: ChangeSourceKind) -> Result<TokenLoadResult, TokenStoreError> {
59 if !matches!(
60 source,
61 ChangeSourceKind::Fsmonitor | ChangeSourceKind::Watchman
62 ) {
63 return Ok(TokenLoadResult::default());
64 }
65 let path = self.path(source);
66 let bytes = match fs::read(&path) {
67 Ok(bytes) => bytes,
68 Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
69 return Ok(TokenLoadResult::default())
70 }
71 Err(source) => return Err(TokenStoreError::Io { path, source }),
72 };
73 match decode(source, &bytes) {
74 Ok(token) => Ok(TokenLoadResult {
75 token: Some(token),
76 invalidation: None,
77 }),
78 Err(invalidation) => {
79 match fs::remove_file(&path) {
80 Ok(()) => {}
81 Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
82 Err(source) => return Err(TokenStoreError::Io { path, source }),
83 }
84 Ok(TokenLoadResult {
85 token: None,
86 invalidation: Some(invalidation),
87 })
88 }
89 }
90 }
91
92 pub fn store(
93 &self,

Calls 4

decodeFunction · 0.70
readFunction · 0.50
pathMethod · 0.45
kindMethod · 0.45