Fossil SCM

Modularize and enhance the file test commands.

mistachkin 2017-02-14 00:30 UTC symlinks
Commit 834a5b6189e633aefc1de7844354559707fe19a1
1 file changed +51 -41
+51 -41
--- src/file.c
+++ src/file.c
@@ -939,10 +939,54 @@
939939
}
940940
#endif
941941
blob_resize(pOut, file_simplify_name(blob_buffer(pOut),
942942
blob_size(pOut), slash));
943943
}
944
+
945
+/*
946
+** Emits the effective or raw stat() information for the specified
947
+** file or directory.
948
+*/
949
+static void emitFileStat(const char *zPath, int raw, int slash){
950
+ char zBuf[100];
951
+ Blob x;
952
+ memset(zBuf, 0, sizeof(zBuf));
953
+ blob_zero(&x);
954
+ file_canonical_name(zPath, &x, slash);
955
+ fossil_print("%s[%s] -> [%s]\n", raw ? "RAW " : "", zPath, blob_buffer(&x));
956
+ blob_reset(&x);
957
+ if( raw ){
958
+ int rc;
959
+ struct fossilStat testFileStat;
960
+ memset(&testFileStat, 0, sizeof(struct fossilStat));
961
+ rc = fossil_stat(zPath, &testFileStat, 0, 0);
962
+ fossil_print(" stat_rc = %d\n", rc);
963
+ sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_size);
964
+ fossil_print(" stat_size = %s\n", zBuf);
965
+ sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_mtime);
966
+ fossil_print(" stat_mtime = %s\n", zBuf);
967
+ fossil_print(" stat_mode = %d\n", testFileStat.st_mode);
968
+ memset(&testFileStat, 0, sizeof(struct fossilStat));
969
+ rc = fossil_stat(zPath, &testFileStat, 1, 1);
970
+ fossil_print(" l_stat_rc = %d\n", rc);
971
+ sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_size);
972
+ fossil_print(" l_stat_size = %s\n", zBuf);
973
+ sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_mtime);
974
+ fossil_print(" l_stat_mtime = %s\n", zBuf);
975
+ fossil_print(" l_stat_mode = %d\n", testFileStat.st_mode);
976
+ }else{
977
+ sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_size(zPath));
978
+ fossil_print(" file_size = %s\n", zBuf);
979
+ sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_mtime(zPath));
980
+ fossil_print(" file_mtime = %s\n", zBuf);
981
+ fossil_print(" file_isfile = %d\n", file_wd_isfile(zPath));
982
+ fossil_print(" file_isfile_or_link = %d\n",file_wd_isfile_or_link(zPath));
983
+ fossil_print(" file_islink = %d\n", file_wd_islink(zPath));
984
+ fossil_print(" file_isexe = %d\n", file_wd_isexe(zPath));
985
+ fossil_print(" file_isdir = %d\n", file_wd_isdir(zPath));
986
+ }
987
+}
944988
945989
/*
946990
** COMMAND: test-file-environment
947991
**
948992
** Usage: %fossil test-file-environment FILENAME...
@@ -955,48 +999,25 @@
955999
** --open-config Open the configuration database first.
9561000
** --slash Trailing slashes, if any, are retained.
9571001
*/
9581002
void cmd_test_file_environment(void){
9591003
int i;
960
- Blob x;
9611004
int slashFlag = find_option("slash",0,0)!=0;
9621005
if( find_option("open-config", 0, 0)!=0 ){
9631006
Th_OpenConfig(1);
9641007
}
965
- blob_zero(&x);
9661008
fossil_print("Th_IsRepositoryOpen() = %d\n", Th_IsRepositoryOpen());
9671009
fossil_print("Th_IsConfigOpen() = %d\n", Th_IsConfigOpen());
9681010
fossil_print("filenames_are_case_sensitive() = %d\n",
9691011
filenames_are_case_sensitive());
9701012
fossil_print("db_allow_symlinks_by_default() = %d\n",
9711013
db_allow_symlinks_by_default());
9721014
fossil_print("db_allow_symlinks(0) = %d\n", db_allow_symlinks(0));
9731015
fossil_print("db_allow_symlinks(1) = %d\n", db_allow_symlinks(1));
9741016
for(i=2; i<g.argc; i++){
975
- int rc;
976
- char zBuf[100];
977
- const char *zName = g.argv[i];
978
- struct fossilStat testFileStat;
979
- file_canonical_name(zName, &x, slashFlag);
980
- fossil_print("[%s] -> [%s]\n", zName, blob_buffer(&x));
981
- blob_reset(&x);
982
- memset(&testFileStat, 0, sizeof(struct fossilStat));
983
- rc = fossil_stat(zName, &testFileStat, 0, 0);
984
- fossil_print(" stat_rc = %d\n", rc);
985
- sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_size);
986
- fossil_print(" file_size = %s\n", zBuf);
987
- sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_mtime);
988
- fossil_print(" file_mtime = %s\n", zBuf);
989
- fossil_print(" file_mode = %d\n", testFileStat.st_mode);
990
- memset(&testFileStat, 0, sizeof(struct fossilStat));
991
- rc = fossil_stat(zName, &testFileStat, 1, 1);
992
- fossil_print(" l_stat_rc = %d\n", rc);
993
- sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_size);
994
- fossil_print(" l_file_size = %s\n", zBuf);
995
- sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_mtime);
996
- fossil_print(" l_file_mtime = %s\n", zBuf);
997
- fossil_print(" l_file_mode = %d\n", testFileStat.st_mode);
1017
+ emitFileStat(g.argv[i], 1, slashFlag);
1018
+ emitFileStat(g.argv[i], 0, slashFlag);
9981019
}
9991020
}
10001021
10011022
/*
10021023
** COMMAND: test-canonical-name
@@ -1006,32 +1027,21 @@
10061027
** Test the operation of the canonical name generator.
10071028
** Also test Fossil's ability to measure attributes of a file.
10081029
**
10091030
** Options:
10101031
**
1032
+** --open-config Open the configuration database first.
10111033
** --slash Trailing slashes, if any, are retained.
10121034
*/
10131035
void cmd_test_canonical_name(void){
10141036
int i;
1015
- Blob x;
10161037
int slashFlag = find_option("slash",0,0)!=0;
1017
- blob_zero(&x);
1038
+ if( find_option("open-config", 0, 0)!=0 ){
1039
+ Th_OpenConfig(1);
1040
+ }
10181041
for(i=2; i<g.argc; i++){
1019
- char zBuf[100];
1020
- const char *zName = g.argv[i];
1021
- file_canonical_name(zName, &x, slashFlag);
1022
- fossil_print("[%s] -> [%s]\n", zName, blob_buffer(&x));
1023
- blob_reset(&x);
1024
- sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_size(zName));
1025
- fossil_print(" file_size = %s\n", zBuf);
1026
- sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_mtime(zName));
1027
- fossil_print(" file_mtime = %s\n", zBuf);
1028
- fossil_print(" file_isfile = %d\n", file_wd_isfile(zName));
1029
- fossil_print(" file_isfile_or_link = %d\n",file_wd_isfile_or_link(zName));
1030
- fossil_print(" file_islink = %d\n", file_wd_islink(zName));
1031
- fossil_print(" file_isexe = %d\n", file_wd_isexe(zName));
1032
- fossil_print(" file_isdir = %d\n", file_wd_isdir(zName));
1042
+ emitFileStat(g.argv[i], 0, slashFlag);
10331043
}
10341044
}
10351045
10361046
/*
10371047
** Return TRUE if the given filename is canonical.
10381048
--- src/file.c
+++ src/file.c
@@ -939,10 +939,54 @@
939 }
940 #endif
941 blob_resize(pOut, file_simplify_name(blob_buffer(pOut),
942 blob_size(pOut), slash));
943 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
944
945 /*
946 ** COMMAND: test-file-environment
947 **
948 ** Usage: %fossil test-file-environment FILENAME...
@@ -955,48 +999,25 @@
955 ** --open-config Open the configuration database first.
956 ** --slash Trailing slashes, if any, are retained.
957 */
958 void cmd_test_file_environment(void){
959 int i;
960 Blob x;
961 int slashFlag = find_option("slash",0,0)!=0;
962 if( find_option("open-config", 0, 0)!=0 ){
963 Th_OpenConfig(1);
964 }
965 blob_zero(&x);
966 fossil_print("Th_IsRepositoryOpen() = %d\n", Th_IsRepositoryOpen());
967 fossil_print("Th_IsConfigOpen() = %d\n", Th_IsConfigOpen());
968 fossil_print("filenames_are_case_sensitive() = %d\n",
969 filenames_are_case_sensitive());
970 fossil_print("db_allow_symlinks_by_default() = %d\n",
971 db_allow_symlinks_by_default());
972 fossil_print("db_allow_symlinks(0) = %d\n", db_allow_symlinks(0));
973 fossil_print("db_allow_symlinks(1) = %d\n", db_allow_symlinks(1));
974 for(i=2; i<g.argc; i++){
975 int rc;
976 char zBuf[100];
977 const char *zName = g.argv[i];
978 struct fossilStat testFileStat;
979 file_canonical_name(zName, &x, slashFlag);
980 fossil_print("[%s] -> [%s]\n", zName, blob_buffer(&x));
981 blob_reset(&x);
982 memset(&testFileStat, 0, sizeof(struct fossilStat));
983 rc = fossil_stat(zName, &testFileStat, 0, 0);
984 fossil_print(" stat_rc = %d\n", rc);
985 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_size);
986 fossil_print(" file_size = %s\n", zBuf);
987 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_mtime);
988 fossil_print(" file_mtime = %s\n", zBuf);
989 fossil_print(" file_mode = %d\n", testFileStat.st_mode);
990 memset(&testFileStat, 0, sizeof(struct fossilStat));
991 rc = fossil_stat(zName, &testFileStat, 1, 1);
992 fossil_print(" l_stat_rc = %d\n", rc);
993 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_size);
994 fossil_print(" l_file_size = %s\n", zBuf);
995 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_mtime);
996 fossil_print(" l_file_mtime = %s\n", zBuf);
997 fossil_print(" l_file_mode = %d\n", testFileStat.st_mode);
998 }
999 }
1000
1001 /*
1002 ** COMMAND: test-canonical-name
@@ -1006,32 +1027,21 @@
1006 ** Test the operation of the canonical name generator.
1007 ** Also test Fossil's ability to measure attributes of a file.
1008 **
1009 ** Options:
1010 **
 
1011 ** --slash Trailing slashes, if any, are retained.
1012 */
1013 void cmd_test_canonical_name(void){
1014 int i;
1015 Blob x;
1016 int slashFlag = find_option("slash",0,0)!=0;
1017 blob_zero(&x);
 
 
1018 for(i=2; i<g.argc; i++){
1019 char zBuf[100];
1020 const char *zName = g.argv[i];
1021 file_canonical_name(zName, &x, slashFlag);
1022 fossil_print("[%s] -> [%s]\n", zName, blob_buffer(&x));
1023 blob_reset(&x);
1024 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_size(zName));
1025 fossil_print(" file_size = %s\n", zBuf);
1026 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_mtime(zName));
1027 fossil_print(" file_mtime = %s\n", zBuf);
1028 fossil_print(" file_isfile = %d\n", file_wd_isfile(zName));
1029 fossil_print(" file_isfile_or_link = %d\n",file_wd_isfile_or_link(zName));
1030 fossil_print(" file_islink = %d\n", file_wd_islink(zName));
1031 fossil_print(" file_isexe = %d\n", file_wd_isexe(zName));
1032 fossil_print(" file_isdir = %d\n", file_wd_isdir(zName));
1033 }
1034 }
1035
1036 /*
1037 ** Return TRUE if the given filename is canonical.
1038
--- src/file.c
+++ src/file.c
@@ -939,10 +939,54 @@
939 }
940 #endif
941 blob_resize(pOut, file_simplify_name(blob_buffer(pOut),
942 blob_size(pOut), slash));
943 }
944
945 /*
946 ** Emits the effective or raw stat() information for the specified
947 ** file or directory.
948 */
949 static void emitFileStat(const char *zPath, int raw, int slash){
950 char zBuf[100];
951 Blob x;
952 memset(zBuf, 0, sizeof(zBuf));
953 blob_zero(&x);
954 file_canonical_name(zPath, &x, slash);
955 fossil_print("%s[%s] -> [%s]\n", raw ? "RAW " : "", zPath, blob_buffer(&x));
956 blob_reset(&x);
957 if( raw ){
958 int rc;
959 struct fossilStat testFileStat;
960 memset(&testFileStat, 0, sizeof(struct fossilStat));
961 rc = fossil_stat(zPath, &testFileStat, 0, 0);
962 fossil_print(" stat_rc = %d\n", rc);
963 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_size);
964 fossil_print(" stat_size = %s\n", zBuf);
965 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_mtime);
966 fossil_print(" stat_mtime = %s\n", zBuf);
967 fossil_print(" stat_mode = %d\n", testFileStat.st_mode);
968 memset(&testFileStat, 0, sizeof(struct fossilStat));
969 rc = fossil_stat(zPath, &testFileStat, 1, 1);
970 fossil_print(" l_stat_rc = %d\n", rc);
971 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_size);
972 fossil_print(" l_stat_size = %s\n", zBuf);
973 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_mtime);
974 fossil_print(" l_stat_mtime = %s\n", zBuf);
975 fossil_print(" l_stat_mode = %d\n", testFileStat.st_mode);
976 }else{
977 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_size(zPath));
978 fossil_print(" file_size = %s\n", zBuf);
979 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_mtime(zPath));
980 fossil_print(" file_mtime = %s\n", zBuf);
981 fossil_print(" file_isfile = %d\n", file_wd_isfile(zPath));
982 fossil_print(" file_isfile_or_link = %d\n",file_wd_isfile_or_link(zPath));
983 fossil_print(" file_islink = %d\n", file_wd_islink(zPath));
984 fossil_print(" file_isexe = %d\n", file_wd_isexe(zPath));
985 fossil_print(" file_isdir = %d\n", file_wd_isdir(zPath));
986 }
987 }
988
989 /*
990 ** COMMAND: test-file-environment
991 **
992 ** Usage: %fossil test-file-environment FILENAME...
@@ -955,48 +999,25 @@
999 ** --open-config Open the configuration database first.
1000 ** --slash Trailing slashes, if any, are retained.
1001 */
1002 void cmd_test_file_environment(void){
1003 int i;
 
1004 int slashFlag = find_option("slash",0,0)!=0;
1005 if( find_option("open-config", 0, 0)!=0 ){
1006 Th_OpenConfig(1);
1007 }
 
1008 fossil_print("Th_IsRepositoryOpen() = %d\n", Th_IsRepositoryOpen());
1009 fossil_print("Th_IsConfigOpen() = %d\n", Th_IsConfigOpen());
1010 fossil_print("filenames_are_case_sensitive() = %d\n",
1011 filenames_are_case_sensitive());
1012 fossil_print("db_allow_symlinks_by_default() = %d\n",
1013 db_allow_symlinks_by_default());
1014 fossil_print("db_allow_symlinks(0) = %d\n", db_allow_symlinks(0));
1015 fossil_print("db_allow_symlinks(1) = %d\n", db_allow_symlinks(1));
1016 for(i=2; i<g.argc; i++){
1017 emitFileStat(g.argv[i], 1, slashFlag);
1018 emitFileStat(g.argv[i], 0, slashFlag);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1019 }
1020 }
1021
1022 /*
1023 ** COMMAND: test-canonical-name
@@ -1006,32 +1027,21 @@
1027 ** Test the operation of the canonical name generator.
1028 ** Also test Fossil's ability to measure attributes of a file.
1029 **
1030 ** Options:
1031 **
1032 ** --open-config Open the configuration database first.
1033 ** --slash Trailing slashes, if any, are retained.
1034 */
1035 void cmd_test_canonical_name(void){
1036 int i;
 
1037 int slashFlag = find_option("slash",0,0)!=0;
1038 if( find_option("open-config", 0, 0)!=0 ){
1039 Th_OpenConfig(1);
1040 }
1041 for(i=2; i<g.argc; i++){
1042 emitFileStat(g.argv[i], 0, slashFlag);
 
 
 
 
 
 
 
 
 
 
 
 
 
1043 }
1044 }
1045
1046 /*
1047 ** Return TRUE if the given filename is canonical.
1048

Keyboard Shortcuts

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