Skip to content

Commit 49cc4d7

Browse files
allisonkarlitskayacgwalters
authored andcommitted
image: change Symlink(OsString) to Box<OsStr>
...for the same reason as all the others. Signed-off-by: Allison Karlitskaya <[email protected]>
1 parent 66f543f commit 49cc4d7

File tree

4 files changed

+17
-23
lines changed

4 files changed

+17
-23
lines changed

src/fs.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use std::{
22
cell::RefCell,
33
cmp::max,
44
collections::{BTreeMap, HashMap},
5-
ffi::{CStr, OsStr, OsString},
5+
ffi::{CStr, OsStr},
66
fs::File,
77
io::Write,
88
mem::MaybeUninit,
9-
os::unix::ffi::{OsStrExt, OsStringExt},
9+
os::unix::ffi::OsStrExt,
1010
path::Path,
1111
rc::Rc,
1212
};
@@ -88,24 +88,24 @@ fn write_directory(
8888
fn write_leaf(leaf: &Leaf, dirfd: &OwnedFd, name: &OsStr, repo: &Repository) -> Result<()> {
8989
let mode = leaf.stat.st_mode.into();
9090

91-
match leaf.content {
91+
match &leaf.content {
9292
LeafContent::Regular(RegularFile::Inline(ref data)) => {
9393
set_file_contents(dirfd, name, &leaf.stat, data)?
9494
}
9595
LeafContent::Regular(RegularFile::External(ref id, size)) => {
9696
let object = repo.open_object(id)?;
9797
// TODO: make this better. At least needs to be EINTR-safe. Could even do reflink in some cases...
98-
let mut buffer = vec![MaybeUninit::uninit(); size as usize];
98+
let mut buffer = vec![MaybeUninit::uninit(); *size as usize];
9999
let (data, _) = read(object, &mut buffer)?;
100100
set_file_contents(dirfd, name, &leaf.stat, data)?;
101101
}
102-
LeafContent::BlockDevice(rdev) => mknodat(dirfd, name, FileType::BlockDevice, mode, rdev)?,
102+
LeafContent::BlockDevice(rdev) => mknodat(dirfd, name, FileType::BlockDevice, mode, *rdev)?,
103103
LeafContent::CharacterDevice(rdev) => {
104-
mknodat(dirfd, name, FileType::CharacterDevice, mode, rdev)?
104+
mknodat(dirfd, name, FileType::CharacterDevice, mode, *rdev)?
105105
}
106106
LeafContent::Socket => mknodat(dirfd, name, FileType::Socket, mode, 0)?,
107107
LeafContent::Fifo => mknodat(dirfd, name, FileType::Fifo, mode, 0)?,
108-
LeafContent::Symlink(ref target) => symlinkat(target, dirfd, name)?,
108+
LeafContent::Symlink(target) => symlinkat(target.as_ref(), dirfd, name)?,
109109
}
110110

111111
Ok(())
@@ -202,7 +202,7 @@ impl FilesystemReader<'_> {
202202
}
203203
FileType::Symlink => {
204204
let target = readlinkat(fd, "", [])?;
205-
LeafContent::Symlink(OsString::from_vec(target.into_bytes()))
205+
LeafContent::Symlink(OsStr::from_bytes(target.as_bytes()).into())
206206
}
207207
FileType::CharacterDevice => LeafContent::CharacterDevice(buf.st_rdev),
208208
FileType::BlockDevice => LeafContent::BlockDevice(buf.st_rdev),

src/image.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
use std::{
2-
cell::RefCell,
3-
collections::BTreeMap,
4-
ffi::{OsStr, OsString},
5-
path::Path,
6-
rc::Rc,
7-
};
1+
use std::{cell::RefCell, collections::BTreeMap, ffi::OsStr, path::Path, rc::Rc};
82

93
use anyhow::{bail, Context, Result};
104

@@ -32,7 +26,7 @@ pub enum LeafContent {
3226
CharacterDevice(u64),
3327
Fifo,
3428
Socket,
35-
Symlink(OsString),
29+
Symlink(Box<OsStr>),
3630
}
3731

3832
#[derive(Debug)]

src/oci/tar.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ fn path_from_tar(pax: Option<Box<[u8]>>, gnu: Vec<u8>, short: &[u8]) -> PathBuf
146146
PathBuf::from(OsString::from_vec(path))
147147
}
148148

149-
fn symlink_target_from_tar(pax: Option<Box<[u8]>>, gnu: Vec<u8>, short: &[u8]) -> OsString {
150-
if let Some(ref name) = pax {
151-
OsString::from(OsStr::from_bytes(name))
149+
fn symlink_target_from_tar(pax: Option<Box<[u8]>>, gnu: Vec<u8>, short: &[u8]) -> Box<OsStr> {
150+
if let Some(name) = pax {
151+
OsStr::from_bytes(name.as_ref()).into()
152152
} else if !gnu.is_empty() {
153-
OsString::from_vec(gnu)
153+
OsStr::from_bytes(&gnu).into()
154154
} else {
155-
OsString::from(OsStr::from_bytes(short))
155+
OsStr::from_bytes(short).into()
156156
}
157157
}
158158

tests/mkfs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{
22
cell::RefCell,
33
collections::BTreeMap,
4-
ffi::{OsStr, OsString},
4+
ffi::OsStr,
55
io::Write,
66
process::{Command, Stdio},
77
rc::Rc,
@@ -67,7 +67,7 @@ fn simple(fs: &mut FileSystem) {
6767
add_leaf(
6868
&mut fs.root,
6969
"symlink",
70-
LeafContent::Symlink(OsString::from("/target")),
70+
LeafContent::Symlink(OsStr::new("/target").into()),
7171
);
7272
}
7373

0 commit comments

Comments
 (0)