summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorapnadkarni <apnmbx-wits@yahoo.com>2023-10-04 12:57:08 (GMT)
committerapnadkarni <apnmbx-wits@yahoo.com>2023-10-04 12:57:08 (GMT)
commit36db68b9d446670328287e35e8959adf3f555bc0 (patch)
tree56c27c7a9e7c722a7e9443284ae70ef5fad90d48
parent0dc647a301ee262934691ac630a1f16f1891ea12 (diff)
downloadtcl-36db68b9d446670328287e35e8959adf3f555bc0.zip
tcl-36db68b9d446670328287e35e8959adf3f555bc0.tar.gz
tcl-36db68b9d446670328287e35e8959adf3f555bc0.tar.bz2
Update tests for zipfs append.
-rw-r--r--generic/tclZipfs.c43
-rw-r--r--tests/zipfs.test12
2 files changed, 28 insertions, 27 deletions
diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c
index b223306..cd75e67 100644
--- a/generic/tclZipfs.c
+++ b/generic/tclZipfs.c
@@ -251,8 +251,7 @@ typedef struct ZipChannel {
ZipEntry *zipEntryPtr; /* Pointer back to virtual file */
size_t maxWrite; /* Maximum size for write */
size_t numBytes; /* Number of bytes of uncompressed data */
- size_t numRead; /* Position of next byte to be read from the
- * channel */
+ size_t cursor; /* Seek position for next read or write*/
unsigned char *ubuf; /* Pointer to the uncompressed data */
unsigned char *ubufToFree; /* NULL if ubuf points to memory that does not
need freeing. Else memory to free (ubuf
@@ -4431,16 +4430,16 @@ ZipChannelRead(
* data in front of ZIP, i.e. the executable itself.
*/
- nextpos = info->numRead + toRead;
+ nextpos = info->cursor + toRead;
if (nextpos > info->zipFilePtr->baseOffset) {
- toRead = info->zipFilePtr->baseOffset - info->numRead;
+ toRead = info->zipFilePtr->baseOffset - info->cursor;
nextpos = info->zipFilePtr->baseOffset;
}
if (toRead == 0) {
return 0;
}
memcpy(buf, info->zipFilePtr->data, toRead);
- info->numRead = nextpos;
+ info->cursor = nextpos;
*errloc = 0;
return toRead;
}
@@ -4448,9 +4447,9 @@ ZipChannelRead(
*errloc = EISDIR;
return -1;
}
- nextpos = info->numRead + toRead;
+ nextpos = info->cursor + toRead;
if (nextpos > info->numBytes) {
- toRead = info->numBytes - info->numRead;
+ toRead = info->numBytes - info->cursor;
nextpos = info->numBytes;
}
if (toRead == 0) {
@@ -4460,14 +4459,14 @@ ZipChannelRead(
int i;
for (i = 0; i < toRead; i++) {
- int ch = info->ubuf[i + info->numRead];
+ int ch = info->ubuf[i + info->cursor];
buf[i] = zdecode(info->keys, crc32tab, ch);
}
} else {
- memcpy(buf, info->ubuf + info->numRead, toRead);
+ memcpy(buf, info->ubuf + info->cursor, toRead);
}
- info->numRead = nextpos;
+ info->cursor = nextpos;
*errloc = 0;
return toRead;
}
@@ -4503,23 +4502,23 @@ ZipChannelWrite(
return -1;
}
if (info->mode & O_APPEND) {
- info->numRead = info->numBytes;
+ info->cursor = info->numBytes;
}
if (toWrite == 0) {
*errloc = 0;
return 0;
}
- assert(info->maxWrite >= info->numRead);
- if (toWrite > (int) (info->maxWrite - info->numRead)) {
+ assert(info->maxWrite >= info->cursor);
+ if (toWrite > (int) (info->maxWrite - info->cursor)) {
/* Don't do partial writes in error case. Or should we? */
*errloc = EFBIG;
return -1;
}
- nextpos = info->numRead + toWrite;
- memcpy(info->ubuf + info->numRead, buf, toWrite);
- info->numRead = nextpos;
- if (info->numRead > info->numBytes) {
- info->numBytes = info->numRead;
+ nextpos = info->cursor + toWrite;
+ memcpy(info->ubuf + info->cursor, buf, toWrite);
+ info->cursor = nextpos;
+ if (info->cursor > info->numBytes) {
+ info->numBytes = info->cursor;
}
*errloc = 0;
return toWrite;
@@ -4565,7 +4564,7 @@ ZipChannelWideSeek(
}
switch (mode) {
case SEEK_CUR:
- offset += info->numRead;
+ offset += info->cursor;
break;
case SEEK_END:
offset += end;
@@ -4592,8 +4591,8 @@ ZipChannelWideSeek(
*errloc = EINVAL;
return -1;
}
- info->numRead = (size_t) offset;
- return info->numRead;
+ info->cursor = (size_t) offset;
+ return info->cursor;
}
#if !defined(TCL_NO_DEPRECATED) && (TCL_MAJOR_VERSION < 9)
@@ -5003,7 +5002,7 @@ InitWritableChannel(
memset(info->keys, 0, sizeof(info->keys));
}
if (mode & O_APPEND) {
- info->numRead = info->numBytes;
+ info->cursor = info->numBytes;
}
assert(info->numBytes == 0 || (int)info->numBytes == z->numBytes);
diff --git a/tests/zipfs.test b/tests/zipfs.test
index d652f05..046e3b5 100644
--- a/tests/zipfs.test
+++ b/tests/zipfs.test
@@ -1007,7 +1007,9 @@ namespace eval test_ns_zipfs {
set body {
set fd [open $path $mode]
fconfigure $fd -translation binary
- puts -nonewline $fd "xyz"
+ puts -nonewline $fd XYZ
+ seek $fd 0
+ puts -nonewline $fd xyz
close $fd
set fd [open $path]
fconfigure $fd -translation binary
@@ -1045,10 +1047,10 @@ namespace eval test_ns_zipfs {
testzipfswrite deflate-w testdeflated2.zip "xyz" abac-repeat.txt w
testzipfswrite store-w+ teststored.zip "xyz" abac-repeat.txt w+
testzipfswrite deflate-w+ testdeflated2.zip "xyz" abac-repeat.txt w+
- testzipfswrite stored-a teststored.zip "append mode not supported: permission denied" abac-repeat.txt a -returnCodes error
- testzipfswrite deflate-a testdeflated2.zip "append mode not supported: permission denied" abac-repeat.txt a -returnCodes error
- testzipfswrite store-a+ teststored.zip "aaaaaaaaaaaaaa\nbbbbbbbbbbbbbb\naaaaaaaaaaaaaa\ncccccccccccccc\nxyz" abac-repeat.txt a+
- testzipfswrite deflate-a+ testdeflated2.zip "aaaaaaaaaaaaaa\nbbbbbbbbbbbbbb\naaaaaaaaaaaaaa\ncccccccccccccc\nxyz" abac-repeat.txt a+
+ testzipfswrite stored-a teststored.zip "aaaaaaaaaaaaaa\nbbbbbbbbbbbbbb\naaaaaaaaaaaaaa\ncccccccccccccc\nXYZxyz" abac-repeat.txt a
+ testzipfswrite deflate-a testdeflated2.zip "aaaaaaaaaaaaaa\nbbbbbbbbbbbbbb\naaaaaaaaaaaaaa\ncccccccccccccc\nXYZxyz" abac-repeat.txt a
+ testzipfswrite store-a+ teststored.zip "xyzaaaaaaaaaaa\nbbbbbbbbbbbbbb\naaaaaaaaaaaaaa\ncccccccccccccc\nXYZ" abac-repeat.txt a+
+ testzipfswrite deflate-a+ testdeflated2.zip "xyzaaaaaaaaaaa\nbbbbbbbbbbbbbb\naaaaaaaaaaaaaa\ncccccccccccccc\nXYZ" abac-repeat.txt a+
testzipfswrite bug-23dd83ce7c-w empty.zip "xyz" empty.txt w
test zipfs-write-unreadable "Reads not allowed on file opened for write" -setup {