cpio: pad after file properly; decrement file size so we don't get an
infinite loop.
This fixes the remaining bugs in cpio -o:
-whether to pad depends on if the pad size is 0, not directly on the size
of the file.
-we got stuck in an infinite loop due to never subtracting the bytes
that we read.
--
Depends on the last patch (infinite loop on EOF, archive devices, and
allow -it).
I've tested like so:
scripts/single.sh cpio
find ./ |./cpio -o |./cpio -it |wc -l
find ./ |wc -l
Since it displays no error while archiving 1599 files in a way it can
read, I figure it "works pretty well".
Thanks,
Isaac Dunham
diff --git a/toys/pending/cpio.c b/toys/pending/cpio.c
index 4cfa181..e5dd92c 100644
--- a/toys/pending/cpio.c
+++ b/toys/pending/cpio.c
@@ -90,7 +90,7 @@ void write_cpio_member(int fd, char *name, struct stat buf)
if (readlink(name, toybuf, sizeof(toybuf)-1) == llen)
xwrite(TT.outfd, toybuf, llen);
else perror_msg("readlink '%s'", name);
- } else while (llen) {
+ } else for (; llen; llen-=nlen) {
nlen = llen > sizeof(toybuf) ? sizeof(toybuf) : llen;
// If read fails, write anyway (we already wrote size in the header).
if (nlen != readall(fd, toybuf, nlen))
@@ -98,7 +98,7 @@ void write_cpio_member(int fd, char *name, struct stat buf)
xwrite(TT.outfd, toybuf, nlen);
}
llen = buf.st_size & 3;
- if (nlen) write(TT.outfd, &zero, 4-llen);
+ if (llen) write(TT.outfd, &zero, 4-llen);
}
// Iterate through a list of files read from stdin. No users need rw.
_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net