Commit 97b62d47 by Matthias Klose

[multiple changes]

2004-07-06  Matthias Klose  <doko@debian.org>

	* Makefile.in: Regenerate.
	* fastjar.texi: Update for '-u'.

2004-05-19  Casey Marshall <csm@gnu.org>

	PR 7854
	* Makefile.am
	(jar_SOURCES): added shift.c, shift.h.
        (jar_CPPFLAGS): define WITH_SHIFT_DOWN.

        * compress.c
        Added FSF copyright.
        (write_data): new function.
        (compress_file): call write_data.

        * jartool.c
        Updated copyright year.
        (progname): new variable.
        (end_of_entries): new variable.
        (main): open and read file when updating.
        (find_entry): new function.
        (looks_like_dir): new function.
        (read_entries): new function.
        (make_manifest): added parameter `updating'.
        Call `add_file_to_jar' with `updating'.
        (add_to_jar_with_dir): added parameter `updating'.
        Call `add_to_jar' with `updating'.
        (add_to_jar): added parameter `updating'.
        Call `add_file_to_jar' with `updating'.
        Don't add directories if they already exist.
        (add_file_to_jar): added parameter `updating'.
        Update entries if they already exist.

        * jartool.h
        Added #ifndef __FASTJAR_JARTOOL_H__.
        (struct zipentry): added `flags'.

        * shift.c: new file.

        * shift.h: new file.

        * zipfile.h
        (CEN_FLAGS): new constant.

From-SVN: r84171
parent ca4f3d13
2004-07-06 Matthias Klose <doko@debian.org>
* Makefile.in: Regenerate.
* fastjar.texi: Update for '-u'.
2004-05-19 Casey Marshall <csm@gnu.org>
PR 7854
* Makefile.am
(jar_SOURCES): added shift.c, shift.h.
(jar_CPPFLAGS): define WITH_SHIFT_DOWN.
* compress.c
Added FSF copyright.
(write_data): new function.
(compress_file): call write_data.
* jartool.c
Updated copyright year.
(progname): new variable.
(end_of_entries): new variable.
(main): open and read file when updating.
(find_entry): new function.
(looks_like_dir): new function.
(read_entries): new function.
(make_manifest): added parameter `updating'.
Call `add_file_to_jar' with `updating'.
(add_to_jar_with_dir): added parameter `updating'.
Call `add_to_jar' with `updating'.
(add_to_jar): added parameter `updating'.
Call `add_file_to_jar' with `updating'.
Don't add directories if they already exist.
(add_file_to_jar): added parameter `updating'.
Update entries if they already exist.
* jartool.h
Added #ifndef __FASTJAR_JARTOOL_H__.
(struct zipentry): added `flags'.
* shift.c: new file.
* shift.h: new file.
* zipfile.h
(CEN_FLAGS): new constant.
2004-07-05 Kelley Cook <kcook@gcc.gnu.org>
* Makefile.am: Silence two automake warnings.
......
......@@ -46,10 +46,11 @@ AM_CPPFLAGS = -I. -I$(top_srcdir) $(ZINCS) -I$(top_srcdir)/../include
LIBIBERTY = ../libiberty/libiberty.a
bin_PROGRAMS = jar grepjar
jar_SOURCES = jartool.c dostime.c compress.c pushback.c jartool.h \
zipfile.h dostime.h compress.h pushback.h
jar_SOURCES = jartool.c dostime.c compress.c pushback.c shift.c jartool.h \
zipfile.h dostime.h compress.h pushback.h shift.h
jar_LDADD = $(ZLIBS) $(LIBIBERTY)
jar_DEPENDENCIES = $(ZDEPS) $(LIBIBERTY)
jar_CPPFLAGS = -DWITH_SHIFT_DOWN
grepjar_SOURCES = jargrep.c dostime.c compress.c pushback.c jartool.h \
zipfile.h dostime.h compress.h pushback.h
......
......@@ -41,11 +41,11 @@ POST_UNINSTALL = :
bin_PROGRAMS = jar$(EXEEXT) grepjar$(EXEEXT)
subdir = .
DIST_COMMON = README $(am__configure_deps) $(fastjar_TEXINFOS) \
$(srcdir)/../install-sh $(srcdir)/../missing \
$(srcdir)/../mkinstalldirs $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in $(srcdir)/config.h.in \
$(srcdir)/install-defs.sh.in $(top_srcdir)/configure AUTHORS \
COPYING ChangeLog INSTALL NEWS
$(srcdir)/../compile $(srcdir)/../install-sh \
$(srcdir)/../missing $(srcdir)/../mkinstalldirs \
$(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(srcdir)/config.h.in $(srcdir)/install-defs.sh.in \
$(top_srcdir)/configure AUTHORS COPYING ChangeLog INSTALL NEWS
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/../config/accross.m4 $(top_srcdir)/configure.ac
......@@ -64,8 +64,9 @@ am_grepjar_OBJECTS = jargrep.$(OBJEXT) dostime.$(OBJEXT) \
grepjar_OBJECTS = $(am_grepjar_OBJECTS)
am__DEPENDENCIES_1 =
am__DEPENDENCIES_2 = ../libiberty/libiberty.a
am_jar_OBJECTS = jartool.$(OBJEXT) dostime.$(OBJEXT) \
compress.$(OBJEXT) pushback.$(OBJEXT)
am_jar_OBJECTS = jar-jartool.$(OBJEXT) jar-dostime.$(OBJEXT) \
jar-compress.$(OBJEXT) jar-pushback.$(OBJEXT) \
jar-shift.$(OBJEXT)
jar_OBJECTS = $(am_jar_OBJECTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I.
depcomp =
......@@ -129,7 +130,6 @@ EGREP = @EGREP@
EXEEXT = @EXEEXT@
GENINSRC_FALSE = @GENINSRC_FALSE@
GENINSRC_TRUE = @GENINSRC_TRUE@
GREP = @GREP@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
......@@ -229,11 +229,12 @@ AM_MAKEFLAGS = \
AM_CPPFLAGS = -I. -I$(top_srcdir) $(ZINCS) -I$(top_srcdir)/../include
LIBIBERTY = ../libiberty/libiberty.a
jar_SOURCES = jartool.c dostime.c compress.c pushback.c jartool.h \
zipfile.h dostime.h compress.h pushback.h
jar_SOURCES = jartool.c dostime.c compress.c pushback.c shift.c jartool.h \
zipfile.h dostime.h compress.h pushback.h shift.h
jar_LDADD = $(ZLIBS) $(LIBIBERTY)
jar_DEPENDENCIES = $(ZDEPS) $(LIBIBERTY)
jar_CPPFLAGS = -DWITH_SHIFT_DOWN
grepjar_SOURCES = jargrep.c dostime.c compress.c pushback.c jartool.h \
zipfile.h dostime.h compress.h pushback.h
......@@ -362,6 +363,36 @@ distclean-compile:
.c.obj:
$(COMPILE) -c `$(CYGPATH_W) '$<'`
jar-jartool.o: jartool.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(jar_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o jar-jartool.o `test -f 'jartool.c' || echo '$(srcdir)/'`jartool.c
jar-jartool.obj: jartool.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(jar_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o jar-jartool.obj `if test -f 'jartool.c'; then $(CYGPATH_W) 'jartool.c'; else $(CYGPATH_W) '$(srcdir)/jartool.c'; fi`
jar-dostime.o: dostime.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(jar_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o jar-dostime.o `test -f 'dostime.c' || echo '$(srcdir)/'`dostime.c
jar-dostime.obj: dostime.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(jar_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o jar-dostime.obj `if test -f 'dostime.c'; then $(CYGPATH_W) 'dostime.c'; else $(CYGPATH_W) '$(srcdir)/dostime.c'; fi`
jar-compress.o: compress.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(jar_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o jar-compress.o `test -f 'compress.c' || echo '$(srcdir)/'`compress.c
jar-compress.obj: compress.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(jar_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o jar-compress.obj `if test -f 'compress.c'; then $(CYGPATH_W) 'compress.c'; else $(CYGPATH_W) '$(srcdir)/compress.c'; fi`
jar-pushback.o: pushback.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(jar_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o jar-pushback.o `test -f 'pushback.c' || echo '$(srcdir)/'`pushback.c
jar-pushback.obj: pushback.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(jar_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o jar-pushback.obj `if test -f 'pushback.c'; then $(CYGPATH_W) 'pushback.c'; else $(CYGPATH_W) '$(srcdir)/pushback.c'; fi`
jar-shift.o: shift.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(jar_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o jar-shift.o `test -f 'shift.c' || echo '$(srcdir)/'`shift.c
jar-shift.obj: shift.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(jar_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o jar-shift.obj `if test -f 'shift.c'; then $(CYGPATH_W) 'shift.c'; else $(CYGPATH_W) '$(srcdir)/shift.c'; fi`
.texi.info:
restore=: && \
backupdir="$(am__leading_dot)am$$$$" && \
......
......@@ -74,6 +74,7 @@
/*
compress.c - code for handling deflation
Copyright (C) 1999 Bryan Burns
Copyright (C) 2004 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
......@@ -109,8 +110,12 @@
#include "jartool.h"
#include "pushback.h"
#include "compress.h"
#include "shift.h"
int write_data (int, void *, size_t, struct zipentry *);
extern int seekable;
extern off_t end_of_entries;
static z_stream zs;
......@@ -133,7 +138,36 @@ void init_compression(){
}
}
int compress_file(int in_fd, int out_fd, struct zipentry *ze){
int
write_data (int fd, void *buf, size_t len, struct zipentry *ze)
{
#ifdef WITH_SHIFT_DOWN
struct zipentry *next = NULL;
off_t here = lseek (fd, 0, SEEK_CUR);
/*
* If we are updating and there is not enough space before the next
* entry, expand the file.
*/
if (ze)
{
next = ze->next_entry;
if (next && here + len >= next->offset)
{
if (shift_down (fd, next->offset, (here + len) - next->offset, next))
{
perror ("can't expand file");
exit (1);
}
}
}
#endif /* WITH_SHIFT_DOWN */
return write (fd, buf, len);
}
int compress_file(int in_fd, int out_fd, struct zipentry *ze,
struct zipentry *existing)
{
Bytef in_buff[RDSZ];
Bytef out_buff[RDSZ];
unsigned int rdamt, wramt;
......@@ -183,10 +217,11 @@ int compress_file(int in_fd, int out_fd, struct zipentry *ze){
/* If the output buffer is full, dump it to disk */
if(zs.avail_out == 0){
if(write(out_fd, out_buff, RDSZ) != RDSZ){
perror("write");
exit(1);
}
if (write_data (out_fd, out_buff, RDSZ, existing) != RDSZ)
{
perror("write");
exit(1);
}
/* clear the output buffer */
zs.next_out = out_buff;
......@@ -201,10 +236,11 @@ int compress_file(int in_fd, int out_fd, struct zipentry *ze){
wramt = RDSZ - zs.avail_out;
if(write(out_fd, out_buff, wramt) != (int)wramt){
perror("write");
exit(1);
}
if (write_data (out_fd, out_buff, wramt, existing) != (int)wramt)
{
perror("write");
exit(1);
}
/* clear the output buffer */
zs.next_out = out_buff;
zs.avail_out = (uInt)RDSZ;
......@@ -215,10 +251,11 @@ int compress_file(int in_fd, int out_fd, struct zipentry *ze){
while(deflate(&zs, Z_FINISH) == Z_OK){
wramt = RDSZ - zs.avail_out;
if(write(out_fd, out_buff, wramt) != (int)wramt){
perror("write");
exit(1);
}
if (write_data (out_fd, out_buff, wramt, existing) != (int)wramt)
{
perror("write");
exit(1);
}
zs.next_out = out_buff;
zs.avail_out = (uInt)RDSZ;
......@@ -228,10 +265,11 @@ int compress_file(int in_fd, int out_fd, struct zipentry *ze){
if(zs.avail_out != RDSZ){
wramt = RDSZ - zs.avail_out;
if(write(out_fd, out_buff, wramt) != (int)wramt){
perror("write");
exit(1);
}
if (write_data (out_fd, out_buff, wramt, existing) != (int)wramt)
{
perror("write");
exit(1);
}
}
/* update fastjar's entry information */
......
......@@ -46,7 +46,7 @@
void init_compression(void);
/* Compresses the file specified by in_fd and appends it to out_fd */
int compress_file(int in_fd, int out_fd, struct zipentry *ze);
int compress_file(int, int, struct zipentry *, struct zipentry *);
/* Frees memory used by compression function */
void end_compression(void);
......
......@@ -125,8 +125,7 @@ List table of contents for archive.
Extract named (or all) files from archive.
@item -u
Update existing archive. This option is disabled due to bugs (currently
fails with exit status 1 and does nothing).
Update existing archive.
@end table
......
......@@ -52,6 +52,10 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __FASTJAR_JARTOOL_H__
#define __FASTJAR_JARTOOL_H__
#include <sys/types.h>
#include "config.h"
#define ACTION_NONE 0
......@@ -104,9 +108,12 @@ struct zipentry {
ub4 usize;
ub4 offset;
ub1 compressed;
ub2 flags;
char *filename;
struct zipentry *next_entry;
};
typedef struct zipentry zipentry;
#endif /* __FASTJAR_JARTOOL_H__ */
/* shift.c -- utilities to move regions of data in a file.
Copyright (C) 2004 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA. */
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include "jartool.h"
#include "shift.h"
#define BUFFER_SIZE 1024
#define MIN(a, b) ((a) < (b) ? (a) : (b))
/*
* Shift the contents of a file up by `amount' bytes, starting at `begin'.
* The file is not truncated, data from `amount' to `begin - amount' is
* overwritten. The current file pointer of `fd' is preserved. Note that
* this might be past the new "end" of the file.
*
* If this function is passed a `struct zipentry', then all `offset'
* fields from that entry down the list that are greater than or equal
* to `begin' will be decreased by `amount'.
*
* fd - The file descriptor.
* begin - The offset of the first byte that should be shifted.
* amount - The number of bytes to shift by.
* ze - A pointer into a list of zip entries that should be updated
* to reflect the modified offset.
*/
int
shift_up (int fd, off_t begin, off_t amount, struct zipentry *ze)
{
extern off_t end_of_entries;
int len, moved = 0;
ub1 buffer[BUFFER_SIZE];
off_t where, end, save;
if (amount <= 0)
return 0;
if ((save = lseek (fd, 0, SEEK_CUR)) == -1)
return 1;
if ((end = lseek (fd, 0, SEEK_END)) == -1)
return 1;
if (end < begin)
return 0;
where = begin;
do
{
if (lseek (fd, where, SEEK_SET) < 0)
return 1;
if ((len = read (fd, buffer, BUFFER_SIZE)) < 0)
return 1;
if (len == 0)
break;
if (lseek (fd, where - amount, SEEK_SET) < 0)
return 1;
if (write (fd, buffer, len) < 0)
return 1;
where += len;
}
while (where < end);
for (; ze; ze = ze->next_entry)
{
if (ze->offset >= begin)
{
ze->offset -= amount;
moved = 1;
}
}
if (moved)
end_of_entries -= amount;
if (lseek (fd, save, SEEK_SET) == -1)
return 1;
return 0;
}
/*
* Shift the contents of this file down by `amount' bytes, extending the
* end of file, starting at `begin'. This function will preserve the
* current file pointer of `fd'. Naturally, this function will fail if
* `fd' is not seekable.
*
* If this function is passed a `struct zipentry', then all `offset'
* fields from that entry down the list that are greater than or equal
* to `begin' will be increased by `amount'.
*
* fd - The file descriptor.
* begin - The offset of the first byte that should be shifted.
* amount - The number of bytes to shift by.
* ze - A pointer into a list of zip entries that should be updated
* to reflect the modified offset.
*/
int
shift_down (int fd, off_t begin, off_t amount, struct zipentry *ze)
{
extern off_t end_of_entries;
int off, len, moved = 0;
ub1 buffer[BUFFER_SIZE];
off_t where, save;
if (amount <= 0)
return 0;
if ((save = lseek (fd, 0, SEEK_CUR)) == -1)
return 1;
if ((where = lseek (fd, 0, SEEK_END)) == -1)
return 1;
if (where < begin)
return 0;
off = (where - begin) % BUFFER_SIZE;
if (off == 0)
where -= BUFFER_SIZE;
else
where -= off;
do
{
if (lseek (fd, where, SEEK_SET) < 0)
return 1;
if ((len = read (fd, buffer, BUFFER_SIZE)) < 0)
return 1;
if (lseek (fd, where + amount, SEEK_SET) < 0)
return 1;
if (write (fd, buffer, len) < 0)
return 1;
where -= BUFFER_SIZE;
}
while (where >= begin);
for (; ze; ze = ze->next_entry)
{
if (ze->offset >= begin)
{
ze->offset += amount;
moved = 1;
}
}
if (moved)
end_of_entries += amount;
if (lseek (fd, save, SEEK_SET) == -1)
return 1;
return 0;
}
/* shift.h -- utilities to move regions of data in a file.
Copyright (C) 2004 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA. */
#ifndef __FASTJAR_SHIFT_H__
#define __FASTJAR_SHIFT_H__
#include <sys/types.h>
#include "jartool.h"
int shift_down (int, off_t, off_t, struct zipentry *);
int shift_up (int, off_t, off_t, struct zipentry *);
#endif /* __FASTJAR_SHIFT_H__ */
......@@ -47,6 +47,7 @@
#define LOC_FNLEN 26 /* filename length */
#define LOC_EFLEN 28 /* extra-field length */
#define CEN_FLAGS 8
#define CEN_COMP 10 /* compression method */
#define CEN_MODTIME 12
#define CEN_MODDATE 14
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment