Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Regex type and rename it to PreventSyncPattern #9049

Merged
merged 6 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libparsec/crates/client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct ClientConfig {
pub mountpoint_mount_strategy: MountpointMountStrategy,
pub workspace_storage_cache_size: WorkspaceStorageCacheSize,
/// The pattern used to filter out files that should not be synced with the server like temporary files.
pub prevent_sync_pattern: Regex,
pub prevent_sync_pattern: PreventSyncPattern,
pub proxy: ProxyConfig,
/// If `false`, nothing runs & react in the background, useful for tests
/// or CLI where the client is started to only perform a single operation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub(super) async fn populate_cache_from_server(
LocalFileManifest::from_remote(manifest),
))),
Ok(ChildManifest::Folder(manifest)) => Some(ArcLocalChildManifest::Folder(Arc::new(
LocalFolderManifest::from_remote(manifest, &Regex::empty()),
LocalFolderManifest::from_remote(manifest, &PreventSyncPattern::empty()),
))),
// This is unexpected: we got an entry ID from a parent folder/workspace
// manifest, but this ID points to nothing according to the server :/
Expand Down
2 changes: 1 addition & 1 deletion libparsec/crates/client/src/workspace/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ pub(super) fn merge_local_file_manifest(
pub(super) fn merge_local_folder_manifest(
local_author: DeviceID,
timestamp: DateTime,
prevent_sync_pattern: &Regex,
prevent_sync_pattern: &PreventSyncPattern,
local: &LocalFolderManifest,
remote: FolderManifest,
) -> MergeLocalFolderManifestOutcome {
Expand Down
8 changes: 4 additions & 4 deletions libparsec/crates/client/src/workspace/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub(super) struct WorkspaceStore {
/// Given accessing `storage` requires exclusive access, it is better to have it
/// under its own lock so that all cache hit operations can occur concurrently.
storage: AsyncMutex<Option<WorkspaceStorage>>,
prevent_sync_pattern: Regex,
prevent_sync_pattern: PreventSyncPattern,
}

impl std::panic::UnwindSafe for WorkspaceStore {}
Expand All @@ -130,7 +130,7 @@ impl WorkspaceStore {
certificates_ops: Arc<CertificateOps>,
cache_size: u64,
realm_id: VlobID,
pattern: &Regex,
prevent_sync_pattern: &PreventSyncPattern,
) -> Result<Self, anyhow::Error> {
// 1) Open the database

Expand Down Expand Up @@ -179,7 +179,7 @@ impl WorkspaceStore {
prevent_sync_pattern::ensure_prevent_sync_pattern_applied_to_wksp(
&mut storage,
device.clone(),
pattern,
prevent_sync_pattern,
)
.await?;

Expand All @@ -192,7 +192,7 @@ impl WorkspaceStore {
certificates_ops,
current_view_cache: Mutex::new(CurrentViewCache::new(Arc::new(root_manifest.into()))),
storage: AsyncMutex::new(Some(storage)),
prevent_sync_pattern: pattern.clone(),
prevent_sync_pattern: prevent_sync_pattern.clone(),
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ pub enum ApplyPreventSyncPatternError {
pub(super) async fn ensure_prevent_sync_pattern_applied_to_wksp(
storage: &mut WorkspaceStorage,
device: Arc<LocalDevice>,
pattern: &Regex,
prevent_sync_pattern: &PreventSyncPattern,
) -> Result<(), ApplyPreventSyncPatternError> {
const PAGE_SIZE: u32 = 1000;

let fully_applied = storage
.set_prevent_sync_pattern(pattern)
.set_prevent_sync_pattern(prevent_sync_pattern)
.await
.map_err(ApplyPreventSyncPatternError::Internal)?;

Expand All @@ -38,8 +38,8 @@ pub(super) async fn ensure_prevent_sync_pattern_applied_to_wksp(
// Only the prevent sync pattern could be applied to a folder type manifest.
// We assume that workspace manifest and folder manifest could both be deserialize as folder manifest.
if let Some(folder) = decode_folder(encoded_manifest, &device.local_symkey)? {
let new_folder =
folder.apply_prevent_sync_pattern(pattern, device.time_provider.now());
let new_folder = folder
.apply_prevent_sync_pattern(prevent_sync_pattern, device.time_provider.now());
if new_folder != folder {
updated_manifest.push(UpdateManifestData {
entry_id: new_folder.base.id,
Expand All @@ -65,7 +65,7 @@ pub(super) async fn ensure_prevent_sync_pattern_applied_to_wksp(
offset += PAGE_SIZE;
}
storage
.mark_prevent_sync_pattern_fully_applied(pattern)
.mark_prevent_sync_pattern_fully_applied(prevent_sync_pattern)
.await
.map_err(|e| ApplyPreventSyncPatternError::Internal(e.into()))?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion libparsec/crates/client/tests/unit/certif/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) async fn certificates_ops_factory(
workspace_storage_cache_size: WorkspaceStorageCacheSize::Default,
proxy: ProxyConfig::default(),
with_monitors: false,
prevent_sync_pattern: Regex::empty(),
prevent_sync_pattern: PreventSyncPattern::empty(),
});
let event_bus = EventBus::default();
let cmds = Arc::new(
Expand Down
2 changes: 1 addition & 1 deletion libparsec/crates/client/tests/unit/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) async fn client_factory(
workspace_storage_cache_size: WorkspaceStorageCacheSize::Default,
proxy: ProxyConfig::default(),
with_monitors: false,
prevent_sync_pattern: Regex::empty(),
prevent_sync_pattern: PreventSyncPattern::empty(),
});
Client::start(config, event_bus, device).await.unwrap()
}
4 changes: 2 additions & 2 deletions libparsec/crates/client/tests/unit/client/with_monitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn multi_devices(env: &TestbedEnv) {
workspace_storage_cache_size: WorkspaceStorageCacheSize::Default,
proxy: libparsec_client_connection::ProxyConfig::default(),
with_monitors: true,
prevent_sync_pattern: Regex::empty(),
prevent_sync_pattern: PreventSyncPattern::empty(),
});
let alice1_event_bus = EventBus::default();
let alice2_event_bus = EventBus::default();
Expand Down Expand Up @@ -139,7 +139,7 @@ async fn sharing(env: &TestbedEnv) {
workspace_storage_cache_size: WorkspaceStorageCacheSize::Default,
proxy: libparsec_client_connection::ProxyConfig::default(),
with_monitors: true,
prevent_sync_pattern: Regex::empty(),
prevent_sync_pattern: PreventSyncPattern::empty(),
});
let alice_event_bus = EventBus::default();
let bob_event_bus = EventBus::default();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn make_config(env: &TestbedEnv) -> Arc<ClientConfig> {
proxy: ProxyConfig::default(),
mountpoint_mount_strategy: MountpointMountStrategy::Disabled,
with_monitors: false,
prevent_sync_pattern: Regex::from_regex_str(r"\.tmp$").unwrap(),
prevent_sync_pattern: PreventSyncPattern::from_regex(r"\.tmp$").unwrap(),
})
}

Expand Down
2 changes: 1 addition & 1 deletion libparsec/crates/client/tests/unit/invite/claimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn claimer(tmp_path: TmpPath, env: &TestbedEnv) {
proxy: ProxyConfig::default(),
mountpoint_mount_strategy: MountpointMountStrategy::Disabled,
with_monitors: false,
prevent_sync_pattern: Regex::from_regex_str(r"\.tmp$").unwrap(),
prevent_sync_pattern: PreventSyncPattern::from_regex(r"\.tmp$").unwrap(),
});

let alice = env.local_device("alice@dev1");
Expand Down
2 changes: 1 addition & 1 deletion libparsec/crates/client/tests/unit/user/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) async fn user_ops_factory(env: &TestbedEnv, device: &Arc<LocalDevice>
workspace_storage_cache_size: WorkspaceStorageCacheSize::Default,
proxy: ProxyConfig::default(),
with_monitors: false,
prevent_sync_pattern: Regex::empty(),
prevent_sync_pattern: PreventSyncPattern::empty(),
});
let event_bus = EventBus::default();
let cmds = Arc::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async fn good(#[values(true, false)] root_level: bool, env: &TestbedEnv) {
builder.workspace_data_storage_fetch_workspace_vlob(
"alice@dev1",
wksp1_id,
libparsec_types::Regex::empty(),
libparsec_types::PreventSyncPattern::empty(),
);
} else {
builder
Expand All @@ -41,7 +41,7 @@ async fn good(#[values(true, false)] root_level: bool, env: &TestbedEnv) {
"alice@dev1",
wksp1_id,
wksp1_foo_id,
libparsec_types::Regex::empty(),
libparsec_types::PreventSyncPattern::empty(),
);
}
})
Expand Down Expand Up @@ -466,7 +466,7 @@ async fn bootstrap_env(env: &TestbedEnv, root_level: bool) -> Env {

let (base_path, parent_id) = env
.customize(|builder| {
let prevent_sync_pattern = Regex::from_regex_str(r"\.tmp$").unwrap();
let prevent_sync_pattern = PreventSyncPattern::from_regex(r"\.tmp$").unwrap();
let res = if root_level {
// Remove all children from the workspace
builder
Expand Down Expand Up @@ -752,7 +752,7 @@ async fn rename_a_entry_to_be_confined(
&env.discriminant_dir,
&bob,
realm_id,
Regex::empty(), // Use empty pattern to prevent workspace to filter out any entry
PreventSyncPattern::empty(), // Use empty pattern to prevent workspace to filter out any entry
)
.await;
ops_inbound_sync(&bob_ops).await;
Expand Down Expand Up @@ -890,7 +890,7 @@ async fn rename_a_confined_entry_to_not_be_confined(
&env.discriminant_dir,
&bob,
realm_id,
Regex::empty(), // Use empty pattern to prevent workspace to filter out any entry
PreventSyncPattern::empty(), // Use empty pattern to prevent workspace to filter out any entry
)
.await;
ops_inbound_sync(&bob_ops).await;
Expand Down Expand Up @@ -1022,7 +1022,7 @@ async fn rename_a_entry_to_be_confined_with_different_parent(
&env.discriminant_dir,
&bob,
realm_id,
Regex::empty(), // Use empty pattern to prevent workspace to filter out any entry
PreventSyncPattern::empty(), // Use empty pattern to prevent workspace to filter out any entry
)
.await;
ops_inbound_sync(&bob_ops).await;
Expand Down Expand Up @@ -1167,7 +1167,7 @@ async fn rename_a_confined_entry_to_not_be_confined_with_different_parent(
&env.discriminant_dir,
&bob,
realm_id,
Regex::empty(), // Use empty pattern to prevent workspace to filter out any entry
PreventSyncPattern::empty(), // Use empty pattern to prevent workspace to filter out any entry
)
.await;
ops_inbound_sync(&bob_ops).await;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn no_remote_change(
kind: &str,
env: &TestbedEnv,
) {
let prevent_sync_pattern = Regex::from_glob_pattern("*.tmp").unwrap();
let prevent_sync_pattern = PreventSyncPattern::from_glob("*.tmp").unwrap();
let local_author = "alice@dev1".parse().unwrap();
let timestamp = "2021-01-10T00:00:00Z".parse().unwrap();
let vlob_id = VlobID::from_hex("87c6b5fd3b454c94bab51d6af1c6930b").unwrap();
Expand Down Expand Up @@ -175,7 +175,7 @@ async fn no_remote_change_but_local_uses_outdated_prevent_sync_pattern(
unknown => panic!("Unknown kind: {}", unknown),
}

let new_prevent_sync_pattern = Regex::from_glob_pattern("*.tmp").unwrap();
let new_prevent_sync_pattern = PreventSyncPattern::from_glob("*.tmp").unwrap();
let outcome = merge_local_folder_manifest(
local_author,
timestamp,
Expand Down Expand Up @@ -263,7 +263,7 @@ async fn remote_only_change(
speculative: false,
};

let prevent_sync_pattern = Regex::from_glob_pattern("*.tmp").unwrap();
let prevent_sync_pattern = PreventSyncPattern::from_glob("*.tmp").unwrap();
let child_id = VlobID::from_hex("1040c4845fd1451b9c243c93991d9a5e").unwrap();
let confined_id = VlobID::from_hex("9100fa0bfca94e4d96077dd274a243c0").unwrap();
match kind {
Expand Down Expand Up @@ -658,7 +658,7 @@ async fn local_and_remote_changes(
speculative: false,
};

let prevent_sync_pattern = Regex::from_glob_pattern("*.tmp").unwrap();
let prevent_sync_pattern = PreventSyncPattern::from_glob("*.tmp").unwrap();
match kind {
"only_updated_field_modified" => {
// Since only `updated` has been modified on local, then
Expand Down
4 changes: 2 additions & 2 deletions libparsec/crates/client/tests/unit/workspace/move_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async fn src_not_found(
"alice@dev1",
wksp1_id,
wksp1_id,
libparsec_types::Regex::empty(),
libparsec_types::PreventSyncPattern::empty(),
);
}
})
Expand Down Expand Up @@ -253,7 +253,7 @@ async fn exchange_but_dst_not_found(
"alice@dev1",
wksp1_id,
wksp1_id,
libparsec_types::Regex::empty(),
libparsec_types::PreventSyncPattern::empty(),
);
}
})
Expand Down
4 changes: 2 additions & 2 deletions libparsec/crates/client/tests/unit/workspace/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub(crate) async fn workspace_ops_factory(
discriminant_dir,
device,
realm_id,
Regex::from_regex_str(r"\.tmp$").unwrap(),
PreventSyncPattern::from_regex(r"\.tmp$").unwrap(),
)
.await
}
Expand All @@ -29,7 +29,7 @@ pub(crate) async fn workspace_ops_with_prevent_sync_pattern_factory(
discriminant_dir: &Path,
device: &Arc<LocalDevice>,
realm_id: VlobID,
prevent_sync_pattern: Regex,
prevent_sync_pattern: PreventSyncPattern,
) -> WorkspaceOps {
let config = Arc::new(ClientConfig {
config_dir: discriminant_dir.to_owned(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async fn real_io_provides_a_starting_event(env: &TestbedEnv) {
workspace_storage_cache_size: WorkspaceStorageCacheSize::Default,
proxy: ProxyConfig::default(),
with_monitors: false,
prevent_sync_pattern: Regex::from_regex_str(r"\.tmp$").unwrap(),
prevent_sync_pattern: PreventSyncPattern::from_regex(r"\.tmp$").unwrap(),
});
let event_bus = EventBus::default();
let cmds = Arc::new(
Expand Down
2 changes: 1 addition & 1 deletion libparsec/crates/platform_mountpoint/examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async fn main() -> ExitCode {
workspace_storage_cache_size: WorkspaceStorageCacheSize::Default,
proxy: ProxyConfig::default(),
with_monitors: false,
prevent_sync_pattern: Regex::empty(),
prevent_sync_pattern: PreventSyncPattern::empty(),
});
let client = Client::start(config, event_bus, alice).await.unwrap();
let wksp1_ops = client.start_workspace(wksp1_id).await.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ async fn read_only_realm(
builder.workspace_data_storage_fetch_workspace_vlob(
"bob@dev1",
wksp1_id,
libparsec_types::Regex::empty(),
libparsec_types::PreventSyncPattern::empty(),
);
builder.workspace_data_storage_fetch_file_vlob("bob@dev1", wksp1_id, bar_txt_id);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use libparsec_client::{
Client, ClientConfig, EventBus, MountpointMountStrategy, ProxyConfig, WorkspaceStorageCacheSize,
};
use libparsec_tests_fixtures::prelude::*;
use libparsec_types::Regex;
use libparsec_types::PreventSyncPattern;

#[cfg_attr(target_os = "windows", allow(dead_code))]
pub async fn start_client(env: &TestbedEnv, start_as: &'static str) -> Arc<Client> {
Expand All @@ -28,7 +28,7 @@ pub async fn start_client_with_mountpoint_base_dir(
workspace_storage_cache_size: WorkspaceStorageCacheSize::Default,
proxy: ProxyConfig::default(),
with_monitors: false,
prevent_sync_pattern: Regex::empty(),
prevent_sync_pattern: PreventSyncPattern::empty(),
});
let device = env.local_device(start_as);
Client::start(config, event_bus, device).await.unwrap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn mount_on_drive(env: &TestbedEnv) {
workspace_storage_cache_size: WorkspaceStorageCacheSize::Default,
proxy: ProxyConfig::default(),
with_monitors: false,
prevent_sync_pattern: Regex::empty(),
prevent_sync_pattern: PreventSyncPattern::empty(),
});
let client = Client::start(config, event_bus, alice).await.unwrap();

Expand Down
11 changes: 7 additions & 4 deletions libparsec/crates/platform_storage/src/native/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,10 @@ impl PlatformWorkspaceStorage {
})
}

pub async fn set_prevent_sync_pattern(&mut self, pattern: &Regex) -> anyhow::Result<bool> {
pub async fn set_prevent_sync_pattern(
&mut self,
pattern: &PreventSyncPattern,
) -> anyhow::Result<bool> {
let pattern = pattern.to_string();

let mut transaction = self.conn.begin().await?;
Expand All @@ -436,19 +439,19 @@ impl PlatformWorkspaceStorage {
Ok(fully_applied)
}

pub async fn get_prevent_sync_pattern(&mut self) -> anyhow::Result<(Regex, bool)> {
pub async fn get_prevent_sync_pattern(&mut self) -> anyhow::Result<(PreventSyncPattern, bool)> {
db_get_prevent_sync_pattern(&mut self.conn)
.await
.and_then(|(pattern, fully_applied)| {
Regex::from_regex_str(&pattern)
PreventSyncPattern::from_regex(&pattern)
.map(|re| (re, fully_applied))
.map_err(anyhow::Error::from)
})
}

pub async fn mark_prevent_sync_pattern_fully_applied(
&mut self,
pattern: &Regex,
pattern: &PreventSyncPattern,
) -> Result<(), MarkPreventSyncPatternFullyAppliedError> {
let pattern = pattern.to_string();

Expand Down
Loading
Loading