mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-26 12:24:26 +03:00
move fs and storage intor separate crates
This commit is contained in:
parent
55b8a0357b
commit
3be7d600e0
25
Cargo.lock
generated
25
Cargo.lock
generated
@ -2119,6 +2119,7 @@ dependencies = [
|
||||
"gitbutler-branch",
|
||||
"gitbutler-core",
|
||||
"gitbutler-error",
|
||||
"gitbutler-fs",
|
||||
"gitbutler-project",
|
||||
"gitbutler-reference",
|
||||
"itertools 0.13.0",
|
||||
@ -2230,6 +2231,18 @@ dependencies = [
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gitbutler-fs"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bstr",
|
||||
"gix",
|
||||
"serde",
|
||||
"toml 0.8.14",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gitbutler-git"
|
||||
version = "0.0.0"
|
||||
@ -2282,6 +2295,7 @@ dependencies = [
|
||||
"gitbutler-branch",
|
||||
"gitbutler-branchstate",
|
||||
"gitbutler-core",
|
||||
"gitbutler-fs",
|
||||
"gitbutler-project",
|
||||
"gitbutler-repo",
|
||||
"gitbutler-serde",
|
||||
@ -2306,6 +2320,7 @@ dependencies = [
|
||||
"gitbutler-error",
|
||||
"gitbutler-id",
|
||||
"gitbutler-serde",
|
||||
"gitbutler-storage",
|
||||
"gitbutler-testsupport",
|
||||
"gix",
|
||||
"resolve-path",
|
||||
@ -2377,6 +2392,13 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gitbutler-storage"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"gitbutler-fs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gitbutler-sync"
|
||||
version = "0.0.0"
|
||||
@ -2420,6 +2442,7 @@ dependencies = [
|
||||
"gitbutler-reference",
|
||||
"gitbutler-repo",
|
||||
"gitbutler-secret",
|
||||
"gitbutler-storage",
|
||||
"gitbutler-testsupport",
|
||||
"gitbutler-user",
|
||||
"gitbutler-virtual",
|
||||
@ -2460,6 +2483,7 @@ dependencies = [
|
||||
"gitbutler-project",
|
||||
"gitbutler-reference",
|
||||
"gitbutler-repo",
|
||||
"gitbutler-storage",
|
||||
"gitbutler-user",
|
||||
"gitbutler-virtual",
|
||||
"keyring",
|
||||
@ -2476,6 +2500,7 @@ dependencies = [
|
||||
"anyhow",
|
||||
"gitbutler-core",
|
||||
"gitbutler-secret",
|
||||
"gitbutler-storage",
|
||||
"keyring",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
@ -22,7 +22,9 @@ members = [
|
||||
"crates/gitbutler-error",
|
||||
"crates/gitbutler-serde",
|
||||
"crates/gitbutler-secret",
|
||||
"crates/gitbutler-id",
|
||||
"crates/gitbutler-id",
|
||||
"crates/gitbutler-storage",
|
||||
"crates/gitbutler-fs",
|
||||
]
|
||||
resolver = "2"
|
||||
|
||||
@ -57,6 +59,8 @@ gitbutler-error = { path = "crates/gitbutler-error" }
|
||||
gitbutler-serde = { path = "crates/gitbutler-serde" }
|
||||
gitbutler-secret = { path = "crates/gitbutler-secret" }
|
||||
gitbutler-id = { path = "crates/gitbutler-id" }
|
||||
gitbutler-storage = { path = "crates/gitbutler-storage" }
|
||||
gitbutler-fs = { path = "crates/gitbutler-fs" }
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1 # Compile crates one after another so the compiler can optimize better
|
||||
|
@ -15,3 +15,4 @@ gitbutler-project.workspace = true
|
||||
gitbutler-branch.workspace = true
|
||||
gitbutler-reference.workspace = true
|
||||
gitbutler-error.workspace = true
|
||||
gitbutler-fs.workspace = true
|
||||
|
@ -9,8 +9,8 @@ use gitbutler_branch::{
|
||||
branch::{Branch, BranchId},
|
||||
target::Target,
|
||||
};
|
||||
use gitbutler_core::fs::read_toml_file_or_default;
|
||||
use gitbutler_error::error::Code;
|
||||
use gitbutler_fs::fs::read_toml_file_or_default;
|
||||
use gitbutler_project::Project;
|
||||
use gitbutler_reference::Refname;
|
||||
use itertools::Itertools;
|
||||
@ -254,5 +254,5 @@ impl VirtualBranchesHandle {
|
||||
}
|
||||
|
||||
fn write<P: AsRef<Path>>(file_path: P, virtual_branches: &VirtualBranches) -> Result<()> {
|
||||
gitbutler_core::fs::write(file_path, toml::to_string(&virtual_branches)?)
|
||||
gitbutler_fs::fs::write(file_path, toml::to_string(&virtual_branches)?)
|
||||
}
|
||||
|
@ -13,10 +13,8 @@
|
||||
clippy::too_many_lines
|
||||
)]
|
||||
|
||||
pub mod fs;
|
||||
pub mod git;
|
||||
pub mod path;
|
||||
pub mod storage;
|
||||
pub mod time;
|
||||
pub mod types;
|
||||
#[cfg(target_os = "windows")]
|
||||
|
14
crates/gitbutler-fs/Cargo.toml
Normal file
14
crates/gitbutler-fs/Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "gitbutler-fs"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
authors = ["GitButler <gitbutler@gitbutler.com>"]
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
serde = { workspace = true, features = ["std"]}
|
||||
bstr = "1.9.1"
|
||||
anyhow = "1.0.86"
|
||||
gix = { workspace = true, features = ["dirwalk", "credentials", "parallel"] }
|
||||
walkdir = "2.5.0"
|
||||
toml = "0.8.13"
|
@ -72,7 +72,7 @@ pub fn write<P: AsRef<Path>>(file_path: P, contents: impl AsRef<[u8]>) -> anyhow
|
||||
|
||||
/// Write a single file so that the write either fully succeeds, or fully fails,
|
||||
/// and create all leading directories.
|
||||
pub(crate) fn create_dirs_then_write<P: AsRef<Path>>(
|
||||
pub fn create_dirs_then_write<P: AsRef<Path>>(
|
||||
file_path: P,
|
||||
contents: impl AsRef<[u8]>,
|
||||
) -> std::io::Result<()> {
|
1
crates/gitbutler-fs/src/lib.rs
Normal file
1
crates/gitbutler-fs/src/lib.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod fs;
|
@ -20,6 +20,7 @@ toml = "0.8.13"
|
||||
gitbutler-project.workspace = true
|
||||
gitbutler-branch.workspace = true
|
||||
gitbutler-serde.workspace = true
|
||||
gitbutler-fs.workspace = true
|
||||
|
||||
[[test]]
|
||||
name="oplog"
|
||||
|
@ -2,7 +2,7 @@ use anyhow::{Context, Result};
|
||||
use gitbutler_branch::{
|
||||
GITBUTLER_INTEGRATION_COMMIT_AUTHOR_EMAIL, GITBUTLER_INTEGRATION_COMMIT_AUTHOR_NAME,
|
||||
};
|
||||
use gitbutler_core::fs::write;
|
||||
use gitbutler_fs::fs::write;
|
||||
use gix::config::tree::Key;
|
||||
use std::path::Path;
|
||||
|
||||
|
@ -4,7 +4,7 @@ use std::{
|
||||
time::SystemTime,
|
||||
};
|
||||
|
||||
use gitbutler_core::fs::read_toml_file_or_default;
|
||||
use gitbutler_fs::fs::read_toml_file_or_default;
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
|
||||
use super::OPLOG_FILE_NAME;
|
||||
@ -92,6 +92,6 @@ impl OplogHandle {
|
||||
|
||||
fn write_file(&self, mut oplog: Oplog) -> Result<()> {
|
||||
oplog.modified_at = SystemTime::now();
|
||||
gitbutler_core::fs::write(&self.file_path, toml::to_string(&oplog)?)
|
||||
gitbutler_fs::fs::write(&self.file_path, toml::to_string(&oplog)?)
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ gitbutler-core.workspace = true
|
||||
gitbutler-error.workspace = true
|
||||
gitbutler-serde.workspace = true
|
||||
gitbutler-id.workspace = true
|
||||
gitbutler-storage.workspace = true
|
||||
git2.workspace = true
|
||||
async-trait = "0.1.80"
|
||||
gix = { workspace = true, features = ["dirwalk", "credentials", "parallel"] }
|
||||
|
@ -2,7 +2,7 @@ use anyhow::{Context, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use gitbutler_core::storage;
|
||||
use gitbutler_storage::storage;
|
||||
|
||||
use crate::{ApiProject, AuthKey, CodePushState, FetchResult, Project, ProjectId};
|
||||
|
||||
|
9
crates/gitbutler-storage/Cargo.toml
Normal file
9
crates/gitbutler-storage/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "gitbutler-storage"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
authors = ["GitButler <gitbutler@gitbutler.com>"]
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
gitbutler-fs.workspace = true
|
1
crates/gitbutler-storage/src/lib.rs
Normal file
1
crates/gitbutler-storage/src/lib.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod storage;
|
@ -43,7 +43,7 @@ impl Storage {
|
||||
/// Generally, the filesystem is used for synchronization, not in-memory primitives.
|
||||
pub fn write(&self, rela_path: impl AsRef<Path>, content: &str) -> std::io::Result<()> {
|
||||
let file_path = self.local_data_dir.join(rela_path);
|
||||
crate::fs::create_dirs_then_write(file_path, content)
|
||||
gitbutler_fs::fs::create_dirs_then_write(file_path, content)
|
||||
}
|
||||
|
||||
/// Delete the file or directory at `rela_path`.
|
@ -61,6 +61,7 @@ gitbutler-reference.workspace = true
|
||||
gitbutler-error.workspace = true
|
||||
gitbutler-secret.workspace = true
|
||||
gitbutler-id.workspace = true
|
||||
gitbutler-storage.workspace = true
|
||||
open = "5"
|
||||
|
||||
[dependencies.tauri]
|
||||
|
@ -13,8 +13,8 @@
|
||||
clippy::too_many_lines
|
||||
)]
|
||||
|
||||
use gitbutler_core::storage;
|
||||
use gitbutler_repo::credentials::Helper;
|
||||
use gitbutler_storage::storage;
|
||||
use gitbutler_tauri::{
|
||||
app, askpass, commands, config, github, logs, menu, projects, remotes, repo, secret, undo,
|
||||
users, virtual_branches, watcher, zip,
|
||||
|
@ -26,3 +26,4 @@ gitbutler-project.workspace = true
|
||||
gitbutler-user.workspace = true
|
||||
gitbutler-branch.workspace = true
|
||||
gitbutler-reference.workspace = true
|
||||
gitbutler-storage.workspace = true
|
||||
|
@ -12,7 +12,7 @@ use crate::{init_opts, init_opts_bare, VAR_NO_CLEANUP};
|
||||
|
||||
pub struct Suite {
|
||||
pub local_app_data: Option<TempDir>,
|
||||
pub storage: gitbutler_core::storage::Storage,
|
||||
pub storage: gitbutler_storage::storage::Storage,
|
||||
pub users: gitbutler_user::Controller,
|
||||
pub projects: gitbutler_project::Controller,
|
||||
}
|
||||
@ -28,7 +28,7 @@ impl Drop for Suite {
|
||||
impl Default for Suite {
|
||||
fn default() -> Self {
|
||||
let local_app_data = temp_dir();
|
||||
let storage = gitbutler_core::storage::Storage::new(local_app_data.path());
|
||||
let storage = gitbutler_storage::storage::Storage::new(local_app_data.path());
|
||||
let users = gitbutler_user::Controller::from_path(local_app_data.path());
|
||||
let projects = gitbutler_project::Controller::from_path(local_app_data.path());
|
||||
Self {
|
||||
|
@ -8,6 +8,7 @@ publish = false
|
||||
[dependencies]
|
||||
gitbutler-core.workspace = true
|
||||
gitbutler-secret.workspace = true
|
||||
gitbutler-storage.workspace = true
|
||||
anyhow = "1.0.86"
|
||||
serde = { workspace = true, features = ["std"]}
|
||||
serde_json = { version = "1.0", features = [ "std", "arbitrary_precision" ] }
|
||||
|
@ -1,7 +1,7 @@
|
||||
use anyhow::Result;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use gitbutler_core::storage as core_storage;
|
||||
use gitbutler_storage::storage as core_storage;
|
||||
|
||||
use crate::User;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user