fix improper utimes usage
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
bf22475e95
commit
dcbfaba264
@ -105,15 +105,15 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
if (status >= 0) {
|
||||
/* TODO: restore other things? */
|
||||
if (info.mtime) {
|
||||
struct timeval times;
|
||||
struct timeval times[2];
|
||||
|
||||
times.tv_sec = info.mtime;
|
||||
times.tv_usec = 0;
|
||||
times[1].tv_sec = times[0].tv_sec = info.mtime;
|
||||
times[1].tv_usec = times[0].tv_usec = 0;
|
||||
/* Note: we closed it first.
|
||||
* On some systems calling utimes
|
||||
* then closing resets the mtime
|
||||
* back to current time. */
|
||||
utimes(new_name, ×); /* ignoring errors */
|
||||
utimes(new_name, times); /* ignoring errors */
|
||||
}
|
||||
|
||||
/* Delete _compressed_ file */
|
||||
|
@ -148,11 +148,11 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
}
|
||||
/* same for utime */
|
||||
if (archive_handle->ah_flags & ARCHIVE_RESTORE_DATE) {
|
||||
struct timeval t;
|
||||
struct timeval t[2];
|
||||
|
||||
t.tv_sec = file_header->mtime;
|
||||
t.tv_usec = 0;
|
||||
utimes(file_header->name, &t);
|
||||
t[1].tv_sec = t[0].tv_sec = file_header->mtime;
|
||||
t[1].tv_usec = t[0].tv_usec = 0;
|
||||
utimes(file_header->name, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,8 +54,8 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
# endif
|
||||
char *reference_file = NULL;
|
||||
char *date_str = NULL;
|
||||
struct timeval timebuf;
|
||||
timebuf.tv_usec = 0;
|
||||
struct timeval timebuf[2];
|
||||
timebuf[1].tv_usec = timebuf[0].tv_usec = 0;
|
||||
#else
|
||||
# define reference_file NULL
|
||||
# define date_str NULL
|
||||
@ -84,7 +84,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (reference_file) {
|
||||
struct stat stbuf;
|
||||
xstat(reference_file, &stbuf);
|
||||
timebuf.tv_sec = stbuf.st_mtime;
|
||||
timebuf[1].tv_sec = timebuf[0].tv_sec = stbuf.st_mtime;
|
||||
}
|
||||
|
||||
if (date_str) {
|
||||
@ -100,11 +100,11 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
tm_time.tm_isdst = -1; /* Be sure to recheck dst */
|
||||
t = validate_tm_time(date_str, &tm_time);
|
||||
|
||||
timebuf.tv_sec = t;
|
||||
timebuf[1].tv_sec = timebuf[0].tv_sec = t;
|
||||
}
|
||||
|
||||
do {
|
||||
if (utimes(*argv, reference_file ? &timebuf : NULL)) {
|
||||
if (utimes(*argv, reference_file ? timebuf : NULL)) {
|
||||
if (errno == ENOENT) { /* no such file */
|
||||
if (opts) { /* creation is disabled, so ignore */
|
||||
continue;
|
||||
@ -115,7 +115,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
);
|
||||
if ((fd >= 0) && !close(fd)) {
|
||||
if (reference_file)
|
||||
utimes(*argv, &timebuf);
|
||||
utimes(*argv, timebuf);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -374,12 +374,12 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
|
||||
/* Cannot happen: */
|
||||
/* && !(flags & (FILEUTILS_MAKE_SOFTLINK|FILEUTILS_MAKE_HARDLINK)) */
|
||||
) {
|
||||
struct timeval times;
|
||||
struct timeval times[2];
|
||||
|
||||
times.tv_sec = source_stat.st_mtime;
|
||||
times.tv_usec = 0;
|
||||
times[1].tv_sec = times[0].tv_sec = source_stat.st_mtime;
|
||||
times[1].tv_usec = times[0].tv_usec = 0;
|
||||
/* BTW, utimes sets usec-precision time - just FYI */
|
||||
if (utimes(dest, ×) < 0)
|
||||
if (utimes(dest, times) < 0)
|
||||
bb_perror_msg("can't preserve %s of '%s'", "times", dest);
|
||||
if (chown(dest, source_stat.st_uid, source_stat.st_gid) < 0) {
|
||||
source_stat.st_mode &= ~(S_ISUID | S_ISGID);
|
||||
|
Loading…
Reference in New Issue
Block a user