aboutsummaryrefslogtreecommitdiff
path: root/archival/bbunzip.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-11-01 12:54:56 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-11-01 12:54:56 +0000
commit1a9e9bdd93b06508b70bd29ef5eeb82f91d86222 (patch)
treeadcf234f48d8a68a5644f1504cc93025d58ce2a2 /archival/bbunzip.c
parent5a89763fb7e57d4fc3d393eafa35c58f8285a083 (diff)
downloadbusybox-1a9e9bdd93b06508b70bd29ef5eeb82f91d86222.tar.gz
gunzip: restore mtime. approx +80 bytes of code
rpm: make code more robust lsmod: small code shrink
Diffstat (limited to 'archival/bbunzip.c')
-rw-r--r--archival/bbunzip.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/archival/bbunzip.c b/archival/bbunzip.c
index c7962058e..75489f2a5 100644
--- a/archival/bbunzip.c
+++ b/archival/bbunzip.c
@@ -30,13 +30,14 @@ int open_to_or_warn(int to_fd, const char *filename, int flags, int mode)
int FAST_FUNC bbunpack(char **argv,
char* (*make_new_name)(char *filename),
- USE_DESKTOP(long long) int (*unpacker)(void)
+ USE_DESKTOP(long long) int (*unpacker)(unpack_info_t *info)
)
{
struct stat stat_buf;
USE_DESKTOP(long long) int status;
char *filename, *new_name;
smallint exitcode = 0;
+ unpack_info_t info;
do {
/* NB: new_name is *maybe* malloc'ed! */
@@ -92,14 +93,29 @@ int FAST_FUNC bbunpack(char **argv,
"use -f to force it");
}
- status = unpacker();
+ /* memset(&info, 0, sizeof(info)); */
+ info.mtime = 0; /* so far it has one member only */
+ status = unpacker(&info);
if (status < 0)
exitcode = 1;
if (filename) {
char *del = new_name;
if (status >= 0) {
- /* TODO: restore user/group/times here? */
+ /* TODO: restore other things? */
+ if (info.mtime) {
+ struct utimbuf times;
+
+ times.actime = info.mtime;
+ times.modtime = info.mtime;
+ /* Close first.
+ * On some systems calling utime
+ * then closing resets the mtime. */
+ close(STDOUT_FILENO);
+ /* Ignoring errors */
+ utime(new_name, &times);
+ }
+
/* Delete _compressed_ file */
del = filename;
/* restore extension (unless tgz -> tar case) */
@@ -159,7 +175,7 @@ char* make_new_name_bunzip2(char *filename)
}
static
-USE_DESKTOP(long long) int unpack_bunzip2(void)
+USE_DESKTOP(long long) int unpack_bunzip2(unpack_info_t *info UNUSED_PARAM)
{
return unpack_bz2_stream_prime(STDIN_FILENO, STDOUT_FILENO);
}
@@ -235,7 +251,7 @@ char* make_new_name_gunzip(char *filename)
}
static
-USE_DESKTOP(long long) int unpack_gunzip(void)
+USE_DESKTOP(long long) int unpack_gunzip(unpack_info_t *info)
{
USE_DESKTOP(long long) int status = -1;
@@ -247,7 +263,7 @@ USE_DESKTOP(long long) int unpack_gunzip(void)
if (ENABLE_FEATURE_SEAMLESS_Z && magic2 == 0x9d) {
status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO);
} else if (magic2 == 0x8b) {
- status = unpack_gz_stream(STDIN_FILENO, STDOUT_FILENO);
+ status = unpack_gz_stream_with_info(STDIN_FILENO, STDOUT_FILENO, info);
} else {
goto bad_magic;
}
@@ -309,7 +325,7 @@ char* make_new_name_unlzma(char *filename)
}
static
-USE_DESKTOP(long long) int unpack_unlzma(void)
+USE_DESKTOP(long long) int unpack_unlzma(unpack_info_t *info UNUSED_PARAM)
{
return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO);
}
@@ -344,7 +360,7 @@ char* make_new_name_uncompress(char *filename)
}
static
-USE_DESKTOP(long long) int unpack_uncompress(void)
+USE_DESKTOP(long long) int unpack_uncompress(unpack_info_t *info UNUSED_PARAM)
{
USE_DESKTOP(long long) int status = -1;