Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

fix(windows): sync OPFS and storage directories safely

zhouziruia9c6e3ba4e85
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index e3b4da514..21979596e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -143,10 +143,10 @@ jobs:
- name: Run full workspace tests
run: cargo nextest run --workspace --profile ci
- windows-browser-profile:
- name: Windows browser profile
+ windows-persistent-storage:
+ name: Windows persistent storage
runs-on: windows-2025
- timeout-minutes: 20
+ timeout-minutes: 25
steps:
- name: Checkout repository
uses: 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-service
python-harness-tests:
name: Python harness tests
diff --git a/moli-opfs/src/staging.rs b/moli-opfs/src/staging.rs
index 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.rs
index 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 `{}`",