diff --git a/Cargo.lock b/Cargo.lock index c7958537e8f..9c0bbac9422 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -127,7 +127,7 @@ dependencies = [ "ammonia 1.0.0-rc2 (git+https://github.com/notriddle/ammonia?rev=3d4e4073f8cdb7c60203b9036c09f4385a2fdbbd)", "cargo-registry-s3 0.2.0", "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "civet 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "civet 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "clippy 0.0.162 (registry+https://github.com/rust-lang/crates.io-index)", "comrak 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "conduit 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -173,6 +173,7 @@ dependencies = [ "tokio-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "uuid 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -211,10 +212,10 @@ dependencies = [ [[package]] name = "civet" -version = "0.9.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "civet-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "civet-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "conduit 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -222,8 +223,11 @@ dependencies = [ [[package]] name = "civet-sys" -version = "0.1.4" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cmake 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "clippy" @@ -1809,6 +1813,14 @@ dependencies = [ "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "uuid" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "vcpkg" version = "0.2.2" @@ -1865,8 +1877,8 @@ dependencies = [ "checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" "checksum chrono 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "158b0bd7d75cbb6bf9c25967a48a2e9f77da95876b858eadfabaa99cd069de6e" "checksum chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c20ebe0b2b08b0aeddba49c609fe7957ba2e33449882cb186a180bc60682fa9" -"checksum civet 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6263e7af767a5bf9e4d3d0a6c3ceb5f3940ec85cf2fbfee59024b8a264be180f" -"checksum civet-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "958d15372bf28b7983cb35e1d4bf36dd843b0d42e507c1c73aad7150372c5936" +"checksum civet 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18dff78a41c25c2dda49df09557738720e1aec35915e2416131562089fb93221" +"checksum civet-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d052aa9df6fb053a714736c3625508f3710e8cf08a10aafc2f8f2be97926d8c7" "checksum clippy 0.0.162 (registry+https://github.com/rust-lang/crates.io-index)" = "fcdb42cab913b8eb5d390ba612400ec581813fb59af29afd39333d7a550f332c" "checksum clippy_lints 0.0.162 (registry+https://github.com/rust-lang/crates.io-index)" = "b1c0da7936c88883ac09bc3b29584c275551eff961b2d0d87a22b60205088e55" "checksum cmake 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "0c8a6541a55bcd72d3de4faee2d101a5a66df29790282c7f797082a7228a9b3d" @@ -2052,6 +2064,7 @@ dependencies = [ "checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f" "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" "checksum uuid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7cfec50b0842181ba6e713151b72f4ec84a6a7e2c9c8a8a3ffc37bb1cd16b231" +"checksum uuid 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcc7e3b898aa6f6c08e5295b6c89258d1331e9ac578cc992fb818759951bdc22" "checksum vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e0a7d8bed3178a8fb112199d466eeca9ed09a14ba8ad67718179b4fd5487d0b" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" diff --git a/Cargo.toml b/Cargo.toml index f237f244699..09c5d5ab255 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,7 +71,7 @@ conduit-middleware = "0.8" conduit-router = "0.8" conduit-static = "0.8" conduit-git-http-backend = "0.8" -civet = "0.9" +civet = "0.10" [dev-dependencies] conduit-test = "0.8" @@ -80,6 +80,7 @@ hyper-tls = "0.1" futures = "0.1" tokio-core = "0.1" tokio-service = "0.1" +uuid = { version = "0.5", features = ["v4"] } [build-dependencies] dotenv = "0.10" diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000000..aae5f9beb3f --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,51 @@ +version: '0.1.{build}' + +platform: x64 + +services: + - postgresql96 + +environment: + global: + PGUSER: postgres + PGPASSWORD: Password12! + OPENSSL_VERSION: 1_1_0f + OPENSSL_DIR: "c:\\openssl" + SSL_CERT_FILE: "c:\\openssl\\cacert.pem" + TEST_DATABASE_URL: "postgres://postgres:Password12!@localhost/cargo_registry_test" + + matrix: + - APPVEYOR_RUST_CHANNEL: stable + - APPVEYOR_RUST_CHANNEL: beta + - APPVEYOR_RUST_CHANNEL: nightly + +matrix: + allow_failures: + - APPVEYOR_RUST_CHANNEL: nightly + +install: + # Install OpenSSL + - mkdir c:\openssl + - ps: Start-FileDownload "http://slproweb.com/download/Win64OpenSSL-${env:OPENSSL_VERSION}.exe" + - Win64OpenSSL-%OPENSSL_VERSION%.exe /SILENT /VERYSILENT /SP- /DIR="C:\openssl" + - appveyor DownloadFile https://curl.haxx.se/ca/cacert.pem -FileName c:\openssl\cacert.pem + # Install rust and cargo + - appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe + - rustup-init.exe -y --default-host x86_64-pc-windows-msvc --default-toolchain %APPVEYOR_RUST_CHANNEL% + - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin + # Debug information + - rustc -V + - cargo -V + +build: false + +before_test: + # Setup test database + - set PATH=%PATH%;C:\Program Files\PostgreSQL\9.6\bin + - createdb cargo_registry_test + +test_script: + - cargo test + +cache: + - C:\Users\appveyor\.cargo\registry -> Cargo.lock diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index e328727877f..f3f155d9054 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -26,7 +26,7 @@ like to see all new types and functions, public and private, to have documentati comments on them. If you change an existing type or function, and it doesn't have a documentation comment on it, it'd be great if you could add one to it too. -When you submit a pull request, it will be automatically tested on TravisCI. In +When you submit a pull request, it will be automatically tested on TravisCI and Appveyor. In addition to running both the frontend and the backend tests described below, Travis runs [jslint], [clippy], and [rustfmt] on each PR. @@ -312,12 +312,18 @@ diesel migration run ##### Setting up the git index -Set up the git repo for the crate index by running: +If you're running Linux or macOS, you can set up the git repo for the crate index by running: ``` ./script/init-local-index.sh ``` +If you're running Windows, you can set up the git repo for the crate index by running the following command in PowerShell: + +``` +.\script\init-local-index.ps1 +``` + ##### Starting the server and the frontend Build and start the server by running this command (you'll need to stop this diff --git a/script/init-local-index.ps1 b/script/init-local-index.ps1 new file mode 100644 index 00000000000..6a073c7a28b --- /dev/null +++ b/script/init-local-index.ps1 @@ -0,0 +1,35 @@ +if (Test-Path -Path ".\tmp\index-bare") { + Write-Host "tmp\index-bare already exists, exiting" + exit +} + +New-Item -Path "." -Name "tmp" -ItemType "directory" -Force 2>&1 | out-null +Remove-Item -Path ".\tmp\index-bare" -Recurse -Force 2>&1 | out-null +Remove-Item -Path ".\tmp\index-co" -Recurse -Force 2>&1 | out-null + +Write-Host "Initializing repository in tmp\index-bare..." +git init -q --bare ".\tmp\index-bare" + +Write-Host "Creating checkout in tmp/index-bare..." +git init -q ".\tmp\index-co" +Set-Location ".\tmp\index-co" + +New-Item -Path "." -Name "config.json" -ItemType "file" -Value @' +{ + "dl": "http://localhost:8888/api/v1/crates", + "api": "http://localhost:8888/" +} +'@ 2>&1 | out-null +git add config.json 2>&1 | out-null +git commit -qm "Initial commit" 2>&1 | out-null +$origin = [string]::Format("file:///{0}/../index-bare", (Get-Location)) +git remote add origin $origin 2>&1 | out-null +git push -q origin master -u 2>&1 | out-null +Set-Location ..\.. +New-Item -Path "tmp\index-co\.git" -Name "git-daemon-export-ok" -ItemType "file" 2>&1 | out-null + +Write-Host @' +Your local git index is ready to go! + +Please refer to https://github.com/rust-lang/crates.io/blob/master/README.md for more info! +'@ diff --git a/src/tests/all.rs b/src/tests/all.rs index 6f4f924556e..659fa677a4c 100644 --- a/src/tests/all.rs +++ b/src/tests/all.rs @@ -21,6 +21,7 @@ extern crate serde_derive; extern crate serde_json; extern crate tar; extern crate url; +extern crate uuid; use std::borrow::Cow; use std::collections::HashMap; diff --git a/src/tests/git.rs b/src/tests/git.rs index 9ae8bc8cfcf..15d9381f42a 100644 --- a/src/tests/git.rs +++ b/src/tests/git.rs @@ -1,17 +1,18 @@ -use std::fs; use std::env; +use std::fs; +use std::io; +use std::path::{Path, PathBuf}; use std::thread; -use std::path::PathBuf; -use std::sync::{Once, ONCE_INIT}; use git2; use url::Url; +use uuid::Uuid; fn root() -> PathBuf { env::current_dir() .unwrap() .join("tmp") - .join(thread::current().name().unwrap()) + .join(thread::current().name().unwrap().replace("::", "_")) } pub fn checkout() -> PathBuf { @@ -21,14 +22,60 @@ pub fn bare() -> PathBuf { root().join("bare") } -pub fn init() { - static INIT: Once = ONCE_INIT; - let _ = fs::remove_dir_all(&checkout()); - let _ = fs::remove_dir_all(&bare()); +#[cfg(target_os = "windows")] +fn remove_dir_all(path: &Path) -> Result<(), io::Error> { + fn rename_temp(path: &Path) -> Result { + let temp_name = Uuid::new_v4().hyphenated().to_string(); + let temp_path = env::temp_dir().join(temp_name); + fs::rename(path, &temp_path)?; + Ok(temp_path) + } + + fn remove_file(path: &Path) -> Result<(), io::Error> { + let temp_path = rename_temp(path)?; + fs::remove_file(&temp_path) + } + + fn remove_dir(path: &Path) -> Result<(), io::Error> { + let temp_path = rename_temp(path)?; + fs::remove_dir(&temp_path) + } + + for cursor in fs::read_dir(path)? { + let entry = cursor?; + let file_type = entry.file_type()?; + if file_type.is_dir() { + remove_dir_all(&entry.path())?; + } else { + let mut permissions = entry.metadata()?.permissions(); + if permissions.readonly() { + permissions.set_readonly(false); + fs::set_permissions(entry.path(), permissions)?; + } + remove_file(&entry.path())?; + } + } + remove_dir(path) +} - INIT.call_once(|| { - fs::create_dir_all(root().parent().unwrap()).unwrap(); - }); +#[cfg(not(target_os = "windows"))] +fn remove_dir_all(path: &Path) -> Result<(), io::Error> { + fs::remove_dir_all(path) +} + +pub fn init() { + if let Err(e) = remove_dir_all(&checkout()) { + println!("Errored: {:?}", e); + } + if let Err(e) = remove_dir_all(&bare()) { + println!("Errored: {:?}", e); + } + if let Err(e) = fs::create_dir_all(&checkout()) { + println!("Errored: {:?}", e); + } + if let Err(e) = fs::create_dir_all(&bare()) { + println!("Errored: {:?}", e); + } // Prepare a bare remote repo {