mirror of https://github.com/zkat/cacache-rs.git
fix(windows): add windows support
This commit is contained in:
parent
25a191887d
commit
97f44573d5
|
|
@ -12,6 +12,9 @@ jobs:
|
|||
os: [ubuntu-latest, windows-latest]
|
||||
|
||||
steps:
|
||||
- uses: hecrj/setup-rust-action@master
|
||||
with:
|
||||
rust-version: ${{ matrix.rust }}
|
||||
- uses: actions/checkout@v1
|
||||
- name: Components
|
||||
run: rustup component add clippy
|
||||
|
|
|
|||
|
|
@ -27,13 +27,15 @@ digest = "0.8.0"
|
|||
serde_json = "1.0.39"
|
||||
serde = "1.0.92"
|
||||
serde_derive = "1.0.92"
|
||||
nix = "0.14.0"
|
||||
chownr = "2.0.0"
|
||||
failure = "0.1.5"
|
||||
walkdir = "2.2.7"
|
||||
either = "1.5.2"
|
||||
mkdirp = "1.0.0"
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
chownr = "2.0.0"
|
||||
nix = "0.14.0"
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.2.11"
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ pub fn content_path(cache: &Path, sri: &Integrity) -> PathBuf {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::content_path;
|
||||
use super::*;
|
||||
use ssri::Integrity;
|
||||
use std::path::Path;
|
||||
|
||||
|
|
@ -30,9 +30,16 @@ mod tests {
|
|||
fn basic_test() {
|
||||
let sri = Integrity::from(b"hello world");
|
||||
let cpath = content_path(Path::new("~/.my-cache"), &sri);
|
||||
let mut wanted = PathBuf::new();
|
||||
wanted.push("~/.my-cache");
|
||||
wanted.push(format!("content-v{}", CONTENT_VERSION));
|
||||
wanted.push("sha256");
|
||||
wanted.push("b9");
|
||||
wanted.push("4d");
|
||||
wanted.push("27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9");
|
||||
assert_eq!(
|
||||
cpath.to_str().unwrap(),
|
||||
"~/.my-cache/content-v2/sha256/b9/4d/27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
|
||||
wanted.to_str().unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use std::io;
|
||||
|
||||
#[cfg(unix)]
|
||||
use chownr;
|
||||
use failure::Fail;
|
||||
use serde_json;
|
||||
|
|
@ -24,6 +25,7 @@ pub enum Error {
|
|||
Io(#[fail(cause)] io::Error),
|
||||
/// Returned when there's an error with changing uid/gid on an entry.
|
||||
#[fail(display = "{}", _0)]
|
||||
#[cfg(unix)]
|
||||
Chownr(#[fail(cause)] chownr::Error),
|
||||
/// Returned when there's an issue with metadata (de)serialization.
|
||||
#[fail(display = "{}", _0)]
|
||||
|
|
@ -44,6 +46,7 @@ impl From<std::io::Error> for Error {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
impl From<chownr::Error> for Error {
|
||||
fn from(error: chownr::Error) -> Self {
|
||||
Error::Chownr(error)
|
||||
|
|
|
|||
13
src/index.rs
13
src/index.rs
|
|
@ -5,6 +5,7 @@ use std::io::{ErrorKind, Write};
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
#[cfg(unix)]
|
||||
use chownr;
|
||||
use digest::Digest;
|
||||
use either::{Left, Right};
|
||||
|
|
@ -62,9 +63,14 @@ impl Hash for SerializableEntry {
|
|||
|
||||
pub fn insert(cache: &Path, key: &str, opts: PutOpts) -> Result<Integrity, Error> {
|
||||
let bucket = bucket_path(&cache, &key);
|
||||
if let Some(path) = mkdirp::mkdirp(bucket.parent().unwrap())? {
|
||||
chownr::chownr(&path, opts.uid, opts.gid)?;
|
||||
#[cfg(unix)]
|
||||
{
|
||||
if let Some(path) = mkdirp::mkdirp(bucket.parent().unwrap())? {
|
||||
chownr::chownr(&path, opts.uid, opts.gid)?;
|
||||
}
|
||||
}
|
||||
#[cfg(windows)]
|
||||
mkdirp::mkdirp(bucket.parent().unwrap())?;
|
||||
let stringified = serde_json::to_string(&SerializableEntry {
|
||||
key: key.to_owned(),
|
||||
integrity: opts.sri.clone().map(|x| x.to_string()),
|
||||
|
|
@ -76,6 +82,7 @@ pub fn insert(cache: &Path, key: &str, opts: PutOpts) -> Result<Integrity, Error
|
|||
let mut buck = OpenOptions::new().create(true).append(true).open(&bucket)?;
|
||||
|
||||
write!(buck, "\n{}\t{}", hash_entry(&stringified), stringified)?;
|
||||
#[cfg(unix)]
|
||||
chownr::chownr(&bucket, opts.uid, opts.gid)?;
|
||||
Ok(opts
|
||||
.sri
|
||||
|
|
@ -120,7 +127,9 @@ pub fn delete(cache: &Path, key: &str) -> Result<(), Error> {
|
|||
sri: None,
|
||||
time: None,
|
||||
metadata: None,
|
||||
#[cfg(unix)]
|
||||
uid: None,
|
||||
#[cfg(unix)]
|
||||
gid: None,
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
use std::io::prelude::*;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[cfg(unix)]
|
||||
use nix::unistd::{Gid, Uid};
|
||||
use serde_json::Value;
|
||||
use ssri::{Algorithm, Integrity};
|
||||
|
|
@ -32,7 +33,9 @@ pub struct PutOpts {
|
|||
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>,
|
||||
}
|
||||
|
||||
|
|
@ -97,6 +100,7 @@ impl PutOpts {
|
|||
|
||||
/// 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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue