diff --git a/CHANGELOG.md b/CHANGELOG.md
index e186d94630..78cd97158b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -52,6 +52,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Removed `sys::socket::addr::from_libc_sockaddr` from the public API.
(#[1215](https://github.com/nix-rust/nix/pull/1215))
+- Nix no longer implements `NixPath` for `Option
where P: NixPath`. Most
+ Nix functions that accept `NixPath` arguments can't do anything useful with
+ `None`. The exceptions (`mount` and `quotactl_sync`) already take explicitly
+ optional arguments.
+ (#[1242](https://github.com/nix-rust/nix/pull/1242))
+
## [0.17.0] - 3 February 2020
### Added
- Add `CLK_TCK` to `SysconfVar`
diff --git a/src/lib.rs b/src/lib.rs
index 0ba7ace88c..51751f9e6e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -283,22 +283,3 @@ impl NixPath for PathBuf {
self.as_os_str().with_nix_path(f)
}
}
-
-/// Treats `None` as an empty string.
-impl<'a, NP: ?Sized + NixPath> NixPath for Option<&'a NP> {
- fn is_empty(&self) -> bool {
- self.map_or(true, NixPath::is_empty)
- }
-
- fn len(&self) -> usize {
- self.map_or(0, NixPath::len)
- }
-
- fn with_nix_path(&self, f: F) -> Result where F: FnOnce(&CStr) -> T {
- if let Some(nix_path) = *self {
- nix_path.with_nix_path(f)
- } else {
- unsafe { CStr::from_ptr("\0".as_ptr() as *const _).with_nix_path(f) }
- }
- }
-}
diff --git a/src/mount.rs b/src/mount.rs
index a9902b170a..b889911305 100644
--- a/src/mount.rs
+++ b/src/mount.rs
@@ -61,22 +61,33 @@ pub fn mount) -> Result<()> {
- let res =
- source.with_nix_path(|source| {
- target.with_nix_path(|target| {
- fstype.with_nix_path(|fstype| {
- data.with_nix_path(|data| {
- unsafe {
- libc::mount(source.as_ptr(),
- target.as_ptr(),
- fstype.as_ptr(),
- flags.bits,
- data.as_ptr() as *const libc::c_void)
- }
- })
+ fn with_opt_nix_path(p: Option<&P>, f: F) -> Result
+ where P: ?Sized + NixPath,
+ F: FnOnce(*const libc::c_char) -> T
+ {
+ match p {
+ Some(path) => path.with_nix_path(|p_str| f(p_str.as_ptr())),
+ None => Ok(f(std::ptr::null()))
+ }
+ }
+
+ let res = with_opt_nix_path(source, |s| {
+ target.with_nix_path(|t| {
+ with_opt_nix_path(fstype, |ty| {
+ with_opt_nix_path(data, |d| {
+ unsafe {
+ libc::mount(
+ s,
+ t.as_ptr(),
+ ty,
+ flags.bits,
+ d as *const libc::c_void
+ )
+ }
})
})
- })????;
+ })
+ })????;
Errno::result(res).map(drop)
}
diff --git a/src/sys/quota.rs b/src/sys/quota.rs
index b056c84d73..db97b0e765 100644
--- a/src/sys/quota.rs
+++ b/src/sys/quota.rs
@@ -253,6 +253,8 @@ pub fn quotactl_off(which: QuotaType, special: &P) -> Resul
}
/// Update the on-disk copy of quota usages for a filesystem.
+///
+/// If `special` is `None`, then all file systems with active quotas are sync'd.
pub fn quotactl_sync(which: QuotaType, special: Option<&P>) -> Result<()> {
quotactl(QuotaCmd(QuotaSubCmd::Q_SYNC, which), special, 0, ptr::null_mut())
}