Skip to content
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
26 changes: 21 additions & 5 deletions crates/argus-core/src/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

mod packaged;

use std::path::Path;
use std::{io::ErrorKind, os::windows::fs::OpenOptionsExt, path::Path};

use serde::Serialize;
use windows::Win32::Foundation::{
ERROR_FILE_NOT_FOUND, ERROR_SUCCESS, FILETIME, MAX_PATH, WIN32_ERROR,
};
use windows::Win32::Storage::FileSystem::{DELETE, FILE_FLAG_OPEN_REPARSE_POINT};
use windows::Win32::System::Com::{
CLSCTX_INPROC_SERVER, COINIT_MULTITHREADED, CoCreateInstance, CoInitializeEx, IPersistFile,
STGM_READ,
Expand Down Expand Up @@ -508,6 +509,20 @@ fn remove_file(folder: &Path, name: &str, recycle: bool) -> Result<(), ActionErr
if !path.is_file() {
return Err(ActionError::NotFound);
}
// Check the caller's delete access on the directory entry itself before
// handing it to the Shell. Release the handle before the recycle operation.
if let Err(error) = std::fs::File::options()
.access_mode(DELETE.0)
.custom_flags(FILE_FLAG_OPEN_REPARSE_POINT.0)
.open(&path)
{
crate::diagnostics::file_failure("startup open for deletion", &path, &error);
return Err(match error.kind() {
ErrorKind::PermissionDenied => ActionError::AccessDenied,
ErrorKind::NotFound => ActionError::NotFound,
_ => ActionError::Os(error.to_string()),
});
}
// The paths, each ended by a NUL, and the list by another.
let mut from = wide(&path.to_string_lossy());
from.push(0);
Expand Down Expand Up @@ -727,10 +742,11 @@ mod tests {
.expect("icacls");
assert!(status.success());
}
assert!(matches!(
remove_file(&folder.0, "Locked.lnk", true),
Err(ActionError::AccessDenied)
));
let result = remove_file(&folder.0, "Locked.lnk", true);
assert!(
matches!(result, Err(ActionError::AccessDenied)),
"{result:?}"
);
assert!(folder.0.join("Locked.lnk").exists());
}

Expand Down
7 changes: 7 additions & 0 deletions src-gpui/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,13 @@ pub fn history_move(
Ok(settings_view(&app))
}

pub fn history_reset_dir(
app: crate::native_runtime::Host,
move_records: bool,
) -> Result<SettingsView, String> {
history_move(app, String::new(), move_records)
}

pub fn history_open_dir(dir: State<'_, HistoryDir>) -> Result<(), String> {
open_folder(&dir.read()).map_err(|_| tr!("history.error.open"))
}
Expand Down
63 changes: 32 additions & 31 deletions src-gpui/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ fn argument<T: serde::de::DeserializeOwned>(args: &Value, key: &str) -> Result<T
serde_json::from_value(args.get(key).cloned().unwrap_or(Value::Null))
.map_err(|_| serde_json::json!(argus_core::tr!("app.invalidRequest")))
}
fn history_settings(result: Result<crate::settings::SettingsView, String>) -> Result<Value, Value> {
serde_json::to_value(result.map_err(Value::String)?)
.map_err(|_| Value::String(argus_core::tr!("app.invalidRequest")))
}
pub fn invoke(host: &Host, name: &str, args: Value) -> Result<Value, Value> {
match name {
"desktop_shell" => Ok(serde_json::to_value(crate::commands::desktop_shell())
Expand Down Expand Up @@ -301,15 +297,13 @@ pub fn invoke(host: &Host, name: &str, args: Value) -> Result<Value, Value> {
argument::<Vec<String>>(&args, "keys")?,
))
.expect("serializable command response")),
"history_events" => serde_json::to_value(
crate::commands::history_events(
host.state(),
argument::<i64>(&args, "from")?,
argument::<i64>(&args, "to")?,
)
.map_err(Value::String)?,
"history_events" => crate::commands::history_events(
host.state(),
argument::<i64>(&args, "from")?,
argument::<i64>(&args, "to")?,
)
.map_err(|_| Value::String(argus_core::tr!("app.invalidRequest"))),
.map(|value| serde_json::to_value(value).expect("serializable command response"))
.map_err(|error| serde_json::to_value(error).unwrap_or(serde_json::Value::Null)),
"history_channels" => Ok(serde_json::to_value(crate::commands::history_channels(
host.state(),
argument::<i64>(&args, "from")?,
Expand Down Expand Up @@ -347,29 +341,36 @@ pub fn invoke(host: &Host, name: &str, args: Value) -> Result<Value, Value> {
)
.map(|value| serde_json::to_value(value).expect("serializable command response"))
.map_err(|error| serde_json::to_value(error).unwrap_or(serde_json::Value::Null)),
"history_move" => history_settings(crate::commands::history_move(
"set_history_enabled" => crate::commands::set_history_enabled(
host.clone(),
argument(&args, "dir")?,
argument(&args, "moveRecords")?,
)),
"history_reset_dir" => history_settings(crate::commands::history_move(
host.state(),
host.state(),
argument::<bool>(&args, "enabled")?,
)
.map(|value| serde_json::to_value(value).expect("serializable command response"))
.map_err(|error| serde_json::to_value(error).unwrap_or(serde_json::Value::Null)),
"set_history_options" => crate::commands::set_history_options(
host.clone(),
String::new(),
argument(&args, "moveRecords")?,
)),
"history_open_dir" => crate::commands::history_open_dir(host.state())
.map(|()| Value::Null)
.map_err(Value::String),
"set_history_options" => history_settings(crate::commands::set_history_options(
argument::<crate::settings::HistoryOptionsPatch>(&args, "options")?,
)
.map(|value| serde_json::to_value(value).expect("serializable command response"))
.map_err(|error| serde_json::to_value(error).unwrap_or(serde_json::Value::Null)),
"history_move" => crate::commands::history_move(
host.clone(),
argument(&args, "options")?,
)),
"set_history_enabled" => history_settings(crate::commands::set_history_enabled(
argument::<String>(&args, "dir")?,
argument::<bool>(&args, "moveRecords")?,
)
.map(|value| serde_json::to_value(value).expect("serializable command response"))
.map_err(|error| serde_json::to_value(error).unwrap_or(serde_json::Value::Null)),
"history_reset_dir" => crate::commands::history_reset_dir(
host.clone(),
host.state(),
host.state(),
argument(&args, "enabled")?,
)),
argument::<bool>(&args, "moveRecords")?,
)
.map(|value| serde_json::to_value(value).expect("serializable command response"))
.map_err(|error| serde_json::to_value(error).unwrap_or(serde_json::Value::Null)),
"history_open_dir" => crate::commands::history_open_dir(host.state())
.map(|value| serde_json::to_value(value).expect("serializable command response"))
.map_err(|error| serde_json::to_value(error).unwrap_or(serde_json::Value::Null)),
"set_kernel_sensors" => crate::commands::set_kernel_sensors(
host.clone(),
host.state(),
Expand Down