@@ -13,18 +13,14 @@ use crate::archive::Archive;
13
13
use crate :: { HttpArchivePointer , LocalArchivePointer } ;
14
14
15
15
#[ derive( Debug , Clone ) ]
16
- pub struct CachedWheel {
16
+ pub struct ResolvedWheel {
17
17
/// The filename of the wheel.
18
18
pub filename : WheelFilename ,
19
19
/// The [`CacheEntry`] for the wheel.
20
20
pub entry : CacheEntry ,
21
- /// The [`HashDigest`]s for the wheel.
22
- pub hashes : HashDigests ,
23
- /// The [`CacheInfo`] for the wheel.
24
- pub cache_info : CacheInfo ,
25
21
}
26
22
27
- impl CachedWheel {
23
+ impl ResolvedWheel {
28
24
/// Try to parse a distribution from a cached directory name (like `typing-extensions-4.8.0-py3-none-any`).
29
25
pub fn from_built_source ( path : impl AsRef < Path > , cache : & Cache ) -> Option < Self > {
30
26
let path = path. as_ref ( ) ;
@@ -36,10 +32,79 @@ impl CachedWheel {
36
32
// Convert to a cached wheel.
37
33
let archive = cache. resolve_link ( path) . ok ( ) ?;
38
34
let entry = CacheEntry :: from_path ( archive) ;
39
- let hashes = HashDigests :: empty ( ) ;
40
- let cache_info = CacheInfo :: default ( ) ;
35
+ Some ( Self { filename, entry } )
36
+ }
37
+ }
38
+
39
+ #[ derive( Debug , Clone ) ]
40
+ pub struct CachedWheel {
41
+ /// The filename of the wheel.
42
+ pub filename : WheelFilename ,
43
+ /// The [`CacheEntry`] for the wheel.
44
+ pub entry : CacheEntry ,
45
+ /// The [`HashDigest`]s for the wheel.
46
+ pub hashes : HashDigests ,
47
+ /// The [`CacheInfo`] for the wheel.
48
+ pub cache_info : CacheInfo ,
49
+ }
50
+
51
+ impl CachedWheel {
52
+ /// Create a [`CachedWheel`] from a [`ResolvedWheel`].
53
+ pub fn from_entry ( wheel : ResolvedWheel , hashes : HashDigests , cache_info : CacheInfo ) -> Self {
54
+ Self {
55
+ filename : wheel. filename ,
56
+ entry : wheel. entry ,
57
+ hashes,
58
+ cache_info,
59
+ }
60
+ }
61
+
62
+ /// Read a cached wheel from a `.http` pointer
63
+ pub fn from_http_pointer ( path : impl AsRef < Path > , cache : & Cache ) -> Option < Self > {
64
+ let path = path. as_ref ( ) ;
65
+
66
+ // Read the pointer.
67
+ let pointer = HttpArchivePointer :: read_from ( path) . ok ( ) ??;
68
+ let cache_info = pointer. to_cache_info ( ) ;
69
+ let archive = pointer. into_archive ( ) ;
70
+
71
+ // Ignore stale pointers.
72
+ if !archive. exists ( cache) {
73
+ return None ;
74
+ }
75
+
76
+ let Archive { id, hashes, .. } = archive;
77
+ let entry = cache. entry ( CacheBucket :: Archive , "" , id) ;
78
+
79
+ // Convert to a cached wheel.
80
+ Some ( Self {
81
+ filename : archive. filename ,
82
+ entry,
83
+ hashes,
84
+ cache_info,
85
+ } )
86
+ }
87
+
88
+ /// Read a cached wheel from a `.rev` pointer
89
+ pub fn from_local_pointer ( path : impl AsRef < Path > , cache : & Cache ) -> Option < Self > {
90
+ let path = path. as_ref ( ) ;
91
+
92
+ // Read the pointer.
93
+ let pointer = LocalArchivePointer :: read_from ( path) . ok ( ) ??;
94
+ let cache_info = pointer. to_cache_info ( ) ;
95
+ let archive = pointer. into_archive ( ) ;
96
+
97
+ // Ignore stale pointers.
98
+ if !archive. exists ( cache) {
99
+ return None ;
100
+ }
101
+
102
+ let Archive { id, hashes, .. } = archive;
103
+ let entry = cache. entry ( CacheBucket :: Archive , "" , id) ;
104
+
105
+ // Convert to a cached wheel.
41
106
Some ( Self {
42
- filename,
107
+ filename : archive . filename ,
43
108
entry,
44
109
hashes,
45
110
cache_info,
@@ -115,64 +180,6 @@ impl CachedWheel {
115
180
cache_info : self . cache_info ,
116
181
}
117
182
}
118
-
119
- /// Read a cached wheel from a `.http` pointer
120
- pub fn from_http_pointer ( path : impl AsRef < Path > , cache : & Cache ) -> Option < Self > {
121
- let path = path. as_ref ( ) ;
122
-
123
- // Read the pointer.
124
- let pointer = HttpArchivePointer :: read_from ( path) . ok ( ) ??;
125
- let cache_info = pointer. to_cache_info ( ) ;
126
- let archive = pointer. into_archive ( ) ;
127
-
128
- // Ignore stale pointers.
129
- if !archive. exists ( cache) {
130
- return None ;
131
- }
132
-
133
- let Archive { id, hashes, .. } = archive;
134
- let entry = cache. entry ( CacheBucket :: Archive , "" , id) ;
135
-
136
- // Convert to a cached wheel.
137
- Some ( Self {
138
- filename : archive. filename ,
139
- entry,
140
- hashes,
141
- cache_info,
142
- } )
143
- }
144
-
145
- /// Read a cached wheel from a `.rev` pointer
146
- pub fn from_local_pointer ( path : impl AsRef < Path > , cache : & Cache ) -> Option < Self > {
147
- let path = path. as_ref ( ) ;
148
-
149
- // Read the pointer.
150
- let pointer = LocalArchivePointer :: read_from ( path) . ok ( ) ??;
151
- let cache_info = pointer. to_cache_info ( ) ;
152
- let archive = pointer. into_archive ( ) ;
153
-
154
- // Ignore stale pointers.
155
- if !archive. exists ( cache) {
156
- return None ;
157
- }
158
-
159
- let Archive { id, hashes, .. } = archive;
160
- let entry = cache. entry ( CacheBucket :: Archive , "" , id) ;
161
-
162
- // Convert to a cached wheel.
163
- Some ( Self {
164
- filename : archive. filename ,
165
- entry,
166
- hashes,
167
- cache_info,
168
- } )
169
- }
170
-
171
- #[ must_use]
172
- pub fn with_cache_info ( mut self , cache_info : CacheInfo ) -> Self {
173
- self . cache_info = cache_info;
174
- self
175
- }
176
183
}
177
184
178
185
impl Hashed for CachedWheel {
0 commit comments