Skip to content

Commit e99f94f

Browse files
committed
Merge remote-tracking branch 'upstream/master' into module-rc
2 parents 89da417 + 6ba1685 commit e99f94f

25 files changed

Lines changed: 432 additions & 554 deletions

native/src/base/cstr.rs

Lines changed: 98 additions & 268 deletions
Large diffs are not rendered by default.

native/src/base/cxx_extern.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ use libc::{c_char, mode_t};
88
use crate::files::map_file_at;
99
pub(crate) use crate::xwrap::*;
1010
use crate::{
11-
CxxResultExt, Directory, FsPath, OsResultStatic, Utf8CStr, clone_attr, cstr, cstr_buf,
12-
fclone_attr, fd_path, map_fd, map_file, slice_from_ptr,
11+
CxxResultExt, Directory, FsPath, OsResultStatic, Utf8CStr, clone_attr, cstr, fclone_attr,
12+
fd_path, map_fd, map_file, slice_from_ptr,
1313
};
1414

1515
pub(crate) fn fd_path_for_cxx(fd: RawFd, buf: &mut [u8]) -> isize {
16-
let mut buf = cstr_buf::wrap(buf);
16+
let mut buf = cstr::buf::wrap(buf);
1717
fd_path(fd, &mut buf)
1818
.log_cxx()
1919
.map_or(-1_isize, |_| buf.len() as isize)
@@ -23,11 +23,11 @@ pub(crate) fn fd_path_for_cxx(fd: RawFd, buf: &mut [u8]) -> isize {
2323
unsafe extern "C" fn canonical_path(path: *const c_char, buf: *mut u8, bufsz: usize) -> isize {
2424
unsafe {
2525
match Utf8CStr::from_ptr(path) {
26-
Ok(p) => {
27-
let mut buf = cstr_buf::wrap_ptr(buf, bufsz);
28-
FsPath::from(p)
29-
.realpath(&mut buf)
30-
.map_or(-1, |_| buf.len() as isize)
26+
Ok(path) => {
27+
let mut buf = cstr::buf::wrap_ptr(buf, bufsz);
28+
path.realpath(&mut buf)
29+
.log_cxx()
30+
.map_or(-1_isize, |_| buf.len() as isize)
3131
}
3232
Err(_) => -1,
3333
}
@@ -38,7 +38,7 @@ unsafe extern "C" fn canonical_path(path: *const c_char, buf: *mut u8, bufsz: us
3838
unsafe extern "C" fn mkdirs_for_cxx(path: *const c_char, mode: mode_t) -> i32 {
3939
unsafe {
4040
match Utf8CStr::from_ptr(path) {
41-
Ok(p) => FsPath::from(p).mkdirs(mode).map_or(-1, |_| 0),
41+
Ok(path) => path.mkdirs(mode).map_or(-1, |_| 0),
4242
Err(_) => -1,
4343
}
4444
}
@@ -48,7 +48,7 @@ unsafe extern "C" fn mkdirs_for_cxx(path: *const c_char, mode: mode_t) -> i32 {
4848
unsafe extern "C" fn rm_rf_for_cxx(path: *const c_char) -> bool {
4949
unsafe {
5050
match Utf8CStr::from_ptr(path) {
51-
Ok(p) => FsPath::from(p).remove_all().is_ok(),
51+
Ok(path) => path.remove_all().is_ok(),
5252
Err(_) => false,
5353
}
5454
}
@@ -114,8 +114,6 @@ unsafe extern "C" fn cp_afc_for_cxx(src: *const c_char, dest: *const c_char) ->
114114
unsafe {
115115
if let Ok(src) = Utf8CStr::from_ptr(src) {
116116
if let Ok(dest) = Utf8CStr::from_ptr(dest) {
117-
let src = FsPath::from(src);
118-
let dest = FsPath::from(dest);
119117
return src.copy_to(dest).log_cxx().is_ok();
120118
}
121119
}
@@ -128,8 +126,6 @@ unsafe extern "C" fn mv_path_for_cxx(src: *const c_char, dest: *const c_char) ->
128126
unsafe {
129127
if let Ok(src) = Utf8CStr::from_ptr(src) {
130128
if let Ok(dest) = Utf8CStr::from_ptr(dest) {
131-
let src = FsPath::from(src);
132-
let dest = FsPath::from(dest);
133129
return src.move_to(dest).log_cxx().is_ok();
134130
}
135131
}
@@ -142,8 +138,6 @@ unsafe extern "C" fn link_path_for_cxx(src: *const c_char, dest: *const c_char)
142138
unsafe {
143139
if let Ok(src) = Utf8CStr::from_ptr(src) {
144140
if let Ok(dest) = Utf8CStr::from_ptr(dest) {
145-
let src = FsPath::from(src);
146-
let dest = FsPath::from(dest);
147141
return src.link_to(dest).log_cxx().is_ok();
148142
}
149143
}
@@ -156,8 +150,6 @@ unsafe extern "C" fn clone_attr_for_cxx(src: *const c_char, dest: *const c_char)
156150
unsafe {
157151
if let Ok(src) = Utf8CStr::from_ptr(src) {
158152
if let Ok(dest) = Utf8CStr::from_ptr(dest) {
159-
let src = FsPath::from(src);
160-
let dest = FsPath::from(dest);
161153
return clone_attr(src, dest).log_cxx().is_ok();
162154
}
163155
}

native/src/base/dir.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::cxx_extern::readlinkat;
22
use crate::{
3-
FileAttr, FsPathBuf, LibcReturn, OsError, OsResult, OsResultStatic, Utf8CStr, Utf8CStrBuf,
4-
cstr_buf, errno, fd_path, fd_set_attr,
3+
FileAttr, FsPath, FsPathBuilder, LibcReturn, OsError, OsResult, OsResultStatic, Utf8CStr,
4+
Utf8CStrBuf, cstr, errno, fd_path, fd_set_attr,
55
};
66
use libc::{EEXIST, O_CLOEXEC, O_CREAT, O_RDONLY, O_TRUNC, O_WRONLY, dirent, mode_t};
77
use std::fs::File;
@@ -184,7 +184,7 @@ impl Directory {
184184

185185
fn path_at(&self, name: &Utf8CStr, buf: &mut dyn Utf8CStrBuf) -> OsResult<'static, ()> {
186186
self.path(buf)?;
187-
FsPathBuf::from(buf).join(name);
187+
buf.append_path(name);
188188
Ok(())
189189
}
190190
}
@@ -247,14 +247,14 @@ impl Directory {
247247
}
248248

249249
pub fn get_attr_at<'a>(&self, name: &'a Utf8CStr) -> OsResult<'a, FileAttr> {
250-
let mut path = FsPathBuf::default();
251-
self.path_at(name, path.0.deref_mut())?;
250+
let mut path = cstr::buf::default();
251+
self.path_at(name, &mut path)?;
252252
path.get_attr().map_err(|e| e.set_args(Some(name), None))
253253
}
254254

255255
pub fn set_attr_at<'a>(&self, name: &'a Utf8CStr, attr: &FileAttr) -> OsResult<'a, ()> {
256-
let mut path = FsPathBuf::default();
257-
self.path_at(name, path.0.deref_mut())?;
256+
let mut path = cstr::buf::default();
257+
self.path_at(name, &mut path)?;
258258
path.set_attr(attr)
259259
.map_err(|e| e.set_args(Some(name), None))
260260
}
@@ -264,15 +264,15 @@ impl Directory {
264264
name: &'a Utf8CStr,
265265
con: &mut dyn Utf8CStrBuf,
266266
) -> OsResult<'a, ()> {
267-
let mut path = FsPathBuf::default();
268-
self.path_at(name, path.0.deref_mut())?;
267+
let mut path = cstr::buf::default();
268+
self.path_at(name, &mut path)?;
269269
path.get_secontext(con)
270270
.map_err(|e| e.set_args(Some(name), None))
271271
}
272272

273273
pub fn set_secontext_at<'a>(&self, name: &'a Utf8CStr, con: &'a Utf8CStr) -> OsResult<'a, ()> {
274-
let mut path = FsPathBuf::default();
275-
self.path_at(name, path.0.deref_mut())?;
274+
let mut path = cstr::buf::default();
275+
self.path_at(name, &mut path)?;
276276
path.set_secontext(con)
277277
.map_err(|e| e.set_args(Some(name), Some(con)))
278278
}
@@ -344,7 +344,7 @@ impl Directory {
344344
std::io::copy(&mut src, &mut dest)?;
345345
fd_set_attr(dest.as_raw_fd(), &attr)?;
346346
} else if e.is_symlink() {
347-
let mut target = cstr_buf::default();
347+
let mut target = cstr::buf::default();
348348
e.read_link(&mut target)?;
349349
unsafe {
350350
libc::symlinkat(target.as_ptr(), dir.as_raw_fd(), e.d_name.as_ptr())

0 commit comments

Comments
 (0)