aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/command')
-rw-r--r--crates/shirabe/src/command/bump_command.rs11
-rw-r--r--crates/shirabe/src/command/init_command.rs4
-rw-r--r--crates/shirabe/src/command/package_discovery_trait.rs4
-rw-r--r--crates/shirabe/src/command/require_command.rs23
4 files changed, 24 insertions, 18 deletions
diff --git a/crates/shirabe/src/command/bump_command.rs b/crates/shirabe/src/command/bump_command.rs
index e10f7b15..9639cbe9 100644
--- a/crates/shirabe/src/command/bump_command.rs
+++ b/crates/shirabe/src/command/bump_command.rs
@@ -73,8 +73,8 @@ impl BumpCommand {
let composer_json = JsonFile::new(composer_json_path.clone(), None, None)?;
let contents = match file_get_contents(composer_json.get_path()) {
- Some(c) => c,
- None => {
+ Ok(c) => c,
+ Err(_) => {
io.write_error3(
&format!("<error>{} is not readable.</error>", composer_json_path),
true,
@@ -86,7 +86,7 @@ impl BumpCommand {
if !is_writable(&composer_json_path)
&& Silencer::call(|| {
- file_put_contents(&composer_json_path, contents.as_bytes())
+ file_put_contents(&composer_json_path, &contents)
.map(|_| ())
.ok_or_else(|| anyhow::anyhow!("file_put_contents failed"))
})
@@ -305,8 +305,9 @@ impl BumpCommand {
updates: &indexmap::IndexMap<&str, indexmap::IndexMap<String, String>>,
) -> anyhow::Result<bool> {
let contents = match file_get_contents(json.get_path()) {
- Some(c) => c,
- None => {
+ // TODO(bytes): JsonManipulator takes the JSON as a String.
+ Ok(c) => String::from_utf8_lossy(&c).into_owned(),
+ Err(_) => {
return Err(shirabe_php_shim::RuntimeException::new(format!(
"Unable to read {} contents.",
json.get_path()
diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs
index 8d892bd3..67530008 100644
--- a/crates/shirabe/src/command/init_command.rs
+++ b/crates/shirabe/src/command/init_command.rs
@@ -215,7 +215,9 @@ impl InitCommand {
fn add_vendor_ignore(&self, ignore_file: &str, vendor: &str) {
let mut contents = String::new();
if file_exists(ignore_file) {
- contents = file_get_contents(ignore_file).unwrap_or_default();
+ // TODO(bytes): the ignore file is edited as a String.
+ contents = String::from_utf8_lossy(&file_get_contents(ignore_file).unwrap_or_default())
+ .into_owned();
if strpos(&contents, "\n") != Some(0) {
contents.push('\n');
diff --git a/crates/shirabe/src/command/package_discovery_trait.rs b/crates/shirabe/src/command/package_discovery_trait.rs
index 4a915fbe..4816e9d4 100644
--- a/crates/shirabe/src/command/package_discovery_trait.rs
+++ b/crates/shirabe/src/command/package_discovery_trait.rs
@@ -112,7 +112,9 @@ pub trait PackageDiscoveryTrait: BaseCommand {
// @phpstan-ignore-next-line as RequireCommand does not have the option above so this code is reachable there
let file = Factory::get_composer_file().unwrap_or_default();
if is_file(&file) && Filesystem::is_readable(&file) {
- let contents = file_get_contents(&file).unwrap_or_default();
+ // TODO(bytes): json_decode_assoc takes the JSON as a &str.
+ let contents =
+ String::from_utf8_lossy(&file_get_contents(&file).unwrap_or_default()).into_owned();
let composer = json_decode_assoc(&contents).unwrap_or(PhpMixed::Null);
if is_array(&composer)
&& let Some(arr) = composer.as_array()
diff --git a/crates/shirabe/src/command/require_command.rs b/crates/shirabe/src/command/require_command.rs
index 4f90a532..2dfb140d 100644
--- a/crates/shirabe/src/command/require_command.rs
+++ b/crates/shirabe/src/command/require_command.rs
@@ -51,11 +51,11 @@ pub struct RequireCommand {
first_require: std::cell::Cell<bool>,
json: std::cell::RefCell<Option<std::rc::Rc<std::cell::RefCell<JsonFile>>>>,
file: std::cell::RefCell<String>,
- composer_backup: std::cell::RefCell<String>,
+ composer_backup: std::cell::RefCell<Vec<u8>>,
/// file name
lock: std::cell::RefCell<String>,
/// contents before modification if the lock file exists
- lock_backup: std::cell::RefCell<Option<String>>,
+ lock_backup: std::cell::RefCell<Option<Vec<u8>>>,
dependency_resolution_completed: std::rc::Rc<std::cell::Cell<bool>>,
repos: std::cell::RefCell<Option<crate::repository::RepositoryInterfaceHandle>>,
repository_sets:
@@ -78,7 +78,7 @@ impl RequireCommand {
first_require: std::cell::Cell::new(false),
json: std::cell::RefCell::new(None),
file: std::cell::RefCell::new(String::new()),
- composer_backup: std::cell::RefCell::new(String::new()),
+ composer_backup: std::cell::RefCell::new(Vec::new()),
lock: std::cell::RefCell::new(String::new()),
lock_backup: std::cell::RefCell::new(None),
dependency_resolution_completed: std::rc::Rc::new(std::cell::Cell::new(false)),
@@ -655,7 +655,11 @@ impl RequireCommand {
remove_key: &str,
sort_packages: bool,
) -> bool {
- let contents = file_get_contents(json.borrow().get_path()).unwrap_or_default();
+ // TODO(bytes): JsonManipulator takes the JSON as a String.
+ let contents = String::from_utf8_lossy(
+ &file_get_contents(json.borrow().get_path()).unwrap_or_default(),
+ )
+ .into_owned();
let mut manipulator = match JsonManipulator::new(contents) {
Ok(m) => m,
@@ -712,12 +716,9 @@ impl RequireCommand {
extra
);
self.get_io().write_error3(&msg, true, io_interface::NORMAL);
- file_put_contents(
- json.borrow().get_path(),
- self.composer_backup.borrow().as_bytes(),
- );
+ file_put_contents(json.borrow().get_path(), &self.composer_backup.borrow());
if let Some(ref lock_backup) = *self.lock_backup.borrow() {
- file_put_contents(&lock, lock_backup.as_bytes());
+ file_put_contents(&lock, lock_backup);
}
}
}
@@ -837,7 +838,7 @@ impl Command for RequireCommand {
file_get_contents(json.borrow().get_path()).unwrap_or_default();
let lock = self.lock.borrow().clone();
*self.lock_backup.borrow_mut() = if file_exists(&lock) {
- file_get_contents(&lock)
+ file_get_contents(&lock).ok()
} else {
None
};
@@ -859,7 +860,7 @@ impl Command for RequireCommand {
let backup_contents = self.composer_backup.borrow().clone();
if !is_writable(&file)
&& Silencer::call(|| {
- shirabe_php_shim::file_put_contents(&file_path, backup_contents.as_bytes());
+ shirabe_php_shim::file_put_contents(&file_path, &backup_contents);
Ok::<bool, anyhow::Error>(false)
})
.ok()