mirror of https://github.com/zkat/cacache-rs.git
feat(chown): stop changing owner/group on unix platforms
Fixes: #16 BREAKING CHANGE: If you were relying on the chown functionality for the index (which you probably weren't), then your index will no longer be updated that way.
This commit is contained in:
parent
864c9314b3
commit
d5bb0dffb6
|
|
@ -160,14 +160,11 @@ dependencies = [
|
|||
"anyhow 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"async-attributes 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"async-std 0.99.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"chownr 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"criterion 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mkdirp 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
@ -184,25 +181,11 @@ name = "cast"
|
|||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "chownr"
|
||||
version = "3.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"anyhow 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "2.33.0"
|
||||
|
|
@ -573,11 +556,6 @@ dependencies = [
|
|||
"ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mkdirp"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "net2"
|
||||
version = "0.2.33"
|
||||
|
|
@ -588,18 +566,6 @@ dependencies = [
|
|||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.14.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nodrop"
|
||||
version = "0.1.14"
|
||||
|
|
@ -983,11 +949,6 @@ name = "unicode-xid"
|
|||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "void"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.2.9"
|
||||
|
|
@ -1068,9 +1029,7 @@ dependencies = [
|
|||
"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
|
||||
"checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101"
|
||||
"checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427"
|
||||
"checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be"
|
||||
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
"checksum chownr 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97905cd65d78952ee4c11e51060b126a2f71e33d4cee0d0574e9381e0e0f0ccb"
|
||||
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
|
||||
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
|
||||
"checksum criterion 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0363053954f3e679645fc443321ca128b7b950a6fe288cf5f9335cc22ee58394"
|
||||
|
|
@ -1113,9 +1072,7 @@ dependencies = [
|
|||
"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23"
|
||||
"checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125"
|
||||
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
|
||||
"checksum mkdirp 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "864e1de64c29b386d2dc7822aea156a7e4d45d4393ac748878dc21c9c41037f0"
|
||||
"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88"
|
||||
"checksum nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6c722bee1037d430d0f8e687bbdbf222f27cc6e4e68d5caf630857bb2b6dbdce"
|
||||
"checksum nodrop 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
|
||||
"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32"
|
||||
"checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273"
|
||||
|
|
@ -1163,7 +1120,6 @@ dependencies = [
|
|||
"checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9"
|
||||
"checksum unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20"
|
||||
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
||||
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
||||
"checksum walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9658c94fa8b940eab2250bd5a457f9c48b748420d71293b165c8cdbe2f55f71e"
|
||||
"checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d"
|
||||
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
||||
|
|
|
|||
|
|
@ -28,16 +28,11 @@ serde = "1.0.92"
|
|||
serde_derive = "1.0.92"
|
||||
walkdir = "2.2.7"
|
||||
either = "1.5.2"
|
||||
mkdirp = "1.0.0"
|
||||
futures-preview = "0.3.0-alpha.18"
|
||||
async-std = { version = "0.99.10", features = ["unstable"]}
|
||||
anyhow = "1.0.16"
|
||||
thiserror = "1.0.3"
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
chownr = "3.0.0"
|
||||
nix = "0.14.0"
|
||||
|
||||
[dev-dependencies]
|
||||
async-attributes = "1.0.0"
|
||||
criterion = "0.2.11"
|
||||
|
|
|
|||
66
src/index.rs
66
src/index.rs
|
|
@ -6,14 +6,11 @@ use std::path::{Path, PathBuf};
|
|||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use async_std::{fs as afs, task};
|
||||
#[cfg(unix)]
|
||||
use chownr;
|
||||
use async_std::fs as afs;
|
||||
use digest::Digest;
|
||||
use either::{Left, Right};
|
||||
use futures::io::AsyncWriteExt;
|
||||
use hex;
|
||||
use mkdirp;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
use sha1::Sha1;
|
||||
|
|
@ -65,20 +62,7 @@ impl Hash for SerializableMetadata {
|
|||
|
||||
pub fn insert(cache: &Path, key: &str, opts: WriteOpts) -> Result<Integrity> {
|
||||
let bucket = bucket_path(&cache, &key);
|
||||
#[cfg(unix)]
|
||||
{
|
||||
if let Some(path) = mkdirp::mkdirp(bucket.parent().unwrap()).with_context(|| {
|
||||
format!(
|
||||
"Failed to create index bucket directory: {:?}",
|
||||
bucket.parent().unwrap()
|
||||
)
|
||||
})? {
|
||||
chownr::chownr(&path, opts.uid, opts.gid)
|
||||
.with_context(|| format!("Failed to chown new index directories: {:?}", path))?;
|
||||
}
|
||||
}
|
||||
#[cfg(windows)]
|
||||
mkdirp::mkdirp(bucket.parent().unwrap()).with_context(|| {
|
||||
fs::create_dir_all(bucket.parent().unwrap()).with_context(|| {
|
||||
format!(
|
||||
"Failed to create index bucket directory: {:?}",
|
||||
bucket.parent().unwrap()
|
||||
|
|
@ -103,9 +87,6 @@ pub fn insert(cache: &Path, key: &str, opts: WriteOpts) -> Result<Integrity> {
|
|||
buck.write_all(out.as_bytes())
|
||||
.with_context(|| format!("Failed to write to index bucket at {:?}", bucket))?;
|
||||
buck.flush()?;
|
||||
#[cfg(unix)]
|
||||
chownr::chownr(&bucket, opts.uid, opts.gid)
|
||||
.with_context(|| format!("Failed to chown index bucket at {:?}", bucket))?;
|
||||
Ok(opts
|
||||
.sri
|
||||
.or_else(|| "sha1-deadbeef".parse::<Integrity>().ok())
|
||||
|
|
@ -114,30 +95,12 @@ pub fn insert(cache: &Path, key: &str, opts: WriteOpts) -> Result<Integrity> {
|
|||
|
||||
pub async fn insert_async<'a>(cache: &'a Path, key: &'a str, opts: WriteOpts) -> Result<Integrity> {
|
||||
let bucket = bucket_path(&cache, &key);
|
||||
let tmpbucket = bucket.clone();
|
||||
#[cfg(unix)]
|
||||
let WriteOpts { uid, gid, .. } = opts;
|
||||
task::spawn_blocking(move || {
|
||||
let parent = tmpbucket.parent().unwrap();
|
||||
#[cfg(unix)]
|
||||
{
|
||||
if let Some(path) = mkdirp::mkdirp(parent).with_context(|| {
|
||||
format!("failed to create index bucket parent dir: {:?}", parent)
|
||||
})? {
|
||||
chownr::chownr(&path, uid, gid).with_context(|| {
|
||||
format!(
|
||||
"failed to change ownership for path {:?} to {:?}:{:?}",
|
||||
path, uid, gid
|
||||
)
|
||||
})?;
|
||||
}
|
||||
}
|
||||
#[cfg(windows)]
|
||||
mkdirp::mkdirp(parent)
|
||||
.with_context(|| format!("failed to create index bucket parent dir: {:?}", parent))?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
})
|
||||
.await?;
|
||||
afs::create_dir_all(bucket.parent().unwrap()).await.with_context(|| {
|
||||
format!(
|
||||
"Failed to create index bucket directory: {:?}",
|
||||
bucket.parent().unwrap()
|
||||
)
|
||||
})?;
|
||||
let stringified = serde_json::to_string(&SerializableMetadata {
|
||||
key: key.to_owned(),
|
||||
integrity: opts.sri.clone().map(|x| x.to_string()),
|
||||
|
|
@ -159,9 +122,6 @@ pub async fn insert_async<'a>(cache: &'a Path, key: &'a str, opts: WriteOpts) ->
|
|||
.await
|
||||
.with_context(|| format!("Failed to write to index bucket at {:?}", bucket))?;
|
||||
buck.flush().await?;
|
||||
#[cfg(unix)]
|
||||
chownr::chownr(&bucket, opts.uid, opts.gid)
|
||||
.with_context(|| format!("Failed to chown index bucket at {:?}", bucket))?;
|
||||
Ok(opts
|
||||
.sri
|
||||
.or_else(|| "sha1-deadbeef".parse::<Integrity>().ok())
|
||||
|
|
@ -235,10 +195,6 @@ pub fn delete(cache: &Path, key: &str) -> Result<()> {
|
|||
sri: None,
|
||||
time: None,
|
||||
metadata: None,
|
||||
#[cfg(unix)]
|
||||
uid: None,
|
||||
#[cfg(unix)]
|
||||
gid: None,
|
||||
},
|
||||
)
|
||||
.map(|_| ())
|
||||
|
|
@ -254,10 +210,6 @@ pub async fn delete_async(cache: &Path, key: &str) -> Result<()> {
|
|||
sri: None,
|
||||
time: None,
|
||||
metadata: None,
|
||||
#[cfg(unix)]
|
||||
uid: None,
|
||||
#[cfg(unix)]
|
||||
gid: None,
|
||||
},
|
||||
)
|
||||
.map(|_| ())
|
||||
|
|
@ -423,7 +375,7 @@ mod tests {
|
|||
let sri: Integrity = "sha1-deadbeef".parse().unwrap();
|
||||
let time = 1_234_567;
|
||||
let bucket = bucket_path(&dir, "hello");
|
||||
mkdirp::mkdirp(bucket.parent().unwrap()).unwrap();
|
||||
fs::create_dir_all(bucket.parent().unwrap()).unwrap();
|
||||
fs::write(bucket, MOCK_ENTRY).unwrap();
|
||||
let entry = find(&dir, "hello").unwrap().unwrap();
|
||||
assert_eq!(
|
||||
|
|
|
|||
15
src/put.rs
15
src/put.rs
|
|
@ -6,8 +6,6 @@ use std::pin::Pin;
|
|||
use futures::prelude::*;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
#[cfg(unix)]
|
||||
use nix::unistd::{Gid, Uid};
|
||||
use serde_json::Value;
|
||||
use ssri::{Algorithm, Integrity};
|
||||
|
||||
|
|
@ -202,10 +200,6 @@ pub struct WriteOpts {
|
|||
pub(crate) size: Option<usize>,
|
||||
pub(crate) time: Option<u128>,
|
||||
pub(crate) metadata: Option<Value>,
|
||||
#[cfg(unix)]
|
||||
pub(crate) uid: Option<Uid>,
|
||||
#[cfg(unix)]
|
||||
pub(crate) gid: Option<Gid>,
|
||||
}
|
||||
|
||||
impl WriteOpts {
|
||||
|
|
@ -285,15 +279,6 @@ impl WriteOpts {
|
|||
self.sri = Some(sri);
|
||||
self
|
||||
}
|
||||
|
||||
/// Configures the uid and gid to write data as. Useful when dropping
|
||||
/// privileges while in `sudo` mode.
|
||||
#[cfg(unix)]
|
||||
pub fn chown(mut self, uid: Option<Uid>, gid: Option<Gid>) -> Self {
|
||||
self.uid = uid;
|
||||
self.gid = gid;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// A reference to an open file writing to the cache.
|
||||
|
|
|
|||
Loading…
Reference in New Issue