X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Fextract.c;h=5f12cf9aa483b3584bf02e9daa3678db976dc534;hb=cac45fffc58cc10056c528582ee4b78b8ee175e0;hp=300f52bc3c5a8cc96305003d10fd93ca63e770ca;hpb=8f390db92fc5890c824db9ebfa295a8a27d7251a;p=chaz%2Ftar diff --git a/src/extract.c b/src/extract.c index 300f52b..5f12cf9 100644 --- a/src/extract.c +++ b/src/extract.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "common.h" @@ -144,7 +145,8 @@ set_mode (char const *file_name, char typeflag) { mode_t mode; - + bool failed; + if (0 < same_permissions_option && permstatus != INTERDIR_PERMSTATUS) { @@ -186,7 +188,17 @@ set_mode (char const *file_name, mode = cur_info->st_mode ^ invert_permissions; } - if (chmod (file_name, mode) != 0) + failed = chmod (file_name, mode) != 0; + if (failed && errno == EPERM) + { + /* On Solaris, chmod may fail if we don't have PRIV_ALL. */ + if (priv_set_restore_linkdir () == 0) + { + failed = chmod (file_name, mode) != 0; + priv_set_remove_linkdir (); + } + } + if (failed) chmod_error_details (file_name, mode); } @@ -195,8 +207,9 @@ static void check_time (char const *file_name, struct timespec t) { if (t.tv_sec <= 0) - WARN ((0, 0, _("%s: implausibly old time stamp %s"), - file_name, tartime (t, true))); + WARNOPT (WARN_TIMESTAMP, + (0, 0, _("%s: implausibly old time stamp %s"), + file_name, tartime (t, true))); else if (timespec_cmp (volume_start_time, t) < 0) { struct timespec now; @@ -212,8 +225,9 @@ check_time (char const *file_name, struct timespec t) diff.tv_nsec += BILLION; diff.tv_sec--; } - WARN ((0, 0, _("%s: time stamp %s is %s s in the future"), - file_name, tartime (t, true), code_timespec (diff, buf))); + WARNOPT (WARN_TIMESTAMP, + (0, 0, _("%s: time stamp %s is %s s in the future"), + file_name, tartime (t, true), code_timespec (diff, buf))); } } } @@ -474,9 +488,13 @@ file_newer_p (const char *file_name, struct tar_stat_info *tar_stat) if (stat (file_name, &st)) { - stat_warn (file_name); - /* Be on the safe side: if the file does exist assume it is newer */ - return errno != ENOENT; + if (errno != ENOENT) + { + stat_warn (file_name); + /* Be on the safe side: if the file does exist assume it is newer */ + return true; + } + return false; } if (!S_ISDIR (st.st_mode) && tar_timespec_cmp (tar_stat->mtime, get_stat_mtime (&st)) <= 0) @@ -666,6 +684,7 @@ extract_dir (char *file_name, int typeflag) } if (S_ISDIR (st.st_mode)) { + status = 0; mode = st.st_mode; break; } @@ -736,7 +755,8 @@ open_output_file (char *file_name, int typeflag, mode_t mode) if (!conttype_diagnosed) { conttype_diagnosed = 1; - WARN ((0, 0, _("Extracting contiguous files as regular files"))); + WARNOPT (WARN_CONTIGUOUS_CAST, + (0, 0, _("Extracting contiguous files as regular files"))); } } fd = open (file_name, openflag, mode); @@ -1014,7 +1034,9 @@ extract_symlink (char *file_name, int typeflag) if (!warned_once) { warned_once = 1; - WARN ((0, 0, _("Attempting extraction of symbolic links as hard links"))); + WARNOPT (WARN_SYMBOLIC_CAST, + (0, 0, + _("Attempting extraction of symbolic links as hard links"))); } return extract_link (file_name, typeflag); #endif @@ -1172,9 +1194,10 @@ prepare_to_extract (char const *file_name, int typeflag, tar_extractor_t *fun) break; default: - WARN ((0, 0, - _("%s: Unknown file type `%c', extracted as normal file"), - quotearg_colon (file_name), typeflag)); + WARNOPT (WARN_UNKNOWN_CAST, + (0, 0, + _("%s: Unknown file type `%c', extracted as normal file"), + quotearg_colon (file_name), typeflag)); *fun = extract_file; } @@ -1198,8 +1221,9 @@ prepare_to_extract (char const *file_name, int typeflag, tar_extractor_t *fun) case KEEP_NEWER_FILES: if (file_newer_p (file_name, ¤t_stat_info)) { - WARN ((0, 0, _("Current %s is newer or same age"), - quote (file_name))); + WARNOPT (WARN_IGNORE_NEWER, + (0, 0, _("Current %s is newer or same age"), + quote (file_name))); return 0; } break; @@ -1218,6 +1242,11 @@ extract_archive (void) char typeflag; tar_extractor_t fun; + fatal_exit_hook = extract_finish; + + /* Try to disable the ability to unlink a directory. */ + priv_set_remove_linkdir (); + set_next_block_after (current_header); decode_header (current_header, ¤t_stat_info, ¤t_format, 1); if (!current_stat_info.file_name[0] @@ -1379,18 +1408,3 @@ rename_directory (char *src, char *dst) } return true; } - -void -fatal_exit (void) -{ - extract_finish (); - error (TAREXIT_FAILURE, 0, _("Error is not recoverable: exiting now")); - abort (); -} - -void -xalloc_die (void) -{ - error (0, 0, "%s", _("memory exhausted")); - fatal_exit (); -}