| | @@ -437,10 +437,29 @@ |
| 437 | 437 | return mprintf("%.*s", (int)(zTail-z-1), z); |
| 438 | 438 | }else{ |
| 439 | 439 | return 0; |
| 440 | 440 | } |
| 441 | 441 | } |
| 442 | + |
| 443 | +/* SQL Function: file_dirname(NAME) |
| 444 | +** |
| 445 | +** Return the directory for NAME |
| 446 | +*/ |
| 447 | +void file_dirname_sql_function( |
| 448 | + sqlite3_context *context, |
| 449 | + int argc, |
| 450 | + sqlite3_value **argv |
| 451 | +){ |
| 452 | + const char *zName = (const char*)sqlite3_value_text(argv[0]); |
| 453 | + char *zDir; |
| 454 | + if( zName==0 ) return; |
| 455 | + zDir = file_dirname(zName); |
| 456 | + if( zDir ){ |
| 457 | + sqlite3_result_text(context,zDir,-1,fossil_free); |
| 458 | + } |
| 459 | +} |
| 460 | + |
| 442 | 461 | |
| 443 | 462 | /* |
| 444 | 463 | ** Rename a file or directory. |
| 445 | 464 | ** Returns zero upon success. |
| 446 | 465 | */ |
| | @@ -594,10 +613,30 @@ |
| 594 | 613 | rc = unlink(zFilename); |
| 595 | 614 | #endif |
| 596 | 615 | fossil_path_free(z); |
| 597 | 616 | return rc; |
| 598 | 617 | } |
| 618 | + |
| 619 | +/* SQL Function: file_delete(NAME) |
| 620 | +** |
| 621 | +** Remove file NAME. Return zero on success and non-zero if anything goes |
| 622 | +** wrong. |
| 623 | +*/ |
| 624 | +void file_delete_sql_function( |
| 625 | + sqlite3_context *context, |
| 626 | + int argc, |
| 627 | + sqlite3_value **argv |
| 628 | +){ |
| 629 | + const char *zName = (const char*)sqlite3_value_text(argv[0]); |
| 630 | + int rc; |
| 631 | + if( zName==0 ){ |
| 632 | + rc = 1; |
| 633 | + }else{ |
| 634 | + rc = file_delete(zName); |
| 635 | + } |
| 636 | + sqlite3_result_int(context, rc); |
| 637 | +} |
| 599 | 638 | |
| 600 | 639 | /* |
| 601 | 640 | ** Create a directory called zName, if it does not already exist. |
| 602 | 641 | ** If forceFlag is 1, delete any prior non-directory object |
| 603 | 642 | ** with the same name. |
| | @@ -910,12 +949,20 @@ |
| 910 | 949 | ** Get the current working directory. |
| 911 | 950 | ** |
| 912 | 951 | ** On windows, the name is converted from unicode to UTF8 and all '\\' |
| 913 | 952 | ** characters are converted to '/'. No conversions are needed on |
| 914 | 953 | ** unix. |
| 954 | +** |
| 955 | +** Store the value of the CWD in zBuf which is nBuf bytes in size. |
| 956 | +** or if zBuf==0, allocate space to hold the result using fossil_malloc(). |
| 915 | 957 | */ |
| 916 | | -void file_getcwd(char *zBuf, int nBuf){ |
| 958 | +char *file_getcwd(char *zBuf, int nBuf){ |
| 959 | + char zTemp[2000]; |
| 960 | + if( zBuf==0 ){ |
| 961 | + zBuf = zTemp; |
| 962 | + nBuf = sizeof(zTemp); |
| 963 | + } |
| 917 | 964 | #ifdef _WIN32 |
| 918 | 965 | win32_getcwd(zBuf, nBuf); |
| 919 | 966 | #else |
| 920 | 967 | if( getcwd(zBuf, nBuf-1)==0 ){ |
| 921 | 968 | if( errno==ERANGE ){ |
| | @@ -924,10 +971,11 @@ |
| 924 | 971 | fossil_panic("cannot find current working directory; %s", |
| 925 | 972 | strerror(errno)); |
| 926 | 973 | } |
| 927 | 974 | } |
| 928 | 975 | #endif |
| 976 | + return zBuf==zTemp ? fossil_strdup(zBuf) : zBuf; |
| 929 | 977 | } |
| 930 | 978 | |
| 931 | 979 | /* |
| 932 | 980 | ** Return true if zPath is an absolute pathname. Return false |
| 933 | 981 | ** if it is relative. |
| 934 | 982 | |