1 //! Tests for corrupt git repos.
4 use std
::path
::{Path, PathBuf}
;
6 use cargo
::util
::paths
as cargopaths
;
7 use cargo_test_support
::paths
;
8 use cargo_test_support
::{basic_manifest, git, project}
;
11 fn deleting_database_files() {
12 let project
= project();
13 let git_project
= git
::new("bar", |project
| {
15 .file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
16 .file("src/lib.rs", "")
30 bar = {{ git = '{}' }}
35 .file("src/lib.rs", "")
38 project
.cargo("build").run();
40 let mut files
= Vec
::new();
41 find_files(&paths
::home().join(".cargo/git/db"), &mut files
);
42 assert
!(!files
.is_empty());
44 let log
= "cargo::sources::git=trace";
49 println
!("deleting {}", file
.display());
50 cargopaths
::remove_file(&file
).unwrap();
51 project
.cargo("build -v").env("CARGO_LOG", log
).run();
56 println
!("truncating {}", file
.display());
58 fs
::OpenOptions
::new()
64 project
.cargo("build -v").env("CARGO_LOG", log
).run();
69 fn deleting_checkout_files() {
70 let project
= project();
71 let git_project
= git
::new("bar", |project
| {
73 .file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
74 .file("src/lib.rs", "")
88 bar = {{ git = '{}' }}
93 .file("src/lib.rs", "")
96 project
.cargo("build").run();
98 let dir
= paths
::home()
99 .join(".cargo/git/checkouts")
100 // get the first entry in the checkouts dir for the package's location
107 // get the first child of that checkout dir for our checkout
114 // and throw on .git to corrupt things
116 let mut files
= Vec
::new();
117 find_files(&dir
, &mut files
);
118 assert
!(!files
.is_empty());
120 let log
= "cargo::sources::git=trace";
125 println
!("deleting {}", file
.display());
126 cargopaths
::remove_file(&file
).unwrap();
127 project
.cargo("build -v").env("CARGO_LOG", log
).run();
132 println
!("truncating {}", file
.display());
133 make_writable(&file
);
134 fs
::OpenOptions
::new()
140 project
.cargo("build -v").env("CARGO_LOG", log
).run();
144 fn make_writable(path
: &Path
) {
145 let mut p
= path
.metadata().unwrap().permissions();
146 p
.set_readonly(false);
147 fs
::set_permissions(path
, p
).unwrap();
150 fn find_files(path
: &Path
, dst
: &mut Vec
<PathBuf
>) {
151 for e
in path
.read_dir().unwrap() {
154 if e
.file_type().unwrap().is_dir() {
155 find_files(&path
, dst
);