Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle relative paths #740

Merged
merged 4 commits into from
Feb 27, 2022
Merged

Conversation

Szymongib
Copy link
Contributor

@Szymongib Szymongib commented Feb 26, 2022

This PR improves the handling of relative paths for root_path and pid_file. I decided to create the specified directory early in determine_root_path if it does not exist, as this seems to be the only way to canonicalize path prior to creating container dir (path needs to exist otherwise canonicalize will fail). This results in the directory being created for other commands like list or delete also which might not be ideal, but runc seems to work this way either so decided to stick with it.

Also not sure about canonicalizing those paths in ContainerBuilder as it disrupts the interface slightly by introducing Result<Self> as a return type to some methods, however, I did not find a better place for that so if anyone has some suggestions please let me know.

Additionally, I have added context to a few errors that made it easier to initially troubleshoot.

Fixes #720

Signed-off-by: Szymon Gibała <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Feb 26, 2022

Codecov Report

Merging #740 (58fdcb4) into main (b349b65) will increase coverage by 0.28%.
The diff coverage is 83.09%.

@@            Coverage Diff             @@
##             main     #740      +/-   ##
==========================================
+ Coverage   71.87%   72.16%   +0.28%     
==========================================
  Files          87       87              
  Lines       11854    11912      +58     
==========================================
+ Hits         8520     8596      +76     
+ Misses       3334     3316      -18     

Signed-off-by: Szymon Gibała <[email protected]>
Signed-off-by: Szymon Gibała <[email protected]>
self.root_path = path
.into()
.canonicalize()
.context("failed to canonicalize root path")?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.context("failed to canonicalize root path")?;
.with_context(||format!("failed to canonicalize root path {:?}", path))?;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to adjust it slightly as Into<PathBuf> is not Debug.

Some(
p.into()
.canonicalize()
.context("failed canonicalize pid file path")?,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.context("failed canonicalize pid file path")?,
.with_context(|| format!("failed canonicalize pid file path"))?,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to add the path here too? Adjusted it similarly to the other one.

Comment on lines +42 to +49
let spec = self.load_spec().context("failed to load spec")?;
let container_dir = self
.create_container_dir()
.context("failed to create container dir")?;

let mut container = self
.create_container_state(&container_dir)
.context("failed to create container state")?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Signed-off-by: Szymon Gibała <[email protected]>
@Szymongib Szymongib force-pushed the fix/handle-relative-paths branch from a738f40 to 58fdcb4 Compare February 27, 2022 09:43
@Szymongib Szymongib requested a review from Furisto February 27, 2022 09:52
@Furisto
Copy link
Collaborator

Furisto commented Feb 27, 2022

@Szymongib 💯

@Furisto Furisto merged commit b8e3cba into youki-dev:main Feb 27, 2022
@Szymongib Szymongib deleted the fix/handle-relative-paths branch February 27, 2022 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to create container when using relative root path
3 participants