Skip to content

Commit

Permalink
chore: server always enables files feature.
Browse files Browse the repository at this point in the history
Otherwise the conditional endpoints make it difficult to present a
consistent OpenAPI spec.
  • Loading branch information
tmpfs committed Jun 21, 2024
1 parent 688ecfb commit 836a6d3
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 41 deletions.
6 changes: 3 additions & 3 deletions crates/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["listen", "files", "audit", "pairing"]
default = ["listen", "audit", "pairing"]
listen = ["sos-protocol/listen"]
files = ["sos-protocol/files"]
pairing = ["sos-protocol/pairing"]
audit = []

Expand Down Expand Up @@ -47,11 +46,12 @@ tower-http = { version = "0.5", features = ["cors", "trace"] }
tokio-stream = { version = "0.1" }
utoipa = { version = "4", features = ["uuid"] }
utoipa-rapidoc = { version = "3", features = ["axum"] }
tokio = { version = "1", features = ["rt", "rt-multi-thread", "time", "sync", "macros"] }
tokio = { version = "1", features = ["rt", "rt-multi-thread", "sync", "macros"] }

[dependencies.sos-protocol]
version = "0.14.1"
path = "../protocol"
features = ["files"]

[dependencies.sos-cli-helpers]
version = "0.1.0"
Expand Down
10 changes: 5 additions & 5 deletions crates/server/src/api_docs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::handlers::account;
use crate::handlers::{account, files};
use utoipa::{openapi::security::*, Modify, OpenApi, ToSchema};

#[derive(ToSchema)]
Expand Down Expand Up @@ -41,10 +41,10 @@ struct SyncPacket(sos_protocol::SyncPacket);
account::event_diff,
account::event_patch,
account::delete_account,
// files::receive_file,
// files::send_file,
// files::move_file,
// files::delete_file,
files::receive_file,
files::send_file,
files::move_file,
files::delete_file,
),
components(
schemas(
Expand Down
5 changes: 0 additions & 5 deletions crates/server/src/handlers/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,6 @@ mod handlers {

use std::sync::Arc;

#[cfg(feature = "files")]
use sos_protocol::sdk::events::{FileDiff, FileEvent};

use sos_protocol::sdk::events::{DeviceDiff, DeviceEvent};
Expand Down Expand Up @@ -756,7 +755,6 @@ mod handlers {
let event_log = log.read().await;
scan_log(&req, &*event_log).await?
}
#[cfg(feature = "files")]
EventLogType::Files => {
let reader = account.read().await;
let log = reader.storage.file_log().await?;
Expand Down Expand Up @@ -879,7 +877,6 @@ mod handlers {
let event_log = log.read().await;
diff_log(&req, &*event_log).await?
}
#[cfg(feature = "files")]
EventLogType::Files => {
let reader = account.read().await;
let log = reader.storage.file_log().await?;
Expand Down Expand Up @@ -1014,7 +1011,6 @@ mod handlers {
records,
)
}
#[cfg(feature = "files")]
EventLogType::Files => {
let patch = Patch::<FileEvent>::new(req.patch);
let mut writer = account.write().await;
Expand Down Expand Up @@ -1129,7 +1125,6 @@ mod handlers {
let mut event_log = log.write().await;
event_log.apply_records(records).await?;
}
#[cfg(feature = "files")]
EventLogType::Files => {
let log = reader.storage.file_log().await?;
let mut event_log = log.write().await;
Expand Down
2 changes: 0 additions & 2 deletions crates/server/src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ use serde_json::json;
use sos_protocol::sdk::signer::ecdsa::Address;

pub mod account;

#[cfg(feature = "files")]
pub mod files;

#[cfg(feature = "pairing")]
Expand Down
5 changes: 1 addition & 4 deletions crates/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,4 @@ pub type Result<T> = std::result::Result<T, error::Error>;

pub use backend::Backend;
pub use config::*;
pub use server::{Server, ServerBackend, ServerState, State};

#[cfg(feature = "files")]
pub use server::ServerTransfer;
pub use server::{Server, ServerBackend, ServerState, ServerTransfer, State};
5 changes: 0 additions & 5 deletions crates/server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use tracing::Level;
#[cfg(feature = "listen")]
use super::handlers::websocket::upgrade;

#[cfg(feature = "files")]
use sos_protocol::sdk::storage::files::ExternalFile;

#[cfg(feature = "pairing")]
Expand All @@ -56,11 +55,9 @@ pub type ServerState = Arc<RwLock<State>>;
pub type ServerBackend = Arc<RwLock<Backend>>;

/// Transfer operations in progress.
#[cfg(feature = "files")]
pub type TransferOperations = HashSet<ExternalFile>;

/// State for the file transfer operations.
#[cfg(feature = "files")]
pub type ServerTransfer = Arc<RwLock<TransferOperations>>;

/// Web server implementation.
Expand Down Expand Up @@ -241,7 +238,6 @@ impl Server {
.patch(account::event_patch),
);

#[cfg(feature = "files")]
{
use super::handlers::files::{self, file_operation_lock};
router = router
Expand Down Expand Up @@ -288,7 +284,6 @@ impl Server {

v1 = v1.layer(Extension(backend)).layer(Extension(state));

#[cfg(feature = "files")]
{
let file_operations: ServerTransfer =
Arc::new(RwLock::new(HashSet::new()));
Expand Down
6 changes: 0 additions & 6 deletions crates/server/src/storage/filesystem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use sos_protocol::sdk::{
use indexmap::IndexSet;
use std::collections::HashSet;

#[cfg(feature = "files")]
use sos_protocol::sdk::events::{FileEvent, FileEventLog};

mod sync;
Expand Down Expand Up @@ -54,7 +53,6 @@ pub struct ServerStorage {
pub(super) devices: IndexSet<TrustedDevice>,

/// File event log.
#[cfg(feature = "files")]
pub(super) file_log: Arc<RwLock<FileEventLog>>,
}

Expand Down Expand Up @@ -97,7 +95,6 @@ impl ServerStorage {
let (device_log, devices) =
Self::initialize_device_log(&*paths).await?;

#[cfg(feature = "files")]
let file_log = Self::initialize_file_log(&paths).await?;

Ok(Self {
Expand All @@ -108,7 +105,6 @@ impl ServerStorage {
account_log,
device_log: Arc::new(RwLock::new(device_log)),
devices,
#[cfg(feature = "files")]
file_log: Arc::new(RwLock::new(file_log)),
})
}
Expand Down Expand Up @@ -141,7 +137,6 @@ impl ServerStorage {
Ok((event_log, devices))
}

#[cfg(feature = "files")]
async fn initialize_file_log(paths: &Paths) -> Result<FileEventLog> {
use sos_protocol::sdk::storage::files::list_external_files;

Expand Down Expand Up @@ -306,7 +301,6 @@ impl ServerStorage {
// Remove local state
self.cache.remove(id);

#[cfg(feature = "files")]
{
let files_folder = self.paths.files_dir().join(id.to_string());
if vfs::try_exists(&files_folder).await? {
Expand Down
12 changes: 1 addition & 11 deletions crates/server/src/storage/filesystem/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ use std::sync::Arc;
use tokio::sync::RwLock;

use sos_protocol::sdk::events::{DeviceDiff, DeviceEventLog, DeviceReducer};

#[cfg(feature = "files")]
use sos_protocol::sdk::events::{FileDiff, FileEventLog};

impl ServerStorage {
Expand Down Expand Up @@ -82,7 +80,6 @@ impl ServerStorage {
self.devices = reducer.reduce().await?;
}

#[cfg(feature = "files")]
{
let mut writer = self.file_log.write().await;
writer.patch_unchecked(&account_data.files).await?;
Expand Down Expand Up @@ -137,7 +134,6 @@ impl ServerStorage {
self.force_merge_device(diff, outcome).await?;
}

#[cfg(feature = "files")]
if let Some(diff) = update_set.files.take() {
self.force_merge_files(diff, outcome).await?;
}
Expand Down Expand Up @@ -235,7 +231,6 @@ impl ForceMerge for ServerStorage {
}

/// Force merge changes to the files event log.
#[cfg(feature = "files")]
async fn force_merge_files(
&mut self,
diff: FileDiff,
Expand Down Expand Up @@ -453,7 +448,6 @@ impl Merge for ServerStorage {
reader.tree().compare(&state.1)
}

#[cfg(feature = "files")]
async fn merge_files(
&mut self,
diff: FileDiff,
Expand Down Expand Up @@ -489,7 +483,6 @@ impl Merge for ServerStorage {
Ok(checked_patch)
}

#[cfg(feature = "files")]
async fn compare_files(&self, state: &CommitState) -> Result<Comparison> {
let reader = self.file_log.read().await;
reader.tree().compare(&state.1)
Expand Down Expand Up @@ -555,7 +548,6 @@ impl StorageEventLogs for ServerStorage {
Ok(Arc::clone(&self.device_log))
}

#[cfg(feature = "files")]
async fn file_log(&self) -> Result<Arc<RwLock<FileEventLog>>> {
Ok(Arc::clone(&self.file_log))
}
Expand Down Expand Up @@ -598,7 +590,6 @@ impl SyncStorage for ServerStorage {
reader.tree().commit_state()?
};

#[cfg(feature = "files")]
let files = {
let reader = self.file_log.read().await;
if reader.tree().is_empty() {
Expand All @@ -625,7 +616,7 @@ impl SyncStorage for ServerStorage {
account.1.root().into(),
device.1.root().into(),
];
#[cfg(feature = "files")]

if let Some(files) = &files {
root_commits.push(files.1.root().into());
}
Expand All @@ -645,7 +636,6 @@ impl SyncStorage for ServerStorage {
identity,
account,
device,
#[cfg(feature = "files")]
files,
folders,
})
Expand Down

0 comments on commit 836a6d3

Please sign in to comment.