Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
fix(windows): sync OPFS and storage directories safely
zhouziruia9c6e3ba4e85
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex e3b4da514..21979596e 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -143,10 +143,10 @@ jobs:- name: Run full workspace testsrun: cargo nextest run --workspace --profile ci- windows-browser-profile:- name: Windows browser profile+ windows-persistent-storage:+ name: Windows persistent storageruns-on: windows-2025- timeout-minutes: 20+ timeout-minutes: 25steps:- name: Checkout repositoryuses: actions/checkout@v4@@ -159,8 +159,12 @@ jobs:$toolchain = (Get-Content rust-toolchain -Raw).Trim()rustup toolchain install $toolchain --profile minimal --no-self-update- - name: Test browser profile persistence on Windows- run: cargo test --locked -p moli-browser-profile+ - name: Test Windows profile, OPFS, and storage paths+ run: >-+ cargo test --locked+ -p moli-browser-profile+ -p moli-opfs+ -p moli-storage-servicepython-harness-tests:name: Python harness testsdiff --git a/moli-opfs/src/staging.rs b/moli-opfs/src/staging.rsindex 36d70e22f..724642ccc 100644--- a/moli-opfs/src/staging.rs+++ b/moli-opfs/src/staging.rs@@ -321,11 +321,29 @@ pub(crate) fn cleanup_staging_directory(bucket_dir: &Path) -> OpfsResult<()> {}pub(crate) fn sync_directory(path: &Path) -> OpfsResult<()> {- File::open(path)- .and_then(|directory| directory.sync_all())+ sync_directory_handle(path).map_err(|source| OpfsError::io("sync backend directory", path, source))}+#[cfg(not(windows))]+fn sync_directory_handle(path: &Path) -> std::io::Result<()> {+ File::open(path)?.sync_all()+}++#[cfg(windows)]+fn sync_directory_handle(path: &Path) -> std::io::Result<()> {+ use std::os::windows::fs::OpenOptionsExt;++ const FILE_FLAG_BACKUP_SEMANTICS: u32 = 0x0200_0000;+ const GENERIC_WRITE: u32 = 0x4000_0000;++ OpenOptions::new()+ .access_mode(GENERIC_WRITE)+ .custom_flags(FILE_FLAG_BACKUP_SEMANTICS)+ .open(path)?+ .sync_all()+}+fn staging_path(bucket_dir: &Path, owner_id: u64) -> PathBuf {bucket_dir.join(STAGING_DIR_NAME)diff --git a/moli-storage-service/src/buckets.rs b/moli-storage-service/src/buckets.rsindex bf1fcc7bc..b4aa01153 100644--- a/moli-storage-service/src/buckets.rs+++ b/moli-storage-service/src/buckets.rs@@ -1914,14 +1914,41 @@ fn remove_storage_bucket_cache_path_if_exists(path: &Path, label: &str) -> Resul}fn sync_storage_bucket_cache_directory(path: &Path) -> Result<()> {- fs::File::open(path)- .and_then(|directory| directory.sync_all())- .with_context(|| {- format!(- "failed to sync StorageBucket CacheStorage directory `{}`",- path.display()- )- })+ sync_storage_bucket_cache_directory_handle(path).with_context(|| {+ format!(+ "failed to sync StorageBucket CacheStorage directory `{}`",+ path.display()+ )+ })+}++#[cfg(not(windows))]+fn sync_storage_bucket_cache_directory_handle(path: &Path) -> io::Result<()> {+ fs::File::open(path)?.sync_all()+}++#[cfg(windows)]+fn sync_storage_bucket_cache_directory_handle(path: &Path) -> io::Result<()> {+ use std::{fs::OpenOptions, os::windows::fs::OpenOptionsExt};++ const FILE_FLAG_BACKUP_SEMANTICS: u32 = 0x0200_0000;+ const GENERIC_WRITE: u32 = 0x4000_0000;++ OpenOptions::new()+ .access_mode(GENERIC_WRITE)+ .custom_flags(FILE_FLAG_BACKUP_SEMANTICS)+ .open(path)?+ .sync_all()+}++#[cfg(not(windows))]+fn sync_storage_bucket_cache_file(path: &Path) -> io::Result<()> {+ fs::File::open(path)?.sync_all()+}++#[cfg(windows)]+fn sync_storage_bucket_cache_file(path: &Path) -> io::Result<()> {+ fs::OpenOptions::new().write(true).open(path)?.sync_all()}fn sync_storage_bucket_cache_parent(path: &Path) -> Result<()> {@@ -1957,14 +1984,12 @@ fn sync_storage_bucket_cache_tree(path: &Path) -> Result<()> {if file_type.is_dir() {sync_storage_bucket_cache_tree(&entry_path)?;} else if file_type.is_file() {- fs::File::open(&entry_path)- .and_then(|file| file.sync_all())- .with_context(|| {- format!(- "failed to sync StorageBucket CacheStorage replacement file `{}`",- entry_path.display()- )- })?;+ sync_storage_bucket_cache_file(&entry_path).with_context(|| {+ format!(+ "failed to sync StorageBucket CacheStorage replacement file `{}`",+ entry_path.display()+ )+ })?;} else {bail!("unsupported entry in StorageBucket CacheStorage replacement `{}`",