@@ -147,7 +147,7 @@ def is_alive(self) -> bool:
147
147
stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL , stdin = subprocess .DEVNULL
148
148
).wait () == 0
149
149
150
- def check_hostname_matches (self ) -> None :
150
+ def check_hostname_matches (self ) -> bool :
151
151
cp = subprocess .run (self .batch_cmd_prefix + [self .conn_data .hostname , 'hostname' , '-f' ], stdout = subprocess .PIPE ,
152
152
stderr = subprocess .DEVNULL , stdin = subprocess .DEVNULL )
153
153
if cp .returncode == 0 :
@@ -170,9 +170,9 @@ def check_hostname_matches(self) -> None:
170
170
)
171
171
sys .stdout .flush ()
172
172
response = get_key_press ('yn' , 'n' )
173
- if response != 'y' :
174
- raise SystemExit (1 )
175
173
print (reset_terminal (), end = '' )
174
+ return response == 'y'
175
+ return True
176
176
177
177
def download (self ) -> bool :
178
178
with open (self .dest , 'wb' ) as f :
@@ -268,9 +268,9 @@ def save_as(conn_data: SSHConnectionData, remote_path: str, cli_opts: RemoteFile
268
268
if os .path .dirname (dest ):
269
269
os .makedirs (os .path .dirname (dest ), exist_ok = True )
270
270
with ControlMaster (conn_data , remote_path , cli_opts , dest = dest ) as master :
271
- master .check_hostname_matches ()
272
- if not master .download ():
273
- show_error ('Failed to copy file from remote machine' )
271
+ if master .check_hostname_matches ():
272
+ if not master .download ():
273
+ show_error ('Failed to copy file from remote machine' )
274
274
275
275
276
276
def handle_action (action : str , cli_opts : RemoteFileCLIOptions ) -> Result :
@@ -280,14 +280,15 @@ def handle_action(action: str, cli_opts: RemoteFileCLIOptions) -> Result:
280
280
print ('Opening' , cli_opts .path , 'from' , cli_opts .hostname )
281
281
dest = os .path .join (tempfile .mkdtemp (), os .path .basename (remote_path ))
282
282
with ControlMaster (conn_data , remote_path , cli_opts , dest = dest ) as master :
283
- master .check_hostname_matches ()
284
- if master .download ():
285
- return dest
286
- show_error ('Failed to copy file from remote machine' )
283
+ if master .check_hostname_matches ():
284
+ if master .download ():
285
+ return dest
286
+ show_error ('Failed to copy file from remote machine' )
287
287
elif action == 'edit' :
288
288
print ('Editing' , cli_opts .path , 'from' , cli_opts .hostname )
289
289
with ControlMaster (conn_data , remote_path , cli_opts ) as master :
290
- master .check_hostname_matches ()
290
+ if not master .check_hostname_matches ():
291
+ return None
291
292
if not master .download ():
292
293
show_error (f'Failed to download { remote_path } ' )
293
294
return None
0 commit comments