Skip to content

Commit c80fa4c

Browse files
committed
fix: gix::open::Permissions now can be compared, and add is_isolated() method.
1 parent 26d5197 commit c80fa4c

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

gix/src/open/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::PathBuf;
33
use crate::{bstr::BString, config};
44

55
/// Permissions associated with various resources of a git repository
6-
#[derive(Debug, Clone)]
6+
#[derive(Copy, Clone, Ord, PartialOrd, PartialEq, Eq, Debug, Hash)]
77
pub struct Permissions {
88
/// Control which environment variables may be accessed.
99
pub env: permissions::Environment,

gix/src/open/permissions.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Default for Attributes {
112112
}
113113

114114
/// Permissions related to the usage of environment variables
115-
#[derive(Debug, Clone, Copy)]
115+
#[derive(Copy, Clone, Ord, PartialOrd, PartialEq, Eq, Debug, Hash)]
116116
pub struct Environment {
117117
/// Control whether resources pointed to by `XDG_CONFIG_HOME` can be used when looking up common configuration values.
118118
///
@@ -170,6 +170,7 @@ impl Environment {
170170
}
171171
}
172172

173+
/// Lifecycle
173174
impl Permissions {
174175
/// Secure permissions are similar to `all()`
175176
pub fn secure() -> Self {
@@ -200,6 +201,14 @@ impl Permissions {
200201
}
201202
}
202203

204+
/// Access
205+
impl Permissions {
206+
/// Return true if these permissions only allow repository-local configuration and deny environment access.
207+
pub fn is_isolated(&self) -> bool {
208+
*self == Self::isolated()
209+
}
210+
}
211+
203212
impl gix_sec::trust::DefaultForLevel for Permissions {
204213
fn default_for_level(level: Trust) -> Self {
205214
match level {

gix/tests/gix/repository/open.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ use gix::bstr::BString;
44

55
use crate::util::named_subrepo_opts;
66

7+
#[test]
8+
fn open_permissions_is_isolated() {
9+
assert!(gix::open::Permissions::isolated().is_isolated());
10+
assert!(!gix::open::Permissions::all().is_isolated());
11+
}
12+
713
#[test]
814
fn on_root_with_decomposed_unicode() -> crate::Result {
915
let tmp = gix_testtools::tempfile::TempDir::new()?;

0 commit comments

Comments
 (0)