@@ -18,91 +18,5 @@ mod impls {
18
18
}
19
19
}
20
20
21
- pub mod init {
22
- #![ allow( unused) ]
23
-
24
- use std:: path:: { Path , PathBuf } ;
25
-
26
- use memmap2:: Mmap ;
27
-
28
- use crate :: { decode, extension, File , State } ;
29
-
30
- mod error {
31
- use quick_error:: quick_error;
32
-
33
- quick_error ! {
34
- #[ derive( Debug ) ]
35
- pub enum Error {
36
- Io ( err: std:: io:: Error ) {
37
- display( "An IO error occurred while opening the index" )
38
- source( err)
39
- from( )
40
- }
41
- Decode ( err: crate :: decode:: Error ) {
42
- display( "The file could not be decoded" )
43
- source( err)
44
- from( )
45
- }
46
- }
47
- }
48
- }
49
- pub use error:: Error ;
50
-
51
- impl File {
52
- pub fn at ( path : impl Into < PathBuf > , options : decode:: Options ) -> Result < Self , Error > {
53
- let path = path. into ( ) ;
54
- let ( data, mtime) = {
55
- // SAFETY: we have to take the risk of somebody changing the file underneath. Git never writes into the same file.
56
- let file = std:: fs:: File :: open ( & path) ?;
57
- #[ allow( unsafe_code) ]
58
- let data = unsafe { Mmap :: map ( & file) ? } ;
59
- ( data, filetime:: FileTime :: from_last_modification_time ( & file. metadata ( ) ?) )
60
- } ;
61
-
62
- let ( state, checksum) = State :: from_bytes ( & data, mtime, options) ?;
63
- Ok ( File { state, path, checksum } )
64
- }
65
- }
66
- }
67
-
68
- mod verify {
69
- use crate :: File ;
70
- use std:: sync:: atomic:: AtomicBool ;
71
-
72
- pub mod error {
73
- use quick_error:: quick_error;
74
-
75
- quick_error ! {
76
- #[ derive( Debug ) ]
77
- pub enum Error {
78
- Io ( err: std:: io:: Error ) {
79
- display( "Could not read index file to generate hash" )
80
- source( err)
81
- from( )
82
- }
83
- ChecksumMismatch { actual: git_hash:: ObjectId , expected: git_hash:: ObjectId } {
84
- display( "Index checksum should have been {}, but was {}" , expected, actual)
85
- }
86
- }
87
- }
88
- }
89
- pub use error:: Error ;
90
-
91
- impl File {
92
- pub fn verify_integrity ( & self ) -> Result < ( ) , Error > {
93
- let num_bytes_to_hash = self . path . metadata ( ) ?. len ( ) - self . checksum . as_bytes ( ) . len ( ) as u64 ;
94
- let should_interrupt = AtomicBool :: new ( false ) ;
95
- let actual = git_features:: hash:: bytes_of_file (
96
- & self . path ,
97
- num_bytes_to_hash as usize ,
98
- self . checksum . kind ( ) ,
99
- & mut git_features:: progress:: Discard ,
100
- & should_interrupt,
101
- ) ?;
102
- ( actual == self . checksum ) . then ( || ( ) ) . ok_or ( Error :: ChecksumMismatch {
103
- actual,
104
- expected : self . checksum ,
105
- } )
106
- }
107
- }
108
- }
21
+ pub mod init;
22
+ pub mod verify;
0 commit comments