Fossil SCM

Merge commonly used operations associated with the PATH= of a remote fossil run using ssh into subroutines, so that they do not get out of sync with each other.

drh 2024-02-06 15:32 trunk
Commit efd3a5ec0760f59b9507a6852aa1b4e70dd143b61ff0cea5d5fa46be3b88d25c
+36 -13
--- src/http.c
+++ src/http.c
@@ -269,10 +269,39 @@
269269
blob_read_from_file(pReply, zDownlink, ExtFILE);
270270
file_delete(zDownlink);
271271
}
272272
return rc;
273273
}
274
+
275
+/* If iTruth<0 then guess as to whether or not a PATH= argument is required
276
+** when using ssh to run fossil on a remote machine name zHostname.
277
+**
278
+** If iTruth is 1 or 0 then that means that the PATH= is or is not required,
279
+** respectively. Record this fact for future reference.
280
+*/
281
+int ssh_needs_path_argument(const char *zHostname, int iTruth){
282
+ int ans = 0; /* Default to "no" */
283
+ char *z = mprintf("use-path-for-ssh:%s", zHostname);
284
+ if( iTruth<0 ){
285
+ if( db_get_boolean(z/*works-like:"x"*/, 0) ) ans = 1;
286
+ }else if( iTruth ){
287
+ ans = 1;
288
+ db_set(z/*works-like:"x"*/, "1", 0);
289
+ }else{
290
+ db_unset(z/*works-like:"x"*/, 0);
291
+ }
292
+ fossil_free(z);
293
+ return ans;
294
+}
295
+
296
+/* Add an approprate PATH= argument to the SSH command under construction
297
+** in pCmd.
298
+*/
299
+void ssh_add_path_argument(Blob *pCmd){
300
+ blob_append_escaped_arg(pCmd,
301
+ "PATH=$HOME/bin:/usr/local/bin:/opt/homebrew/bin:$PATH", 1);
302
+}
274303
275304
/*
276305
** Sign the content in pSend, compress it, and send it to the server
277306
** via HTTP or HTTPS. Get a reply, uncompress the reply, and store the reply
278307
** in pRecv. pRecv is assumed to be uninitialized when
@@ -308,16 +337,15 @@
308337
}
309338
310339
/* Activate the PATH= auxiliary argument to the ssh command if that
311340
** is called for.
312341
*/
313
- if( g.url.isSsh && (g.url.flags & URL_SSH_RETRY)==0 ){
314
- char *z = mprintf("use-path-for-ssh:%s", g.url.hostname);
315
- if( db_get_boolean(z/*works-like:"x"*/, 0) ){
316
- g.url.flags |= URL_SSH_PATH;
317
- }
318
- fossil_free(z);
342
+ if( g.url.isSsh
343
+ && (g.url.flags & URL_SSH_RETRY)==0
344
+ && ssh_needs_path_argument(g.url.hostname, -1)
345
+ ){
346
+ g.url.flags |= URL_SSH_PATH;
319347
}
320348
321349
if( transport_open(&g.url) ){
322350
fossil_warning("%s", transport_errmsg(&g.url));
323351
return 1;
@@ -515,17 +543,12 @@
515543
(g.url.flags & URL_SSH_PATH)!=0 ? "without" : "with"
516544
);
517545
g.url.flags ^= URL_SSH_PATH|URL_SSH_RETRY;
518546
rc = http_exchange(pSend,pReply,mHttpFlags,0,zAltMimetype);
519547
if( rc==0 ){
520
- char *z = mprintf("use-path-for-ssh:%s", g.url.hostname);
521
- if( (g.url.flags & URL_SSH_PATH) ){
522
- db_set(z/*works-like:"x"*/, "1", 0);
523
- }else{
524
- db_unset(z/*works-like:"x"*/, 0);
525
- }
526
- fossil_free(z);
548
+ (void)ssh_needs_path_argument(g.url.hostname,
549
+ (g.url.flags & URL_SSH_PATH)!=0);
527550
}
528551
return rc;
529552
}else{
530553
/* The problem could not be corrected by retrying. Report the
531554
** the error. */
532555
--- src/http.c
+++ src/http.c
@@ -269,10 +269,39 @@
269 blob_read_from_file(pReply, zDownlink, ExtFILE);
270 file_delete(zDownlink);
271 }
272 return rc;
273 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
275 /*
276 ** Sign the content in pSend, compress it, and send it to the server
277 ** via HTTP or HTTPS. Get a reply, uncompress the reply, and store the reply
278 ** in pRecv. pRecv is assumed to be uninitialized when
@@ -308,16 +337,15 @@
308 }
309
310 /* Activate the PATH= auxiliary argument to the ssh command if that
311 ** is called for.
312 */
313 if( g.url.isSsh && (g.url.flags & URL_SSH_RETRY)==0 ){
314 char *z = mprintf("use-path-for-ssh:%s", g.url.hostname);
315 if( db_get_boolean(z/*works-like:"x"*/, 0) ){
316 g.url.flags |= URL_SSH_PATH;
317 }
318 fossil_free(z);
319 }
320
321 if( transport_open(&g.url) ){
322 fossil_warning("%s", transport_errmsg(&g.url));
323 return 1;
@@ -515,17 +543,12 @@
515 (g.url.flags & URL_SSH_PATH)!=0 ? "without" : "with"
516 );
517 g.url.flags ^= URL_SSH_PATH|URL_SSH_RETRY;
518 rc = http_exchange(pSend,pReply,mHttpFlags,0,zAltMimetype);
519 if( rc==0 ){
520 char *z = mprintf("use-path-for-ssh:%s", g.url.hostname);
521 if( (g.url.flags & URL_SSH_PATH) ){
522 db_set(z/*works-like:"x"*/, "1", 0);
523 }else{
524 db_unset(z/*works-like:"x"*/, 0);
525 }
526 fossil_free(z);
527 }
528 return rc;
529 }else{
530 /* The problem could not be corrected by retrying. Report the
531 ** the error. */
532
--- src/http.c
+++ src/http.c
@@ -269,10 +269,39 @@
269 blob_read_from_file(pReply, zDownlink, ExtFILE);
270 file_delete(zDownlink);
271 }
272 return rc;
273 }
274
275 /* If iTruth<0 then guess as to whether or not a PATH= argument is required
276 ** when using ssh to run fossil on a remote machine name zHostname.
277 **
278 ** If iTruth is 1 or 0 then that means that the PATH= is or is not required,
279 ** respectively. Record this fact for future reference.
280 */
281 int ssh_needs_path_argument(const char *zHostname, int iTruth){
282 int ans = 0; /* Default to "no" */
283 char *z = mprintf("use-path-for-ssh:%s", zHostname);
284 if( iTruth<0 ){
285 if( db_get_boolean(z/*works-like:"x"*/, 0) ) ans = 1;
286 }else if( iTruth ){
287 ans = 1;
288 db_set(z/*works-like:"x"*/, "1", 0);
289 }else{
290 db_unset(z/*works-like:"x"*/, 0);
291 }
292 fossil_free(z);
293 return ans;
294 }
295
296 /* Add an approprate PATH= argument to the SSH command under construction
297 ** in pCmd.
298 */
299 void ssh_add_path_argument(Blob *pCmd){
300 blob_append_escaped_arg(pCmd,
301 "PATH=$HOME/bin:/usr/local/bin:/opt/homebrew/bin:$PATH", 1);
302 }
303
304 /*
305 ** Sign the content in pSend, compress it, and send it to the server
306 ** via HTTP or HTTPS. Get a reply, uncompress the reply, and store the reply
307 ** in pRecv. pRecv is assumed to be uninitialized when
@@ -308,16 +337,15 @@
337 }
338
339 /* Activate the PATH= auxiliary argument to the ssh command if that
340 ** is called for.
341 */
342 if( g.url.isSsh
343 && (g.url.flags & URL_SSH_RETRY)==0
344 && ssh_needs_path_argument(g.url.hostname, -1)
345 ){
346 g.url.flags |= URL_SSH_PATH;
 
347 }
348
349 if( transport_open(&g.url) ){
350 fossil_warning("%s", transport_errmsg(&g.url));
351 return 1;
@@ -515,17 +543,12 @@
543 (g.url.flags & URL_SSH_PATH)!=0 ? "without" : "with"
544 );
545 g.url.flags ^= URL_SSH_PATH|URL_SSH_RETRY;
546 rc = http_exchange(pSend,pReply,mHttpFlags,0,zAltMimetype);
547 if( rc==0 ){
548 (void)ssh_needs_path_argument(g.url.hostname,
549 (g.url.flags & URL_SSH_PATH)!=0);
 
 
 
 
 
550 }
551 return rc;
552 }else{
553 /* The problem could not be corrected by retrying. Report the
554 ** the error. */
555
--- src/http_transport.c
+++ src/http_transport.c
@@ -140,14 +140,11 @@
140140
"the server.", pUrlData->fossil);
141141
}
142142
if( (pUrlData->flags & URL_SSH_EXE)==0
143143
&& (pUrlData->flags & URL_SSH_PATH)!=0
144144
){
145
- blob_append_escaped_arg(&zCmd,
146
- /* tag-20240206-b:
147
- ** vvvv--- keep in sync with PATH= at tag-20240206-a */
148
- "PATH=$HOME/bin:/usr/local/bin:/opt/homebrew/bin:$PATH", 1);
145
+ ssh_add_path_argument(&zCmd);
149146
}
150147
blob_append_escaped_arg(&zCmd, pUrlData->fossil, 1);
151148
blob_append(&zCmd, " test-http", 10);
152149
if( pUrlData->path && pUrlData->path[0] ){
153150
blob_append_escaped_arg(&zCmd, pUrlData->path, 1);
154151
--- src/http_transport.c
+++ src/http_transport.c
@@ -140,14 +140,11 @@
140 "the server.", pUrlData->fossil);
141 }
142 if( (pUrlData->flags & URL_SSH_EXE)==0
143 && (pUrlData->flags & URL_SSH_PATH)!=0
144 ){
145 blob_append_escaped_arg(&zCmd,
146 /* tag-20240206-b:
147 ** vvvv--- keep in sync with PATH= at tag-20240206-a */
148 "PATH=$HOME/bin:/usr/local/bin:/opt/homebrew/bin:$PATH", 1);
149 }
150 blob_append_escaped_arg(&zCmd, pUrlData->fossil, 1);
151 blob_append(&zCmd, " test-http", 10);
152 if( pUrlData->path && pUrlData->path[0] ){
153 blob_append_escaped_arg(&zCmd, pUrlData->path, 1);
154
--- src/http_transport.c
+++ src/http_transport.c
@@ -140,14 +140,11 @@
140 "the server.", pUrlData->fossil);
141 }
142 if( (pUrlData->flags & URL_SSH_EXE)==0
143 && (pUrlData->flags & URL_SSH_PATH)!=0
144 ){
145 ssh_add_path_argument(&zCmd);
 
 
 
146 }
147 blob_append_escaped_arg(&zCmd, pUrlData->fossil, 1);
148 blob_append(&zCmd, " test-http", 10);
149 if( pUrlData->path && pUrlData->path[0] ){
150 blob_append_escaped_arg(&zCmd, pUrlData->path, 1);
151
+1 -4
--- src/patch.c
+++ src/patch.c
@@ -694,14 +694,11 @@
694694
transport_ssh_command(&cmd);
695695
blob_appendf(&cmd, " -T");
696696
blob_append_escaped_arg(&cmd, zRemote, 0);
697697
blob_init(&remote, 0, 0);
698698
if( zFossilCmd==0 ){
699
- blob_append_escaped_arg(&cmd,
700
- /* tag-20240206-a:
701
- ** vvvv---- Keep in sync with the PATH= in tag-20240206-b */
702
- "PATH=$HOME/bin:/usr/local/bin:/opt/homebrew/bin:$PATH", 0);
699
+ ssh_add_path_argument(&cmd);
703700
zFossilCmd = "fossil";
704701
}
705702
blob_appendf(&remote, "%$ patch %s%s --dir64 %z -",
706703
zFossilCmd, zRemoteCmd, zForce, encode64(zDir, -1));
707704
blob_append_escaped_arg(&cmd, blob_str(&remote), 0);
708705
--- src/patch.c
+++ src/patch.c
@@ -694,14 +694,11 @@
694 transport_ssh_command(&cmd);
695 blob_appendf(&cmd, " -T");
696 blob_append_escaped_arg(&cmd, zRemote, 0);
697 blob_init(&remote, 0, 0);
698 if( zFossilCmd==0 ){
699 blob_append_escaped_arg(&cmd,
700 /* tag-20240206-a:
701 ** vvvv---- Keep in sync with the PATH= in tag-20240206-b */
702 "PATH=$HOME/bin:/usr/local/bin:/opt/homebrew/bin:$PATH", 0);
703 zFossilCmd = "fossil";
704 }
705 blob_appendf(&remote, "%$ patch %s%s --dir64 %z -",
706 zFossilCmd, zRemoteCmd, zForce, encode64(zDir, -1));
707 blob_append_escaped_arg(&cmd, blob_str(&remote), 0);
708
--- src/patch.c
+++ src/patch.c
@@ -694,14 +694,11 @@
694 transport_ssh_command(&cmd);
695 blob_appendf(&cmd, " -T");
696 blob_append_escaped_arg(&cmd, zRemote, 0);
697 blob_init(&remote, 0, 0);
698 if( zFossilCmd==0 ){
699 ssh_add_path_argument(&cmd);
 
 
 
700 zFossilCmd = "fossil";
701 }
702 blob_appendf(&remote, "%$ patch %s%s --dir64 %z -",
703 zFossilCmd, zRemoteCmd, zForce, encode64(zDir, -1));
704 blob_append_escaped_arg(&cmd, blob_str(&remote), 0);
705

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button