Skip to content

Commit 620ceca

Browse files
committed
Rename topdir -> submission_dir in chkentry
The tool is run on the submission directory that has the files that came from the topdir, not the topdir itself.
1 parent 0389c28 commit 620ceca

File tree

4 files changed

+73
-68
lines changed

4 files changed

+73
-68
lines changed

chkentry.c

+46-45
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static bool ignore_remarks_md = false; /* true ==> skip remarks.md check
6565
* Use the usage() function to print the usage_msg([0-9]?)+ strings.
6666
*/
6767
static const char * const usage_msg =
68-
"usage: %s [-h] [-v level] [-J level] [-V] [-q] [-i file] topdir\n"
68+
"usage: %s [-h] [-v level] [-J level] [-V] [-q] [-i file] submission_dir\n"
6969
"\n"
7070
"\t-h\t\tprint help message and exit\n"
7171
"\t-v level\tset verbosity level (def level: %d)\n"
@@ -174,29 +174,30 @@ usage(int exitcode, char const *prog, char const *str)
174174
* to know all the possible paths in a submission/entry, in those cases it must
175175
* be the exact path.
176176
*
177-
* NOTE: these paths are from UNDER the topdir. So if one has the file:
177+
* NOTE: these paths are from UNDER the submission directory. So if one has the
178+
* file:
178179
*
179-
* topdir/foo/bar/baz
180+
* submission_dir/foo/bar/baz
180181
*
181182
* and they run the command:
182183
*
183-
* chkentry topdir
184+
* chkentry submission_dir
184185
*
185186
* and want to ignore the path baz they should NOT do:
186187
*
187-
* chkentry -i topdir/foo/bar/baz topdir
188+
* chkentry -i submission_dir/foo/bar/baz submission_dir
188189
*
189190
* Rather they should do:
190191
*
191-
* chkentry -i foo/bar/baz topdir
192+
* chkentry -i foo/bar/baz submission_dir
192193
*
193194
* NOTE: this function uses the static char *abbrevs[][2] to find abbreviations.
194195
* In the case nothing is found then the path will be added to the list as is.
195196
*
196197
* NOTE: this function will not add a path to the array more than once so if you
197198
* were to do:
198199
*
199-
* chkentry -i foo -i foo topdir
200+
* chkentry -i foo -i foo submission_dir
200201
*
201202
* the ignored list would only have the path 'foo' once.
202203
*
@@ -577,7 +578,7 @@ int
577578
main(int argc, char *argv[])
578579
{
579580
char const *program = NULL; /* our name */
580-
char **topdir = NULL; /* directory from which files are to be checked */
581+
char **submission_dir = NULL; /* directory from which files are to be checked */
581582
extern char *optarg; /* option argument */
582583
extern int optind; /* argv index of the next arg */
583584
char const *auth_filename = "."; /* .auth.json file to process, or NULL ==> no .auth.json to process */
@@ -694,7 +695,7 @@ main(int argc, char *argv[])
694695
argv += optind;
695696
switch (argc) {
696697
case 1:
697-
topdir = argv;
698+
submission_dir = argv;
698699
break;
699700
case 2:
700701
if (!strcmp(argv[0], ".") && !strcmp(argv[1], ".")) {
@@ -708,20 +709,20 @@ main(int argc, char *argv[])
708709
break;
709710
}
710711

711-
if (topdir != NULL && *topdir != NULL) {
712+
if (submission_dir != NULL && *submission_dir != NULL) {
712713
/*
713714
* check if we can search / work within the directory
714715
*/
715-
if (!exists(*topdir)) {
716-
err(56, __func__, "directory does not exist: %s", *topdir);
716+
if (!exists(*submission_dir)) {
717+
err(56, __func__, "directory does not exist: %s", *submission_dir);
717718
not_reached();
718719
}
719-
if (!is_dir(*topdir)) {
720-
err(57, __func__, "is not a directory: %s", *topdir);
720+
if (!is_dir(*submission_dir)) {
721+
err(57, __func__, "is not a directory: %s", *submission_dir);
721722
not_reached();
722723
}
723-
if (!is_exec(*topdir)) {
724-
err(58, __func__, "directory is not searchable: %s", *topdir);
724+
if (!is_exec(*submission_dir)) {
725+
err(58, __func__, "directory is not searchable: %s", *submission_dir);
725726
not_reached();
726727
}
727728

@@ -743,7 +744,7 @@ main(int argc, char *argv[])
743744
* make sure .entry.json exists unless -i entry
744745
*/
745746
if (!ignore_entry) {
746-
path = find_path(ENTRY_JSON_FILENAME, *topdir, -1, &cwd, false, &fts);
747+
path = find_path(ENTRY_JSON_FILENAME, *submission_dir, -1, &cwd, false, &fts);
747748
if (path == NULL) {
748749
dbg(DBG_LOW, "file does NOT exist and -w USED and -i entry NOT used: %s", ENTRY_JSON_FILENAME);
749750
++all_extra_err_count;
@@ -769,7 +770,7 @@ main(int argc, char *argv[])
769770
* unless -i auth .auth.json must NOT exist
770771
*/
771772
if (!ignore_auth) {
772-
path = find_path(AUTH_JSON_FILENAME, *topdir, -1, &cwd, false, &fts);
773+
path = find_path(AUTH_JSON_FILENAME, *submission_dir, -1, &cwd, false, &fts);
773774
if (path != NULL) {
774775
dbg(DBG_LOW, "file EXISTS and -w USED and -i auth NOT used: %s", AUTH_JSON_FILENAME);
775776
++all_extra_err_count;
@@ -789,7 +790,7 @@ main(int argc, char *argv[])
789790
/*
790791
* .info.json
791792
*/
792-
path = find_path(INFO_JSON_FILENAME, *topdir, -1, &cwd, false, &fts);
793+
path = find_path(INFO_JSON_FILENAME, *submission_dir, -1, &cwd, false, &fts);
793794
if (path != NULL) {
794795
dbg(DBG_LOW, "file EXISTS and -w USED and -i info NOT used: %s", INFO_JSON_FILENAME);
795796
++all_extra_err_count;
@@ -809,7 +810,7 @@ main(int argc, char *argv[])
809810
/*
810811
* README.md
811812
*/
812-
path = find_path(README_MD_FILENAME, *topdir, -1, &cwd, false, &fts);
813+
path = find_path(README_MD_FILENAME, *submission_dir, -1, &cwd, false, &fts);
813814
if (path == NULL) {
814815
dbg(DBG_LOW, "file does NOT exist and -w USED and -i README NOT used: %s", README_MD_FILENAME);
815816
++all_extra_err_count;
@@ -837,7 +838,7 @@ main(int argc, char *argv[])
837838
/*
838839
* index.html
839840
*/
840-
path = find_path(INDEX_HTML_FILENAME, *topdir, -1, &cwd, false, &fts);
841+
path = find_path(INDEX_HTML_FILENAME, *submission_dir, -1, &cwd, false, &fts);
841842
if (path == NULL) {
842843
dbg(DBG_LOW, "file does NOT exist and -w USED and -i index NOT used: %s", INDEX_HTML_FILENAME);
843844
++all_extra_err_count;
@@ -866,7 +867,7 @@ main(int argc, char *argv[])
866867
/*
867868
* Makefile
868869
*/
869-
path = find_path(MAKEFILE_FILENAME, *topdir, -1, &cwd, false, &fts);
870+
path = find_path(MAKEFILE_FILENAME, *submission_dir, -1, &cwd, false, &fts);
870871
if (path == NULL) {
871872
dbg(DBG_LOW, "%s does not exist and -w used and -i Makefile not used", MAKEFILE_FILENAME);
872873
++all_extra_err_count;
@@ -894,7 +895,7 @@ main(int argc, char *argv[])
894895
/*
895896
* prog.c
896897
*/
897-
path = find_path(PROG_C_FILENAME, *topdir, -1, &cwd, false, &fts);
898+
path = find_path(PROG_C_FILENAME, *submission_dir, -1, &cwd, false, &fts);
898899
if (path == NULL) {
899900
dbg(DBG_LOW, "%s does not exist and -w used and -i prog.c not used", PROG_C_FILENAME);
900901
++all_extra_err_count;
@@ -922,7 +923,7 @@ main(int argc, char *argv[])
922923
/*
923924
* prog
924925
*/
925-
path = find_path(PROG_FILENAME, *topdir, -1, &cwd, false, &fts);
926+
path = find_path(PROG_FILENAME, *submission_dir, -1, &cwd, false, &fts);
926927
if (path != NULL) {
927928
dbg(DBG_LOW, "%s exists and -w used and -i prog not used", PROG_FILENAME);
928929
++all_extra_err_count;
@@ -942,7 +943,7 @@ main(int argc, char *argv[])
942943
/*
943944
* remarks.md
944945
*/
945-
path = find_path(REMARKS_FILENAME, *topdir, -1, &cwd, false, &fts);
946+
path = find_path(REMARKS_FILENAME, *submission_dir, -1, &cwd, false, &fts);
946947
if (path != NULL) {
947948
dbg(DBG_LOW, "%s exists and -w used and -i remarks not used", REMARKS_FILENAME);
948949
++all_extra_err_count;
@@ -968,7 +969,7 @@ main(int argc, char *argv[])
968969
* list of paths to ignore is already in the fts->ignore list we
969970
* don't need to do anything special.
970971
*/
971-
found = find_paths(paths, *topdir, -1, &cwd, false, &fts);
972+
found = find_paths(paths, *submission_dir, -1, &cwd, false, &fts);
972973
if (found != NULL) {
973974
/*
974975
* case: files were found, check that they are both allowed and
@@ -1051,7 +1052,7 @@ main(int argc, char *argv[])
10511052
* make sure .entry.json does NOT exist unless -i entry
10521053
*/
10531054
if (!ignore_entry) {
1054-
path = find_path(ENTRY_JSON_FILENAME, *topdir, -1, &cwd, false, &fts);
1055+
path = find_path(ENTRY_JSON_FILENAME, *submission_dir, -1, &cwd, false, &fts);
10551056
if (path != NULL) {
10561057
dbg(DBG_LOW, "%s exists and -w and -i entry not used and ", ENTRY_JSON_FILENAME);
10571058
++all_extra_err_count;
@@ -1069,7 +1070,7 @@ main(int argc, char *argv[])
10691070
* unless -i auth .auth.json MUST exist
10701071
*/
10711072
if (!ignore_auth) {
1072-
path = find_path(AUTH_JSON_FILENAME, *topdir, -1, &cwd, false, &fts);
1073+
path = find_path(AUTH_JSON_FILENAME, *submission_dir, -1, &cwd, false, &fts);
10731074
if (path == NULL) {
10741075
dbg(DBG_LOW, "%s does not exist and -i auth not used", AUTH_JSON_FILENAME);
10751076
++all_extra_err_count;
@@ -1097,7 +1098,7 @@ main(int argc, char *argv[])
10971098
/*
10981099
* .info.json
10991100
*/
1100-
path = find_path(INFO_JSON_FILENAME, *topdir, -1, &cwd, false, &fts);
1101+
path = find_path(INFO_JSON_FILENAME, *submission_dir, -1, &cwd, false, &fts);
11011102
if (path == NULL) {
11021103
dbg(DBG_LOW, "%s does not exist and -i info not used", INFO_JSON_FILENAME);
11031104
++all_extra_err_count;
@@ -1125,7 +1126,7 @@ main(int argc, char *argv[])
11251126
/*
11261127
* README.md
11271128
*/
1128-
path = find_path(README_MD_FILENAME, *topdir, -1, &cwd, false, &fts);
1129+
path = find_path(README_MD_FILENAME, *submission_dir, -1, &cwd, false, &fts);
11291130
if (path != NULL) {
11301131
dbg(DBG_LOW, "%s exists and -i README not used", README_MD_FILENAME);
11311132
++all_extra_err_count;
@@ -1145,7 +1146,7 @@ main(int argc, char *argv[])
11451146
/*
11461147
* index.html
11471148
*/
1148-
path = find_path(INDEX_HTML_FILENAME, *topdir, -1, &cwd, false, &fts);
1149+
path = find_path(INDEX_HTML_FILENAME, *submission_dir, -1, &cwd, false, &fts);
11491150
if (path != NULL) {
11501151
dbg(DBG_LOW, "%s exists and -i index not used", INDEX_HTML_FILENAME);
11511152
++all_extra_err_count;
@@ -1166,7 +1167,7 @@ main(int argc, char *argv[])
11661167
/*
11671168
* Makefile
11681169
*/
1169-
path = find_path(MAKEFILE_FILENAME, *topdir, -1, &cwd, false, &fts);
1170+
path = find_path(MAKEFILE_FILENAME, *submission_dir, -1, &cwd, false, &fts);
11701171
if (path == NULL) {
11711172
dbg(DBG_LOW, "%s does not exist and -i Makefile not used", MAKEFILE_FILENAME);
11721173
++all_extra_err_count;
@@ -1194,7 +1195,7 @@ main(int argc, char *argv[])
11941195
/*
11951196
* prog.c
11961197
*/
1197-
path = find_path(PROG_C_FILENAME, *topdir, -1, &cwd, false, &fts);
1198+
path = find_path(PROG_C_FILENAME, *submission_dir, -1, &cwd, false, &fts);
11981199
if (path == NULL) {
11991200
dbg(DBG_LOW, "%s does not exist and -i prog.c not used", PROG_C_FILENAME);
12001201
++all_extra_err_count;
@@ -1222,7 +1223,7 @@ main(int argc, char *argv[])
12221223
/*
12231224
* prog
12241225
*/
1225-
path = find_path(PROG_FILENAME, *topdir, -1, &cwd, false, &fts);
1226+
path = find_path(PROG_FILENAME, *submission_dir, -1, &cwd, false, &fts);
12261227
if (path != NULL) {
12271228
dbg(DBG_LOW, "%s exists and -i prog not used", PROG_FILENAME);
12281229
++all_extra_err_count;
@@ -1242,7 +1243,7 @@ main(int argc, char *argv[])
12421243
/*
12431244
* remarks.md
12441245
*/
1245-
path = find_path(REMARKS_FILENAME, *topdir, -1, &cwd, false, &fts);
1246+
path = find_path(REMARKS_FILENAME, *submission_dir, -1, &cwd, false, &fts);
12461247
if (path == NULL) {
12471248
dbg(DBG_LOW, "%s does not exist and -i remarks not used", REMARKS_FILENAME);
12481249
++all_extra_err_count;
@@ -1275,7 +1276,7 @@ main(int argc, char *argv[])
12751276
* list of paths to ignore is already in the fts->ignore list we
12761277
* don't need to do anything special.
12771278
*/
1278-
found = find_paths(paths, *topdir, -1, &cwd, false, &fts);
1279+
found = find_paths(paths, *submission_dir, -1, &cwd, false, &fts);
12791280
if (found != NULL) {
12801281
/*
12811282
* case: files were found, check that they are both allowed and
@@ -1350,33 +1351,33 @@ main(int argc, char *argv[])
13501351
}
13511352

13521353
/*
1353-
* open the .auth.json file under topdir if !ignore_auth && -w not used
1354+
* open the .auth.json file under submission_dir if !ignore_auth && -w not used
13541355
*/
13551356
if (!ignore_auth && !winning_entry_mode) {
13561357
auth_filename = ".auth.json";
1357-
auth_stream = open_dir_file(*topdir, auth_filename);
1358+
auth_stream = open_dir_file(*submission_dir, auth_filename);
13581359
if (auth_stream == NULL) { /* paranoia */
1359-
err(63, __func__, "auth_stream = open_dir_file(%s, %s) returned NULL", *topdir, auth_filename);
1360+
err(63, __func__, "auth_stream = open_dir_file(%s, %s) returned NULL", *submission_dir, auth_filename);
13601361
not_reached();
13611362
}
1362-
auth_path = calloc_path(*topdir, auth_filename);
1363+
auth_path = calloc_path(*submission_dir, auth_filename);
13631364
if (auth_path == NULL) {
13641365
err(64, __func__, "auth_path is NULL");
13651366
not_reached();
13661367
}
13671368
}
13681369

13691370
/*
1370-
* open the .info.json file under topdir if !ignore_info and -w not used
1371+
* open the .info.json file under submission_dir if !ignore_info and -w not used
13711372
*/
13721373
if (!ignore_info && !winning_entry_mode) {
13731374
info_filename = ".info.json";
1374-
info_stream = open_dir_file(*topdir, info_filename);
1375+
info_stream = open_dir_file(*submission_dir, info_filename);
13751376
if (info_stream == NULL) { /* paranoia */
1376-
err(65, __func__, "info_stream = open_dir_file(%s, %s) returned NULL", *topdir, info_filename);
1377+
err(65, __func__, "info_stream = open_dir_file(%s, %s) returned NULL", *submission_dir, info_filename);
13771378
not_reached();
13781379
}
1379-
info_path = calloc_path(*topdir, info_filename);
1380+
info_path = calloc_path(*submission_dir, info_filename);
13801381
if (info_path == NULL) {
13811382
err(66, __func__, "info_path is NULL");
13821383
not_reached();
@@ -1461,7 +1462,7 @@ main(int argc, char *argv[])
14611462
*/
14621463
dbg(DBG_HIGH, "about to perform JSON semantic check for .info.json file: %s", info_path);
14631464
info_all_err_count = json_sem_check(info_tree, JSON_DEFAULT_MAX_DEPTH, sem_info,
1464-
&info_count_err, &info_val_err, *topdir);
1465+
&info_count_err, &info_val_err, *submission_dir);
14651466

14661467
/*
14671468
* firewall on json_sem_check() results AND count errors for .info.json

0 commit comments

Comments
 (0)