@@ -6,8 +6,6 @@ use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
6
6
use rustc_serialize:: Encodable as RustcEncodable ;
7
7
use rustc_session:: Session ;
8
8
use std:: fs;
9
- use std:: io;
10
- use std:: path:: PathBuf ;
11
9
12
10
use super :: data:: * ;
13
11
use super :: dirty_clean;
@@ -44,7 +42,9 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) {
44
42
join (
45
43
move || {
46
44
sess. time ( "incr_comp_persist_result_cache" , || {
47
- save_in ( sess, query_cache_path, "query cache" , |e| encode_query_cache ( tcx, e) ) ;
45
+ file_format:: save_in ( sess, query_cache_path, "query cache" , |e| {
46
+ encode_query_cache ( tcx, e)
47
+ } ) ;
48
48
} ) ;
49
49
} ,
50
50
move || {
@@ -86,7 +86,9 @@ pub fn save_work_product_index(
86
86
debug ! ( "save_work_product_index()" ) ;
87
87
dep_graph. assert_ignored ( ) ;
88
88
let path = work_products_path ( sess) ;
89
- save_in ( sess, path, "work product index" , |e| encode_work_product_index ( & new_work_products, e) ) ;
89
+ file_format:: save_in ( sess, path, "work product index" , |e| {
90
+ encode_work_product_index ( & new_work_products, e)
91
+ } ) ;
90
92
91
93
// We also need to clean out old work-products, as not all of them are
92
94
// deleted during invalidation. Some object files don't change their
@@ -113,58 +115,6 @@ pub fn save_work_product_index(
113
115
} ) ;
114
116
}
115
117
116
- pub ( crate ) fn save_in < F > ( sess : & Session , path_buf : PathBuf , name : & str , encode : F )
117
- where
118
- F : FnOnce ( & mut FileEncoder ) -> FileEncodeResult ,
119
- {
120
- debug ! ( "save: storing data in {}" , path_buf. display( ) ) ;
121
-
122
- // Delete the old file, if any.
123
- // Note: It's important that we actually delete the old file and not just
124
- // truncate and overwrite it, since it might be a shared hard-link, the
125
- // underlying data of which we don't want to modify
126
- match fs:: remove_file ( & path_buf) {
127
- Ok ( ( ) ) => {
128
- debug ! ( "save: remove old file" ) ;
129
- }
130
- Err ( err) if err. kind ( ) == io:: ErrorKind :: NotFound => ( ) ,
131
- Err ( err) => {
132
- sess. err ( & format ! (
133
- "unable to delete old {} at `{}`: {}" ,
134
- name,
135
- path_buf. display( ) ,
136
- err
137
- ) ) ;
138
- return ;
139
- }
140
- }
141
-
142
- let mut encoder = match FileEncoder :: new ( & path_buf) {
143
- Ok ( encoder) => encoder,
144
- Err ( err) => {
145
- sess. err ( & format ! ( "failed to create {} at `{}`: {}" , name, path_buf. display( ) , err) ) ;
146
- return ;
147
- }
148
- } ;
149
-
150
- if let Err ( err) = file_format:: write_file_header ( & mut encoder, sess. is_nightly_build ( ) ) {
151
- sess. err ( & format ! ( "failed to write {} header to `{}`: {}" , name, path_buf. display( ) , err) ) ;
152
- return ;
153
- }
154
-
155
- if let Err ( err) = encode ( & mut encoder) {
156
- sess. err ( & format ! ( "failed to write {} to `{}`: {}" , name, path_buf. display( ) , err) ) ;
157
- return ;
158
- }
159
-
160
- if let Err ( err) = encoder. flush ( ) {
161
- sess. err ( & format ! ( "failed to flush {} to `{}`: {}" , name, path_buf. display( ) , err) ) ;
162
- return ;
163
- }
164
-
165
- debug ! ( "save: data written to disk successfully" ) ;
166
- }
167
-
168
118
fn encode_work_product_index (
169
119
work_products : & FxHashMap < WorkProductId , WorkProduct > ,
170
120
encoder : & mut FileEncoder ,
0 commit comments