This repository was archived by the owner on Dec 29, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -260,6 +260,17 @@ fn run_cargo_ws(
260
260
Arc :: clone ( & reached_primary) ,
261
261
) ;
262
262
263
+ // Cargo excludes target/ from backups since rust-lang/cargo@cf3bfc9/rust-lang/cargo#8378 but
264
+ // it does so if and only if the directory does not exist and it's about to create it.
265
+ // rls runs cargo internally with target directory set to target/rls/ so, if target/ doesn't
266
+ // exist yet and rls runs, target/ and target/rls/ will be created. While target/rls/ will be
267
+ // excluded from backups target/ won't be (as from our perspective it's not the target
268
+ // directory but its parent) and, when user runs "cargo build" themselves cargo will see
269
+ // target/ existing already and won't exclude it from backups. We can work around that by
270
+ // attempting to create a backup-excluded target/ ourelves using cargo paths:: machinery.
271
+ cargo:: util:: paths:: create_dir_all_excluded_from_backups_atomic (
272
+ config. target_dir ( ) . unwrap ( ) . unwrap ( ) . as_path_unlocked ( ) . parent ( ) . unwrap ( ) ,
273
+ ) ?;
263
274
let exec = Arc :: new ( exec) as Arc < dyn Executor > ;
264
275
match compile_with_exec ( & ws, & compile_opts, & exec) {
265
276
Ok ( _) => {
Original file line number Diff line number Diff line change
1
+ use std:: fs;
1
2
use std:: path:: Path ;
2
3
use std:: time:: { Duration , Instant } ;
3
4
@@ -2227,3 +2228,30 @@ fn client_parse_error_on_malformed_input() {
2227
2228
// to provide better fault tolerance.
2228
2229
cmd. wait ( ) . unwrap ( ) ;
2229
2230
}
2231
+
2232
+ #[ test]
2233
+ fn client_cargo_target_directory_is_excluded_from_backups ( ) {
2234
+ // This is to make sure that if it's rls that crates target/ directory the directory is
2235
+ // excluded from backups just as if it was created by cargo itself. See a comment in
2236
+ // run_cargo_ws() or rust-lang/cargo@cf3bfc9/rust-lang/cargo#8378 for more information.
2237
+ let p = project ( "backup_exclusion_workspace" )
2238
+ . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ) )
2239
+ . file (
2240
+ "src/main.rs" ,
2241
+ r#"
2242
+ fn main() {
2243
+ println!("Hello world!");
2244
+ }
2245
+ "# ,
2246
+ )
2247
+ . build ( ) ;
2248
+ let root_path = p. root ( ) ;
2249
+ let mut rls = p. spawn_rls_async ( ) ;
2250
+ rls. request :: < Initialize > ( 0 , initialize_params ( root_path) ) ;
2251
+ let _ = rls. wait_for_indexing ( ) ;
2252
+ let cachedir_tag = p. root ( ) . join ( "target" ) . join ( "CACHEDIR.TAG" ) ;
2253
+ assert ! ( cachedir_tag. is_file( ) ) ;
2254
+ assert ! ( fs:: read_to_string( & cachedir_tag)
2255
+ . unwrap( )
2256
+ . starts_with( "Signature: 8a477f597d28d172789f06886806bc55" ) ) ;
2257
+ }
You can’t perform that action at this time.
0 commit comments