@@ -71,10 +71,12 @@ pub enum InputOrigin {
71
71
/// computation. The `ExecutionState` code then has further pieces that track
72
72
/// access to nonexistent files, which we treat as being equivalent to an
73
73
/// existing empty file for these purposes.
74
-
75
74
pub struct InputHandle {
76
75
name : OsString ,
77
76
inner : Box < dyn InputFeatures > ,
77
+ /// Indicates that the file cannot be written to (provided by a read-only IoProvider) and
78
+ /// therefore it is useless to compute the digest.
79
+ read_only : bool ,
78
80
digest : digest:: DigestComputer ,
79
81
origin : InputOrigin ,
80
82
ever_read : bool ,
@@ -91,6 +93,24 @@ impl InputHandle {
91
93
InputHandle {
92
94
name : name. to_os_string ( ) ,
93
95
inner : Box :: new ( inner) ,
96
+ read_only : false ,
97
+ digest : Default :: default ( ) ,
98
+ origin,
99
+ ever_read : false ,
100
+ did_unhandled_seek : false ,
101
+ ungetc_char : None ,
102
+ }
103
+ }
104
+
105
+ pub fn new_read_only < T : ' static + InputFeatures > (
106
+ name : & OsStr ,
107
+ inner : T ,
108
+ origin : InputOrigin ,
109
+ ) -> InputHandle {
110
+ InputHandle {
111
+ name : name. to_os_string ( ) ,
112
+ inner : Box :: new ( inner) ,
113
+ read_only : true ,
94
114
digest : Default :: default ( ) ,
95
115
origin,
96
116
ever_read : false ,
@@ -114,13 +134,13 @@ impl InputHandle {
114
134
}
115
135
116
136
/// Consumes the object and returns the SHA256 sum of the content that was
117
- /// written . No digest is returned if there was ever a seek on the input
137
+ /// read . No digest is returned if there was ever a seek on the input
118
138
/// stream, since in that case the results will not be reliable. We also
119
139
/// return None if the stream was never read, which is another common
120
140
/// TeX access pattern: files are opened, immediately closed, and then
121
- /// opened again.
141
+ /// opened again. Finally, no digest is returned if the file is marked read-only.
122
142
pub fn into_name_digest ( self ) -> ( OsString , Option < DigestData > ) {
123
- if self . did_unhandled_seek || !self . ever_read {
143
+ if self . did_unhandled_seek || !self . ever_read || self . read_only {
124
144
( self . name , None )
125
145
} else {
126
146
( self . name , Some ( DigestData :: from ( self . digest ) ) )
@@ -174,7 +194,9 @@ impl Read for InputHandle {
174
194
175
195
self . ever_read = true ;
176
196
let n = self . inner . read ( buf) ?;
177
- self . digest . input ( & buf[ ..n] ) ;
197
+ if !self . read_only {
198
+ self . digest . input ( & buf[ ..n] ) ;
199
+ }
178
200
Ok ( n)
179
201
}
180
202
}
0 commit comments