4
4
*--------------------------------------------------------------------------------------------*/
5
5
use crate :: auth;
6
6
use crate :: constants:: {
7
- CONTROL_PORT , IS_INTERACTIVE_CLI , PROTOCOL_VERSION_TAG , PROTOCOL_VERSION_TAG_PREFIX ,
8
- TUNNEL_SERVICE_USER_AGENT ,
7
+ CONTROL_PORT , IS_INTERACTIVE_CLI , PROTOCOL_VERSION_TAG , TUNNEL_SERVICE_USER_AGENT ,
9
8
} ;
10
9
use crate :: state:: { LauncherPaths , PersistedState } ;
11
10
use crate :: util:: errors:: {
@@ -32,6 +31,8 @@ use tunnels::management::{
32
31
NO_REQUEST_OPTIONS ,
33
32
} ;
34
33
34
+ use super :: wsl_detect:: is_wsl_installed;
35
+
35
36
#[ derive( Clone , Serialize , Deserialize ) ]
36
37
pub struct PersistedTunnel {
37
38
pub name : String ,
@@ -304,7 +305,7 @@ impl DevTunnels {
304
305
return Ok ( ( full_tunnel, persisted) ) ;
305
306
}
306
307
307
- full_tunnel. tags = vec ! [ name . to_string ( ) , VSCODE_CLI_TUNNEL_TAG . to_string ( ) ] ;
308
+ full_tunnel. tags = self . get_tags ( & name ) ;
308
309
309
310
let new_tunnel = spanf ! (
310
311
self . log,
@@ -383,11 +384,9 @@ impl DevTunnels {
383
384
}
384
385
} ;
385
386
386
- if !tunnel. tags . iter ( ) . any ( |t| t == PROTOCOL_VERSION_TAG ) {
387
- tunnel = self
388
- . update_protocol_version_tag ( tunnel, & HOST_TUNNEL_REQUEST_OPTIONS )
389
- . await ?;
390
- }
387
+ tunnel = self
388
+ . sync_tunnel_tags ( & persisted. name , tunnel, & HOST_TUNNEL_REQUEST_OPTIONS )
389
+ . await ?;
391
390
392
391
let locator = TunnelLocator :: try_from ( & tunnel) . unwrap ( ) ;
393
392
let host_token = get_host_token_from_tunnel ( & tunnel) ;
@@ -504,23 +503,40 @@ impl DevTunnels {
504
503
}
505
504
}
506
505
506
+ /// Gets the expected tunnel tags
507
+ fn get_tags ( & self , name : & str ) -> Vec < String > {
508
+ let mut tags = vec ! [
509
+ name. to_string( ) ,
510
+ PROTOCOL_VERSION_TAG . to_string( ) ,
511
+ VSCODE_CLI_TUNNEL_TAG . to_string( ) ,
512
+ ] ;
513
+
514
+ if is_wsl_installed ( & self . log ) {
515
+ tags. push ( "_wsl" . to_string ( ) )
516
+ }
517
+
518
+ tags
519
+ }
520
+
507
521
/// Ensures the tunnel contains a tag for the current PROTCOL_VERSION, and no
508
522
/// other version tags.
509
- async fn update_protocol_version_tag (
523
+ async fn sync_tunnel_tags (
510
524
& self ,
525
+ name : & str ,
511
526
tunnel : Tunnel ,
512
527
options : & TunnelRequestOptions ,
513
528
) -> Result < Tunnel , AnyError > {
529
+ let new_tags = self . get_tags ( name) ;
530
+ if vec_eq_unsorted ( & tunnel. tags , & new_tags) {
531
+ return Ok ( tunnel) ;
532
+ }
533
+
514
534
debug ! (
515
535
self . log,
516
- "Updating tunnel protocol version tag to {}" , PROTOCOL_VERSION_TAG
536
+ "Updating tunnel tags {} -> {}" ,
537
+ tunnel. tags. join( ", " ) ,
538
+ new_tags. join( ", " )
517
539
) ;
518
- let mut new_tags: Vec < String > = tunnel
519
- . tags
520
- . into_iter ( )
521
- . filter ( |t| !t. starts_with ( PROTOCOL_VERSION_TAG_PREFIX ) )
522
- . collect ( ) ;
523
- new_tags. push ( PROTOCOL_VERSION_TAG . to_string ( ) ) ;
524
540
525
541
let tunnel_update = Tunnel {
526
542
tags : new_tags,
@@ -982,6 +998,20 @@ fn clean_hostname_for_tunnel(hostname: &str) -> String {
982
998
}
983
999
}
984
1000
1001
+ fn vec_eq_unsorted ( a : & [ String ] , b : & [ String ] ) -> bool {
1002
+ if a. len ( ) != b. len ( ) {
1003
+ return false ;
1004
+ }
1005
+
1006
+ for item in a {
1007
+ if !b. contains ( item) {
1008
+ return false ;
1009
+ }
1010
+ }
1011
+
1012
+ true
1013
+ }
1014
+
985
1015
#[ cfg( test) ]
986
1016
mod test {
987
1017
use super :: * ;
0 commit comments