MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / new

Method new

crates/chat-cli/src/database/mod.rs:190–231  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

188
189impl Database {
190 pub async fn new() -> Result<Self, DatabaseError> {
191 let path = match cfg!(test) && !is_integ_test() {
192 true => {
193 return Self {
194 pool: Pool::builder().build(SqliteConnectionManager::memory()).unwrap(),
195 settings: Settings::new().await?,
196 }
197 .migrate();
198 },
199 false => GlobalPaths::database_path_static()?,
200 };
201
202 // make the parent dir if it doesnt exist
203 if let Some(parent) = path.parent() {
204 if !parent.exists() {
205 std::fs::create_dir_all(parent)?;
206 }
207 }
208
209 let conn = SqliteConnectionManager::file(&path);
210 let pool = Pool::builder().build(conn)?;
211
212 // Check the unix permissions of the database file, set them to 0600 if they are not
213 #[cfg(unix)]
214 {
215 use std::os::unix::fs::PermissionsExt;
216 let metadata = std::fs::metadata(&path)?;
217 let mut permissions = metadata.permissions();
218 if permissions.mode() & 0o777 != 0o600 {
219 tracing::debug!(?path, "Setting database file permissions to 0600");
220 permissions.set_mode(0o600);
221 std::fs::set_permissions(path, permissions)?;
222 }
223 }
224
225 Ok(Self {
226 pool,
227 settings: Settings::new().await?,
228 }
229 .migrate()
230 .map_err(|e| DbOpenError(e.to_string()))?)
231 }
232
233 /// Get all entries for dumping the persistent application state.
234 pub fn get_all_entries(&self) -> Result<Map<String, Value>, DatabaseError> {

Callers

nothing calls this directly

Calls 7

DbOpenErrorClass · 0.85
migrateMethod · 0.80
permissionsMethod · 0.80
to_stringMethod · 0.80
is_integ_testFunction · 0.50
buildMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected