From 240a5c85cb23430400bad9be9f15a9313e314195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saugat=20Pachhai=20=28=E0=A4=B8=E0=A5=8C=E0=A4=97=E0=A4=BE?= =?UTF-8?q?=E0=A4=A4=29?= Date: Mon, 19 Feb 2024 18:18:31 +0545 Subject: [PATCH] windows support --- .github/workflows/ci.yml | 5 ++++- Cargo.lock | 2 +- Cargo.toml | 4 +++- src/repo.rs | 28 ++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ffae1ef..9aa8632 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,10 @@ env: jobs: ci: name: Check - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] steps: - uses: actions/checkout@v4 - uses: actions-rust-lang/setup-rust-toolchain@v1 diff --git a/Cargo.lock b/Cargo.lock index 8ad0003..d7daadc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -426,7 +426,7 @@ dependencies = [ [[package]] name = "dvc-data" -version = "0.1.0" +version = "0.1.1" dependencies = [ "base16ct", "clap", diff --git a/Cargo.toml b/Cargo.toml index 37c00a0..bb756ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,12 +33,14 @@ ignore = "0.4.22" itertools = "0.12.1" env_logger = "0.11.2" log = "0.4.20" -uzers = "0.11.3" config = "0.14.0" serde_derive = "1.0.196" directories = "5.0.1" git2 = { version = "0.18.2", default-features = false } +[target.'cfg(unix)'.dependencies] +uzers = "0.11.3" + [dev-dependencies] tempfile = "3.10.0" diff --git a/src/repo.rs b/src/repo.rs index bc40c79..98c5660 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -63,6 +63,29 @@ fn db_dirname(root: &Path, tmp_dir: &Path) -> String { md5(&mut st.as_bytes()) } +#[cfg(windows)] +fn db_dirname(root: &Path, tmp_dir: &Path) -> String { + use std::os::unix::ffi::OsStrExt; + let btime = btime(tmp_dir).unwrap(); + let user = uzers::get_current_username().unwrap(); + let dvc_major = 3; + let salt = 2; + + let mut st: OsString = "('".into(); + st.push(root.as_os_str()); + st.push("', "); + st.push(btime.to_string()); + st.push(", '"); + st.push(user); + st.push("', "); + st.push(dvc_major.to_string()); + st.push(", "); + st.push(salt.to_string()); + st.push(")"); + + md5(&mut st.as_bytes()) +} + #[cfg(not(any( target_os = "windows", target_os = "macos", @@ -73,6 +96,11 @@ fn db_dirs() -> PathBuf { "/var/tmp/dvc/repo".into() } +#[cfg(target_os = "windows")] +fn db_dirs() -> PathBuf { + Path::new(env::var("CSIDL_COMMON_APPDATA").or_else("C:/ProgramData/iterative/dvc")).to_owned() +} + #[cfg(target_os = "macos")] fn db_dirs() -> PathBuf { "/Library/Caches/dvc/repo".into()