Fossil

Check-in [efd3a5ec07]
Login

Check-in [efd3a5ec07]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: efd3a5ec0760f59b9507a6852aa1b4e70dd143b61ff0cea5d5fa46be3b88d25c
User & Date: drh 2024-02-06 15:32:35.610
Context
2024-02-06
23:18
Fix the "fossil patch push" and "fossil patch pull" commands so that, like "fossil sync", they initial try to run ssh without the PATH= argument, but add in the PATH= argument if the initial attempt does not work. ... (check-in: eb135ef204 user: drh tags: trunk)
15:32
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. ... (check-in: efd3a5ec07 user: drh tags: trunk)
15:15
Make the PATH= argument identical for the patch and the sync commands, just to avoid confusion. ... (check-in: e82375910b user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/http.c.
267
268
269
270
271
272
273





























274
275
276
277
278
279
280
    blob_zero(pReply);
  }else{
    blob_read_from_file(pReply, zDownlink, ExtFILE);
    file_delete(zDownlink);
  }
  return rc;
}






























/*
** Sign the content in pSend, compress it, and send it to the server
** via HTTP or HTTPS.  Get a reply, uncompress the reply, and store the reply
** in pRecv.  pRecv is assumed to be uninitialized when
** this routine is called - this routine will initialize it.
**







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
    blob_zero(pReply);
  }else{
    blob_read_from_file(pReply, zDownlink, ExtFILE);
    file_delete(zDownlink);
  }
  return rc;
}

/* If iTruth<0 then guess as to whether or not a PATH= argument is required
** when using ssh to run fossil on a remote machine name zHostname.
**
** If iTruth is 1 or 0 then that means that the PATH= is or is not required,
** respectively.  Record this fact for future reference.
*/
int ssh_needs_path_argument(const char *zHostname, int iTruth){
  int ans = 0;  /* Default to "no" */
  char *z = mprintf("use-path-for-ssh:%s", zHostname);
  if( iTruth<0 ){
    if( db_get_boolean(z/*works-like:"x"*/, 0) ) ans = 1;
  }else if( iTruth ){
    ans = 1;
    db_set(z/*works-like:"x"*/, "1", 0);
  }else{
    db_unset(z/*works-like:"x"*/, 0);
  }
  fossil_free(z);
  return ans;
}

/* Add an approprate PATH= argument to the SSH command under construction
** in pCmd.
*/
void ssh_add_path_argument(Blob *pCmd){
  blob_append_escaped_arg(pCmd, 
     "PATH=$HOME/bin:/usr/local/bin:/opt/homebrew/bin:$PATH", 1);
}

/*
** Sign the content in pSend, compress it, and send it to the server
** via HTTP or HTTPS.  Get a reply, uncompress the reply, and store the reply
** in pRecv.  pRecv is assumed to be uninitialized when
** this routine is called - this routine will initialize it.
**
306
307
308
309
310
311
312

313
314
315

316
317
318
319
320
321
322
323
324
325
    /* Handle the --transport-command option for "fossil sync" and similar */
    return http_exchange_external(pSend,pReply,mHttpFlags,zAltMimetype);
  }

  /* Activate the PATH= auxiliary argument to the ssh command if that
  ** is called for.
  */

  if( g.url.isSsh && (g.url.flags & URL_SSH_RETRY)==0 ){
    char *z = mprintf("use-path-for-ssh:%s", g.url.hostname);
    if( db_get_boolean(z/*works-like:"x"*/, 0) ){

      g.url.flags |= URL_SSH_PATH;
    }
    fossil_free(z);
  }

  if( transport_open(&g.url) ){
    fossil_warning("%s", transport_errmsg(&g.url));
    return 1;
  }








>
|
|
<
>
|
<
<







335
336
337
338
339
340
341
342
343
344

345
346


347
348
349
350
351
352
353
    /* Handle the --transport-command option for "fossil sync" and similar */
    return http_exchange_external(pSend,pReply,mHttpFlags,zAltMimetype);
  }

  /* Activate the PATH= auxiliary argument to the ssh command if that
  ** is called for.
  */
  if( g.url.isSsh
   && (g.url.flags & URL_SSH_RETRY)==0
   && ssh_needs_path_argument(g.url.hostname, -1)

  ){
    g.url.flags |= URL_SSH_PATH;


  }

  if( transport_open(&g.url) ){
    fossil_warning("%s", transport_errmsg(&g.url));
    return 1;
  }

513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
        "Retrying %s the PATH= argument.\n",
        g.url.hostname,
        (g.url.flags & URL_SSH_PATH)!=0 ? "without" : "with"
      );
      g.url.flags ^= URL_SSH_PATH|URL_SSH_RETRY;
      rc = http_exchange(pSend,pReply,mHttpFlags,0,zAltMimetype);
      if( rc==0 ){
        char *z = mprintf("use-path-for-ssh:%s", g.url.hostname);
        if( (g.url.flags & URL_SSH_PATH) ){
          db_set(z/*works-like:"x"*/, "1", 0);
        }else{
          db_unset(z/*works-like:"x"*/, 0);
        }
        fossil_free(z);
      }
      return rc;
    }else{
      /* The problem could not be corrected by retrying.  Report the
      ** the error. */
      if( g.url.isSsh && !g.fSshTrace ){
        fossil_warning("server did not reply: "







|
|
<
<
<
<
<







541
542
543
544
545
546
547
548
549





550
551
552
553
554
555
556
        "Retrying %s the PATH= argument.\n",
        g.url.hostname,
        (g.url.flags & URL_SSH_PATH)!=0 ? "without" : "with"
      );
      g.url.flags ^= URL_SSH_PATH|URL_SSH_RETRY;
      rc = http_exchange(pSend,pReply,mHttpFlags,0,zAltMimetype);
      if( rc==0 ){
        (void)ssh_needs_path_argument(g.url.hostname,
                                (g.url.flags & URL_SSH_PATH)!=0);





      }
      return rc;
    }else{
      /* The problem could not be corrected by retrying.  Report the
      ** the error. */
      if( g.url.isSsh && !g.fSshTrace ){
        fossil_warning("server did not reply: "
Changes to src/http_transport.c.
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
  ){
    fossil_fatal("the ssh:// URL is asking to run an unsafe command [%s] on "
                 "the server.", pUrlData->fossil);
  }
  if( (pUrlData->flags & URL_SSH_EXE)==0
   && (pUrlData->flags & URL_SSH_PATH)!=0 
  ){
    blob_append_escaped_arg(&zCmd, 
     /*  tag-20240206-b:
     **  vvvv---  keep in sync with PATH= at tag-20240206-a */
        "PATH=$HOME/bin:/usr/local/bin:/opt/homebrew/bin:$PATH", 1);
  }
  blob_append_escaped_arg(&zCmd, pUrlData->fossil, 1);
  blob_append(&zCmd, " test-http", 10);
  if( pUrlData->path && pUrlData->path[0] ){
    blob_append_escaped_arg(&zCmd, pUrlData->path, 1);
  }else{
    fossil_fatal("ssh:// URI does not specify a path to the repository");







|
<
<
<







138
139
140
141
142
143
144
145



146
147
148
149
150
151
152
  ){
    fossil_fatal("the ssh:// URL is asking to run an unsafe command [%s] on "
                 "the server.", pUrlData->fossil);
  }
  if( (pUrlData->flags & URL_SSH_EXE)==0
   && (pUrlData->flags & URL_SSH_PATH)!=0 
  ){
    ssh_add_path_argument(&zCmd);



  }
  blob_append_escaped_arg(&zCmd, pUrlData->fossil, 1);
  blob_append(&zCmd, " test-http", 10);
  if( pUrlData->path && pUrlData->path[0] ){
    blob_append_escaped_arg(&zCmd, pUrlData->path, 1);
  }else{
    fossil_fatal("ssh:// URI does not specify a path to the repository");
Changes to src/patch.c.
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
    Blob remote;
    *(char*)(zDir-1) = 0;
    transport_ssh_command(&cmd);
    blob_appendf(&cmd, " -T");
    blob_append_escaped_arg(&cmd, zRemote, 0);
    blob_init(&remote, 0, 0);
    if( zFossilCmd==0 ){
      blob_append_escaped_arg(&cmd,
        /*  tag-20240206-a:
        **  vvvv----  Keep in sync with the PATH= in tag-20240206-b */
           "PATH=$HOME/bin:/usr/local/bin:/opt/homebrew/bin:$PATH", 0);
      zFossilCmd = "fossil";
    }
    blob_appendf(&remote, "%$ patch %s%s --dir64 %z -",
                 zFossilCmd, zRemoteCmd, zForce, encode64(zDir, -1));
    blob_append_escaped_arg(&cmd, blob_str(&remote), 0);
    blob_reset(&remote);
  }







|
<
<
<







692
693
694
695
696
697
698
699



700
701
702
703
704
705
706
    Blob remote;
    *(char*)(zDir-1) = 0;
    transport_ssh_command(&cmd);
    blob_appendf(&cmd, " -T");
    blob_append_escaped_arg(&cmd, zRemote, 0);
    blob_init(&remote, 0, 0);
    if( zFossilCmd==0 ){
      ssh_add_path_argument(&cmd);



      zFossilCmd = "fossil";
    }
    blob_appendf(&remote, "%$ patch %s%s --dir64 %z -",
                 zFossilCmd, zRemoteCmd, zForce, encode64(zDir, -1));
    blob_append_escaped_arg(&cmd, blob_str(&remote), 0);
    blob_reset(&remote);
  }