TEA (tclconfig) Source Code

Check-in [af56cbe24a]
Login

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

Overview
Comment:Separated the indexing of zip contents from the opening of the zip file stream
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | practcl
Files: files | file ages | folders
SHA3-256: af56cbe24a8b9f27ff1c98b824e079618d6484e6ac6455e057a09fbd15f5e165
User & Date: hypnotoad 2018-01-17 00:22:19.608
Context
2018-01-17
02:44
Modifications to the TEA zipfs implementation to index file systems by mount point. check-in: 02d71a5423 user: hypnotoad tags: practcl
00:22
Separated the indexing of zip contents from the opening of the zip file stream check-in: af56cbe24a user: hypnotoad tags: practcl
2018-01-16
23:27
New version of practcl.tcl from tcllib.

New version of the tclZipfs.c file. Now an identical file is checked into set core itself. check-in: 3785abe658 user: hypnotoad tags: practcl

Changes
Unified Diff Ignore Whitespace Patch
Changes to compat/tclZipfs.c.
938
939
940
941
942
943
944
945


































































































946
947
948
949
950
951
952
        zf->tofree = NULL;
    }
    if(zf->chan != NULL) {
        Tcl_Close(interp, zf->chan);
        zf->chan = NULL;
    }
}



































































































/*
 *-------------------------------------------------------------------------
 *
 * ZipFSOpenArchive --
 *
 *    This function opens a ZIP archive file for reading. An attempt
 *    is made to memory map that file. Otherwise it is read into







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
        zf->tofree = NULL;
    }
    if(zf->chan != NULL) {
        Tcl_Close(interp, zf->chan);
        zf->chan = NULL;
    }
}

/*
 *-------------------------------------------------------------------------
 *
 * ZipFSIndexArchive --
 *
 *   This function takes a memory mapped zip file and indexes the contents.
 *   When "needZip" is zero an embedded ZIP archive in an executable file is accepted.
 *
 * Results:
 *    TCL_OK on success, TCL_ERROR otherwise with an error message
 *    placed into the given "interp" if it is not NULL.
 *
 * Side effects:
 *    The given ZipFile struct is filled with information about the ZIP archive file.
 *
 *-------------------------------------------------------------------------
 */
static int
ZipFSIndexArchive(Tcl_Interp *interp, int needZip, ZipFile *zf)
{
    int i;
    unsigned char *p, *q;
    p = zf->data + zf->length - ZIP_CENTRAL_END_LEN;
    while (p >= zf->data) {
        if (*p == (ZIP_CENTRAL_END_SIG & 0xFF)) {
            if (zip_read_int(p) == ZIP_CENTRAL_END_SIG) {
            break;
            }
            p -= ZIP_SIG_LEN;
        } else {
            --p;
        }
    }
    if (p < zf->data) {
        if (!needZip) {
            zf->baseoffs = zf->baseoffsp = zf->length;
            return TCL_OK;
        }
        ZIPFS_ERROR(interp,"wrong end signature");
        goto error;
    }
    zf->nfiles = zip_read_short(p + ZIP_CENTRAL_ENTS_OFFS);
    if (zf->nfiles == 0) {
        if (!needZip) {
            zf->baseoffs = zf->baseoffsp = zf->length;
            return TCL_OK;
        }
        ZIPFS_ERROR(interp,"empty archive");
        goto error;
    }
    q = zf->data + zip_read_int(p + ZIP_CENTRAL_DIRSTART_OFFS);
    p -= zip_read_int(p + ZIP_CENTRAL_DIRSIZE_OFFS);
    if (
        (p < zf->data) || (p > (zf->data + zf->length)) ||
        (q < zf->data) || (q > (zf->data + zf->length))
    ) {
        if (!needZip) {
            zf->baseoffs = zf->baseoffsp = zf->length;
            return TCL_OK;
        }
        ZIPFS_ERROR(interp,"archive directory not found");
        goto error;
    }
    zf->baseoffs = zf->baseoffsp = p - q;
    zf->centoffs = p - zf->data;
    q = p;
    for (i = 0; i < zf->nfiles; i++) {
        int pathlen, comlen, extra;

        if ((q + ZIP_CENTRAL_HEADER_LEN) > (zf->data + zf->length)) {
            ZIPFS_ERROR(interp,"wrong header length");
            goto error;
        }
        if (zip_read_int(q) != ZIP_CENTRAL_HEADER_SIG) {
            ZIPFS_ERROR(interp,"wrong header signature");
            goto error;
        }
        pathlen = zip_read_short(q + ZIP_CENTRAL_PATHLEN_OFFS);
        comlen = zip_read_short(q + ZIP_CENTRAL_FCOMMENTLEN_OFFS);
        extra = zip_read_short(q + ZIP_CENTRAL_EXTRALEN_OFFS);
        q += pathlen + comlen + extra + ZIP_CENTRAL_HEADER_LEN;
    }
    q = zf->data + zf->baseoffs;
    if ((zf->baseoffs >= 6) && (zip_read_int(q - 4) == ZIP_PASSWORD_END_SIG)) {
        i = q[-5];
        if (q - 5 - i > zf->data) {
            zf->pwbuf[0] = i;
            memcpy(zf->pwbuf + 1, q - 5 - i, i);
            zf->baseoffsp -= i ? (5 + i) : 0;
        }
    }
    return TCL_OK;

error:
    ZipFSCloseArchive(interp, zf);
    return TCL_ERROR;
}

/*
 *-------------------------------------------------------------------------
 *
 * ZipFSOpenArchive --
 *
 *    This function opens a ZIP archive file for reading. An attempt
 *    is made to memory map that file. Otherwise it is read into
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
 *    the given ZipFile struct is filled with information about
 *    the ZIP archive file.
 *
 *-------------------------------------------------------------------------
 */

static int
ZipFSOpenArchive(Tcl_Interp *interp, const char *zipname, int needZip,
         ZipFile *zf)
{
    int i;
    ClientData handle;
    unsigned char *p, *q;

#if defined(_WIN32) || defined(_WIN64)
    zf->data = NULL;
    zf->mh = INVALID_HANDLE_VALUE;
#else
    zf->data = MAP_FAILED;
#endif







|
<



<







1061
1062
1063
1064
1065
1066
1067
1068

1069
1070
1071

1072
1073
1074
1075
1076
1077
1078
 *    the given ZipFile struct is filled with information about
 *    the ZIP archive file.
 *
 *-------------------------------------------------------------------------
 */

static int
ZipFSOpenArchive(Tcl_Interp *interp, const char *zipname, int needZip, ZipFile *zf)

{
    int i;
    ClientData handle;


#if defined(_WIN32) || defined(_WIN64)
    zf->data = NULL;
    zf->mh = INVALID_HANDLE_VALUE;
#else
    zf->data = MAP_FAILED;
#endif
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128

1129
1130
1131
1132
1133
1134
1135
                          (int) (long) handle, 0);
        if (zf->data == MAP_FAILED) {
            ZIPFS_ERROR(interp,"file mapping failed");
            goto error;
        }
#endif
    }
    p = zf->data + zf->length - ZIP_CENTRAL_END_LEN;
    while (p >= zf->data) {
        if (*p == (ZIP_CENTRAL_END_SIG & 0xFF)) {
            if (zip_read_int(p) == ZIP_CENTRAL_END_SIG) {
            break;
            }
            p -= ZIP_SIG_LEN;
        } else {
            --p;
        }
    }
    if (p < zf->data) {
        if (!needZip) {
            zf->baseoffs = zf->baseoffsp = zf->length;
            return TCL_OK;
        }
        ZIPFS_ERROR(interp,"wrong end signature");
        goto error;
    }
    zf->nfiles = zip_read_short(p + ZIP_CENTRAL_ENTS_OFFS);
    if (zf->nfiles == 0) {
        if (!needZip) {
            zf->baseoffs = zf->baseoffsp = zf->length;
            return TCL_OK;
        }
        ZIPFS_ERROR(interp,"empty archive");
        goto error;
    }
    q = zf->data + zip_read_int(p + ZIP_CENTRAL_DIRSTART_OFFS);
    p -= zip_read_int(p + ZIP_CENTRAL_DIRSIZE_OFFS);
    if (
        (p < zf->data) || (p > (zf->data + zf->length)) ||
        (q < zf->data) || (q > (zf->data + zf->length))
    ) {
        if (!needZip) {
            zf->baseoffs = zf->baseoffsp = zf->length;
            return TCL_OK;
        }
        ZIPFS_ERROR(interp,"archive directory not found");
        goto error;
    }
    zf->baseoffs = zf->baseoffsp = p - q;
    zf->centoffs = p - zf->data;
    q = p;
    for (i = 0; i < zf->nfiles; i++) {
        int pathlen, comlen, extra;

        if ((q + ZIP_CENTRAL_HEADER_LEN) > (zf->data + zf->length)) {
            ZIPFS_ERROR(interp,"wrong header length");
            goto error;
        }
        if (zip_read_int(q) != ZIP_CENTRAL_HEADER_SIG) {
            ZIPFS_ERROR(interp,"wrong header signature");
            goto error;
        }
        pathlen = zip_read_short(q + ZIP_CENTRAL_PATHLEN_OFFS);
        comlen = zip_read_short(q + ZIP_CENTRAL_FCOMMENTLEN_OFFS);
        extra = zip_read_short(q + ZIP_CENTRAL_EXTRALEN_OFFS);
        q += pathlen + comlen + extra + ZIP_CENTRAL_HEADER_LEN;
    }
    q = zf->data + zf->baseoffs;
    if ((zf->baseoffs >= 6) && (zip_read_int(q - 4) == ZIP_PASSWORD_END_SIG)) {
        i = q[-5];
        if (q - 5 - i > zf->data) {
            zf->pwbuf[0] = i;
            memcpy(zf->pwbuf + 1, q - 5 - i, i);
            zf->baseoffsp -= i ? (5 + i) : 0;
        }
    }
    return TCL_OK;

error:
    ZipFSCloseArchive(interp, zf);
    return TCL_ERROR;
}


static void TclZipfs_C_Init(void) {
    static const Tcl_Time t = { 0, 0 };
    if (!ZipFS.initialized) {
#ifdef TCL_THREADS
        /*
         * Inflate condition variable.







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




>







1143
1144
1145
1146
1147
1148
1149














































1150



1151




















1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
                          (int) (long) handle, 0);
        if (zf->data == MAP_FAILED) {
            ZIPFS_ERROR(interp,"file mapping failed");
            goto error;
        }
#endif
    }














































    return ZipFSIndexArchive(interp,needZip,zf);
























error:
    ZipFSCloseArchive(interp, zf);
    return TCL_ERROR;
}


static void TclZipfs_C_Init(void) {
    static const Tcl_Time t = { 0, 0 };
    if (!ZipFS.initialized) {
#ifdef TCL_THREADS
        /*
         * Inflate condition variable.
1162
1163
1164
1165
1166
1167
1168
1169

1170
1171
1172
1173
1174
1175
1176
 *    allocated.
 *
 *-------------------------------------------------------------------------
 */

int
TclZipfs_Mount(
    Tcl_Interp *interp, const char *zipname,

    const char *mntpt,
    const char *passwd
) {
    char *realname, *p;
    int i, pwlen, isNew;
    ZipFile *zf, zf0;
    ZipEntry *z;







|
>







1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
 *    allocated.
 *
 *-------------------------------------------------------------------------
 */

int
TclZipfs_Mount(
    Tcl_Interp *interp,
    const char *zipname,
    const char *mntpt,
    const char *passwd
) {
    char *realname, *p;
    int i, pwlen, isNew;
    ZipFile *zf, zf0;
    ZipEntry *z;