Check-in [ed6495baa6]
Not logged in

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

Overview
Comment:For the "fossil ui REMOTE:path" command, initially omit the PATH= prefix but add it in if the initial attempt fails to find a fossil executable.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ed6495baa68341d271e913f13073f27ba34bbd3269c4e88b8a47671565e41fe6
User & Date: drh 2024-02-07 12:16:30.374
Context
2024-02-07
15:11
Fix the "test-ssh-needs-path" command so that it works even if run from outside of an open check-out. check-in: 46e7855a4e user: drh tags: trunk
14:25
Pull in the remaining bits from trunk for integration testing. check-in: d27cb05f6b user: andybradford tags: clone-resume
12:16
For the "fossil ui REMOTE:path" command, initially omit the PATH= prefix but add it in if the initial attempt fails to find a fossil executable. check-in: ed6495baa6 user: drh tags: trunk
2024-02-06
23:59
Make use of the ssh_add_path_argument() function for the implementation of "fossil ui REMOTE:folder". check-in: 151406f34c user: drh tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/http.c.
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
    if( db_get_boolean(z/*works-like:"x"*/, 0) ) ans = 1;
  }else{
    if( iTruth>=99 ){
      iTruth = !db_get_boolean(z/*works-like:"x"*/, 0);
    }
    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;
}

/*







|

|







289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
    if( db_get_boolean(z/*works-like:"x"*/, 0) ) ans = 1;
  }else{
    if( iTruth>=99 ){
      iTruth = !db_get_boolean(z/*works-like:"x"*/, 0);
    }
    if( iTruth ){
      ans = 1;
      db_set(z/*works-like:"x"*/, "1", 1);
    }else{
      db_unset(z/*works-like:"x"*/, 1);
    }
  }
  fossil_free(z);
  return ans;
}

/*
Changes to src/main.c.
3341
3342
3343
3344
3345
3346
3347


3348

3349


3350
3351
3352
3353
3354
3355
3356

3357

3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370




3371
3372
3373
3374
3375
3376
3377
3378
3379






3380
3381
3382
3383
3384
3385
3386

3387

3388
3389
3390
3391
3392
3393
3394
  }
  if( zRemote ){
    /* If a USER@HOST:REPO argument is supplied, then use SSH to run
    ** "fossil ui --nobrowser" on the remote system and to set up a
    ** tunnel from the local machine to the remote. */
    FILE *sshIn;
    Blob ssh;


    char zLine[1000];

    blob_init(&ssh, 0, 0);


    transport_ssh_command(&ssh);
    db_close_config();
    blob_appendf(&ssh,
       " -t -L 127.0.0.1:%d:127.0.0.1:%d %!$",
       iPort, iPort, zRemote
    );
    if( zFossilCmd==0 ){

      ssh_add_path_argument(&ssh);

      blob_append_escaped_arg(&ssh, "fossil", 1);
    }else{
      blob_appendf(&ssh, " %$", zFossilCmd);
    }
    blob_appendf(&ssh, " ui --nobrowser --localauth --port %d", iPort);
    if( zNotFound ) blob_appendf(&ssh, " --notfound %!$", zNotFound);
    if( zFileGlob ) blob_appendf(&ssh, " --files-urlenc %T", zFileGlob);
    if( g.zCkoutAlias ) blob_appendf(&ssh, " --ckout-alias %!$",g.zCkoutAlias);
    if( g.zExtRoot ) blob_appendf(&ssh, " --extroot %$", g.zExtRoot);
    if( skin_in_use() ) blob_appendf(&ssh, " --skin %s", skin_in_use());
    if( zJsMode ) blob_appendf(&ssh, " --jsmode %s", zJsMode);
    if( fCreate ) blob_appendf(&ssh, " --create");
    blob_appendf(&ssh, " %$", g.argv[2]);




    fossil_print("%s\n", blob_str(&ssh));
    sshIn = popen(blob_str(&ssh), "r");
    if( sshIn==0 ){
      fossil_fatal("unable to %s", blob_str(&ssh));
    }
    while( fgets(zLine, sizeof(zLine), sshIn) ){
      fputs(zLine, stdout);
      fflush(stdout);
      if( zBrowserCmd && sqlite3_strglob("*Listening for HTTP*",zLine)==0 ){






        char *zCmd = mprintf(zBrowserCmd/*works-like:"%d"*/,iPort);
        fossil_system(zCmd);
        fossil_free(zCmd);
        fossil_free(zBrowserCmd);
        zBrowserCmd = 0;
      }
    }

    pclose(sshIn);

    fossil_free(zBrowserCmd);
    return;
  }
  if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
  if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
  db_close(1);
#if !defined(_WIN32)







>
>

>

>
>
|
<
|
|
|
|
|
>
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
|
|
|
|
|
|
|
>
|
>







3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355

3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
  }
  if( zRemote ){
    /* If a USER@HOST:REPO argument is supplied, then use SSH to run
    ** "fossil ui --nobrowser" on the remote system and to set up a
    ** tunnel from the local machine to the remote. */
    FILE *sshIn;
    Blob ssh;
    int bRunning = 0;    /* True when fossil starts up on the remote */
    int isRetry;         /* True if on the second attempt */        
    char zLine[1000];

    blob_init(&ssh, 0, 0);
    for(isRetry=0; isRetry<2 && !bRunning; isRetry++){
      blob_reset(&ssh);
      transport_ssh_command(&ssh);

      blob_appendf(&ssh,
         " -t -L 127.0.0.1:%d:127.0.0.1:%d %!$",
         iPort, iPort, zRemote
      );
      if( zFossilCmd==0 ){
        if( ssh_needs_path_argument(zRemote,-1) ^ isRetry ){
          ssh_add_path_argument(&ssh);
        }
        blob_append_escaped_arg(&ssh, "fossil", 1);
      }else{
        blob_appendf(&ssh, " %$", zFossilCmd);
      }
      blob_appendf(&ssh, " ui --nobrowser --localauth --port %d", iPort);
      if( zNotFound ) blob_appendf(&ssh, " --notfound %!$", zNotFound);
      if( zFileGlob ) blob_appendf(&ssh, " --files-urlenc %T", zFileGlob);
      if( g.zCkoutAlias ) blob_appendf(&ssh," --ckout-alias %!$",g.zCkoutAlias);
      if( g.zExtRoot ) blob_appendf(&ssh, " --extroot %$", g.zExtRoot);
      if( skin_in_use() ) blob_appendf(&ssh, " --skin %s", skin_in_use());
      if( zJsMode ) blob_appendf(&ssh, " --jsmode %s", zJsMode);
      if( fCreate ) blob_appendf(&ssh, " --create");
      blob_appendf(&ssh, " %$", g.argv[2]);
      if( isRetry ){
        fossil_print("First attempt to run \"fossil\" on %s failed\n"
                     "Retry: ", zRemote);
      } 
      fossil_print("%s\n", blob_str(&ssh));
      sshIn = popen(blob_str(&ssh), "r");
      if( sshIn==0 ){
        fossil_fatal("unable to %s", blob_str(&ssh));
      }
      while( fgets(zLine, sizeof(zLine), sshIn) ){
        fputs(zLine, stdout);
        fflush(stdout);
        if( !bRunning && sqlite3_strglob("*Listening for HTTP*",zLine)==0 ){
          bRunning = 1;
          if( isRetry ){
            ssh_needs_path_argument(zRemote,99);
          }
          db_close_config();
          if( zBrowserCmd ){
            char *zCmd = mprintf(zBrowserCmd/*works-like:"%d"*/,iPort);
            fossil_system(zCmd);
            fossil_free(zCmd);
            fossil_free(zBrowserCmd);
            zBrowserCmd = 0;
          }
        }
      }
      pclose(sshIn);
    }
    fossil_free(zBrowserCmd);
    return;
  }
  if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
  if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
  db_close(1);
#if !defined(_WIN32)