fix(rome_cli): Allow to run on read-only file systems
MODIFY
crates/rome_cli/src/traversal.rs
crates/rome_cli/src/traversal.rs
@@ -770,7 +770,14 @@ fn process_file(ctx: &TraversalOptions, path: &Path, file_id: FileId) -> FileRes
};
}
- let open_options = OpenOptions::default().read(true).write(true);
+ let write_access = matches!(
+ ctx.execution.traversal_mode(),
+ TraversalMode::Check {
+ fix_file_mode: Some(_),
+ } | TraversalMode::Format { write: true, .. }
+ );
+
+ let open_options = OpenOptions::default().read(true).write(write_access);
let mut file = ctx
.fs
.open_with_options(path, open_options)

MODIFY
crates/rome_cli/tests/commands/check.rs
crates/rome_cli/tests/commands/check.rs
@@ -85,6 +85,23 @@ fn ok() {
assert!(result.is_ok(), "run_cli returned {result:?}");
}
+#[test]
+fn ok_read_only() {
+ let mut fs = MemoryFileSystem::new_read_only();
+ let mut console = BufferConsole::default();
+
+ let file_path = Path::new("check.js");
+ fs.insert(file_path.into(), FORMATTED.as_bytes());
+
+ let result = run_cli(
+ DynRef::Borrowed(&mut fs),
+ DynRef::Borrowed(&mut console),
+ Arguments::from_vec(vec![OsString::from("check"), file_path.as_os_str().into()]),
+ );
+
+ assert!(result.is_ok(), "run_cli returned {result:?}");
+}
+
#[test]
fn parse_error() {
let mut fs = MemoryFileSystem::default();
@@ -793,6 +810,38 @@ fn fs_error_infinite_symlink_exapansion() {
));
}
+#[test]
+fn fs_error_read_only() {
+ let mut fs = MemoryFileSystem::new_read_only();
+ let mut console = BufferConsole::default();
+
+ let file_path = Path::new("test.js");
+ fs.insert(file_path.into(), *b"content");
+
+ let result = run_cli(
+ DynRef::Borrowed(&mut fs),
+ DynRef::Borrowed(&mut console),
+ Arguments::from_vec(vec![
+ OsString::from("check"),
+ OsString::from("--apply"),
+ file_path.as_os_str().into(),
+ ]),
+ );
+
+ assert!(result.is_err(), "run_cli returned {result:?}");
+
+ // Do not store the content of the file in the snapshot
+ fs.remove(file_path);
+
+ assert_cli_snapshot(SnapshotPayload::new(
+ module_path!(),
+ "fs_error_read_only",
+ fs,
+ console,
+ result,
+ ));
+}
+
#[test]
fn fs_error_unknown() {
let mut fs = MemoryFileSystem::default();

MODIFY
crates/rome_cli/tests/commands/format.rs
crates/rome_cli/tests/commands/format.rs
@@ -1158,6 +1158,38 @@ fn does_not_format_ignored_directories() {
));
}
+#[test]
+fn fs_error_read_only() {
+ let mut fs = MemoryFileSystem::new_read_only();
+ let mut console = BufferConsole::default();
+
+ let file_path = Path::new("test.js");
+ fs.insert(file_path.into(), *b"content");
+
+ let result = run_cli(
+ DynRef::Borrowed(&mut fs),
+ DynRef::Borrowed(&mut console),
+ Arguments::from_vec(vec![
+ OsString::from("format"),
+ OsString::from("--write"),
+ file_path.as_os_str().into(),
+ ]),
+ );
+
+ assert!(result.is_err(), "run_cli returned {result:?}");
+
+ // Do not store the content of the file in the snapshot
+ fs.remove(file_path);
+
+ assert_cli_snapshot(SnapshotPayload::new(
+ module_path!(),
+ "fs_error_read_only",
+ fs,
+ console,
+ result,
+ ));
+}
+
#[test]
fn file_too_large() {
let mut fs = MemoryFileSystem::default();

MODIFY
crates/rome_service/src/configuration/mod.rs
crates/rome_service/src/configuration/mod.rs
@@ -177,7 +177,7 @@ pub fn load_config(
"Attempting to load the configuration file at path {:?}",
configuration_path
);
- let options = OpenOptions::default().read(true).write(true);
+ let options = OpenOptions::default().read(true);
let file = file_system.open_with_options(&configuration_path, options);
match file {
Ok(mut file) => {

fix(rome_cli): Allow to run on read-only file systems (#3851)