@@ -6,8 +6,6 @@ use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
66use rustc_serialize:: Encodable as RustcEncodable ;
77use rustc_session:: Session ;
88use std:: fs;
9- use std:: io;
10- use std:: path:: PathBuf ;
119
1210use super :: data:: * ;
1311use super :: dirty_clean;
@@ -44,7 +42,9 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) {
4442 join (
4543 move || {
4644 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+ } ) ;
4848 } ) ;
4949 } ,
5050 move || {
@@ -86,7 +86,9 @@ pub fn save_work_product_index(
8686 debug ! ( "save_work_product_index()" ) ;
8787 dep_graph. assert_ignored ( ) ;
8888 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+ } ) ;
9092
9193 // We also need to clean out old work-products, as not all of them are
9294 // deleted during invalidation. Some object files don't change their
@@ -113,58 +115,6 @@ pub fn save_work_product_index(
113115 } ) ;
114116}
115117
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-
168118fn encode_work_product_index (
169119 work_products : & FxHashMap < WorkProductId , WorkProduct > ,
170120 encoder : & mut FileEncoder ,
0 commit comments