From: drh <> Date: Thu, 2 Oct 2025 18:31:19 +0000 (+0000) Subject: In the ".open" command of the CLI if using the --new option with a URI X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4defad2f298af3f2682af25863190611c5950754;p=thirdparty%2Fsqlite.git In the ".open" command of the CLI if using the --new option with a URI filename, then decode the URI to extract the actual filename prior to trying to delete that file. FossilOrigin-Name: 14ee3c1f03de274e5fa1efb471816a0001762623614253c24d58f41ea6af0628 --- diff --git a/manifest b/manifest index 1f3d9dc0b1..f779a911b5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\s-DSQLITE_OS_OTHER=0\sbuilds. -D 2025-10-02T14:48:27.422 +C In\sthe\s".open"\scommand\sof\sthe\sCLI\sif\susing\sthe\s--new\soption\swith\sa\sURI\nfilename,\sthen\sdecode\sthe\sURI\sto\sextract\sthe\sactual\sfilename\sprior\sto\ntrying\sto\sdelete\sthat\sfile. +D 2025-10-02T18:31:19.026 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -737,7 +737,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c f8d1d011aba0964ff1bdccd049d4d2c2fec217efd90d202a4bb775e926b2c25d F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c b95181711d59c36d9789e67f76c4cfec64b99f9629a50be5e6566e117b87d957 -F src/shell.c.in 9cfc941ea2068076bb54b10b7c18c2958bda29e9d6aa2d0e807bf4af29a8ac05 +F src/shell.c.in cb057f99dbc549ba2524b81243076d1f438403f70a7ed761ce778ae59028c0c6 F src/sqlite.h.in 5732519a2acb09066032ceac21f25996eb3f28f807a4468e30633c7c70faae1c F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479 F src/sqlite3ext.h 3f0c4ed6934e7309a61c6f3c30f70a30a5b869f785bb3d9f721a36c5e4359126 @@ -2169,8 +2169,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7 F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 22b2700ac20bb8e5883d484bfd0aee7a0fbc99b92696d8ca850cd129e2ccbb43 -R 399a433d692825e6557f7aa80a566057 -U dan -Z 1d09f435c80c1e511337c9686eefb17c +P 2971d7470110fcd43bdc8ad5d09d1f2f63f5a3bccda41810948a683e310ad908 +R 336d33ed228557f8a4572eff7757820f +U drh +Z 771c3346d655dc279ea944b772a8bb1f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d2a50cbd98..ec565c95f4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2971d7470110fcd43bdc8ad5d09d1f2f63f5a3bccda41810948a683e310ad908 +14ee3c1f03de274e5fa1efb471816a0001762623614253c24d58f41ea6af0628 diff --git a/src/shell.c.in b/src/shell.c.in index 26c0e14c37..30521a5689 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -7088,6 +7088,43 @@ static int optionMatch(const char *zStr, const char *zOpt){ return cli_strcmp(zStr, zOpt)==0; } +/* +** The input zFN is guaranteed to start with "file:" and is thus a URI +** filename. Extract the actual filename and return a pointer to that +** filename in spaced obtained from sqlite3_malloc(). +** +** The caller is responsible for freeing space using sqlite3_free() when +** it has finished with the filename. +*/ +static char *shellFilenameFromUri(const char *zFN){ + char *zOut; + int i, j, d1, d2; + + assert( cli_strncmp(zFN,"file:",5)==0 ); + zOut = sqlite3_mprintf("%s", zFN+5); + shell_check_oom(zOut); + for(i=j=0; zOut[i]!=0 && zOut[i]!='?'; i++){ + if( zOut[i]!='%' ){ + zOut[j++] = zOut[i]; + continue; + } + d1 = hexDigitValue(zOut[i+1]); + if( d1<0 ){ + zOut[j] = 0; + break; + } + d2 = hexDigitValue(zOut[i+2]); + if( d2<0 ){ + zOut[j] = 0; + break; + } + zOut[j++] = d1*16 + d2; + i += 2; + } + zOut[j] = 0; + return zOut; +} + /* ** Delete a file. */ @@ -10271,7 +10308,16 @@ static int do_meta_command(char *zLine, ShellState *p){ /* If a filename is specified, try to open it first */ if( zFN || p->openMode==SHELL_OPEN_HEXDB ){ - if( newFlag && zFN && !p->bSafeMode ) shellDeleteFile(zFN); + if( newFlag && zFN && !p->bSafeMode ){ + if( cli_strncmp(zFN,"file:",5)==0 ){ + char *zDel = shellFilenameFromUri(zFN); + shell_check_oom(zDel); + shellDeleteFile(zDel); + sqlite3_free(zDel); + }else{ + shellDeleteFile(zFN); + } + } #ifndef SQLITE_SHELL_FIDDLE if( p->bSafeMode && p->openMode!=SHELL_OPEN_HEXDB