mirror of
https://github.com/kata-containers/cgroups-rs.git
synced 2026-08-05 02:13:23 +00:00
Merge pull request #159 from Lu-yq/fix-verify-path
cgroups-rs: fix verify_path() logic
This commit is contained in:
@@ -164,20 +164,10 @@ mod sealed {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_path(&self) -> Result<()> {
|
|
||||||
if self.get_path().starts_with(self.get_base()) {
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(Error::new(ErrorKind::InvalidPath))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn open_path(&self, p: &str, w: bool) -> Result<File> {
|
fn open_path(&self, p: &str, w: bool) -> Result<File> {
|
||||||
let mut path = self.get_path().clone();
|
let mut path = self.get_path().clone();
|
||||||
path.push(p);
|
path.push(p);
|
||||||
|
|
||||||
self.verify_path()?;
|
|
||||||
|
|
||||||
if w {
|
if w {
|
||||||
match File::create(&path) {
|
match File::create(&path) {
|
||||||
Err(e) => Err(Error::with_cause(
|
Err(e) => Err(Error::with_cause(
|
||||||
@@ -213,10 +203,6 @@ mod sealed {
|
|||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn path_exists(&self, p: &str) -> bool {
|
fn path_exists(&self, p: &str) -> bool {
|
||||||
if self.verify_path().is_err() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::path::Path::new(p).exists()
|
std::path::Path::new(p).exists()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -323,9 +309,6 @@ where
|
|||||||
|
|
||||||
/// Create this controller
|
/// Create this controller
|
||||||
fn create(&self) -> Result<()> {
|
fn create(&self) -> Result<()> {
|
||||||
self.verify_path()
|
|
||||||
.unwrap_or_else(|_| panic!("path should be valid: {:?}", self.path()));
|
|
||||||
|
|
||||||
std::fs::create_dir_all(self.get_path())
|
std::fs::create_dir_all(self.get_path())
|
||||||
.map_err(|err| Error::with_cause(ErrorKind::FsError, err))?;
|
.map_err(|err| Error::with_cause(ErrorKind::FsError, err))?;
|
||||||
self.post_create();
|
self.post_create();
|
||||||
|
|||||||
Reference in New Issue
Block a user