Skip to content

Commit 061751a

Browse files
committed
Change Container field from 'name' to 'id'
This is a more accurate name, since `RUNTIME_BIN` is accepting the container ID, not the name, as the argument.
1 parent c98217f commit 061751a

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/container.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const RUNTIME_BIN: &str = "/usr/bin/crun";
1616
/// An actively running OCI container.
1717
#[derive(Debug)]
1818
pub struct Container {
19-
name: String,
19+
id: String,
2020
uuid: Uuid,
2121
pid: i32,
2222
console_sock: UnixSeqpacket,
@@ -28,7 +28,6 @@ impl Container {
2828
/// Spawns a new container with the given `id` from the `rt` OCI bundle.
2929
pub async fn create(id: &str, rt: OciBundle) -> anyhow::Result<Self> {
3030
let uuid = Uuid::new_v4();
31-
3231
let start_pipe = StartPipe::new()?;
3332
let mut sync_pipe = SyncPipe::new()?;
3433

@@ -38,9 +37,9 @@ impl Container {
3837
.stderr(Stdio::piped())
3938
.args(&["--syslog", "--log-level=debug"])
4039
.arg("--terminal") // Passes `--console-sock` to `crun`.
41-
.args(&["--cid", id])
40+
.args(&["--cid", &id])
4241
.args(&["--cuuid", &uuid.to_string()])
43-
.args(&["--name", id])
42+
.args(&["--name", &id])
4443
.args(&["--runtime", RUNTIME_BIN])
4544
.args(&["--runtime-arg", "--rootless=true"])
4645
.args(&["--bundle", &rt.bundle_dir.display().to_string()])
@@ -92,7 +91,7 @@ impl Container {
9291
eprintln!("connected to console socket!");
9392

9493
Ok(Container {
95-
name: id.to_string(),
94+
id: id.to_string(),
9695
uuid,
9796
pid,
9897
console_sock,
@@ -104,38 +103,38 @@ impl Container {
104103
/// Start the container, if it isn't already running.
105104
pub async fn start(&self) -> anyhow::Result<()> {
106105
let mut pause_cmd = Command::new(RUNTIME_BIN);
107-
pause_cmd.args(&["start", &self.name]);
106+
pause_cmd.args(&["start", &self.id]);
108107
exec_command(&mut pause_cmd).await?;
109108
Ok(())
110109
}
111110

112111
/// Pause the container's execution, if it currently running.
113112
pub async fn pause(&self) -> anyhow::Result<()> {
114113
let mut pause_cmd = Command::new(RUNTIME_BIN);
115-
pause_cmd.args(&["pause", &self.name]);
114+
pause_cmd.args(&["pause", &self.id]);
116115
exec_command(&mut pause_cmd).await?;
117116
Ok(())
118117
}
119118

120119
/// Resume the container's execution, if it currently paused.
121120
pub async fn resume(&self) -> anyhow::Result<()> {
122121
let mut resume_cmd = Command::new(RUNTIME_BIN);
123-
resume_cmd.args(&["resume", &self.name]);
122+
resume_cmd.args(&["resume", &self.id]);
124123
exec_command(&mut resume_cmd).await?;
125124
Ok(())
126125
}
127126

128127
/// Delete the container immediately.
129128
pub async fn delete(self) -> anyhow::Result<()> {
130129
let mut delete_cmd = Command::new(RUNTIME_BIN);
131-
delete_cmd.args(&["delete", "--force", &self.name]);
130+
delete_cmd.args(&["delete", "--force", &self.id]);
132131
exec_command(&mut delete_cmd).await?;
133132
Ok(())
134133
}
135134

136-
/// Returns the name of the container.
137-
pub fn name(&self) -> &str {
138-
&self.name
135+
/// Returns the ID of the container.
136+
pub fn id(&self) -> &str {
137+
&self.id
139138
}
140139

141140
/// Returns the UUIDv4 assigned to the container.

0 commit comments

Comments
 (0)