Home | History | Annotate | Download | only in pax
History log of /src/bin/pax/file_subs.c
RevisionDateAuthorComments
 1.66  05-Aug-2024  riastradh pax(1): Nix trailing whitespace.

No functional change intended.
 1.65  28-May-2023  lukem branches: 1.65.2;
pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.
The partial temporary file is removed. pax still exists non-zero.

Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.

Should fix PR misc/33753.
 1.64  20-Mar-2019  gutteridge branches: 1.64.2; 1.64.10;
pax: fix typos in comments in file_subs.c & tar.c

Stamp out "greengrocers' apostrophes" in various places (arguably there
are still more present, but style guides vary on that, and my energies
spent corralling wayward punctuation marks could be spent elsewhere).
 1.63  29-Jul-2013  christos branches: 1.63.26;
PR/48095: NAKAJIMA Yoshihiro: remove casts from time_t to long
 1.62  07-Apr-2009  perry branches: 1.62.6; 1.62.12;
Fixes from christos for pr-41167

XXX -X is still broken, but that wasn't part of this PR.
 1.61  10-Jan-2008  tls branches: 1.61.10; 1.61.12;
Teach set_ftime about symbolic links, because it has to know: on some
Linux systems, when we build as a tool we think we have lutimes but it
doesn't work on some filesystems at runtime. A bit ugly but effective
and without use of AC_TRY_RUN in the tool build. Tidier (than mine)
set_ftime reorganization from christos.
 1.60  29-Apr-2007  msaitoh branches: 1.60.4;
fix typos
 1.59  11-Feb-2006  dsl Change all the 'return(x)' to 'return c'.
Makes some other searches I want to do a bit easier.
 1.58  04-Jan-2006  yamt obey umask as it used to be before the "mkstemp and then rename" change.
 1.57  18-Sep-2005  christos Check for another race reported by chuq.
 1.56  16-Sep-2005  christos Another missing mkdir() race pointed out by chuq. Factor out the mkdir code.
 1.55  13-Sep-2005  christos use stat and not lstat to detect if we have a directory. refactor the mkpath()
code.
 1.54  13-Sep-2005  christos when creating directories, check if the failure occured because someone
else created the directory before we did to avoid races. From chuq.
 1.53  24-Apr-2005  christos For clarity instead of using -1 and -2 use the negative of the archive type.
 1.52  22-Sep-2004  christos Keep track of the length of the gnu long name/link hack, so that
we can append to it. Modify the code so that file_write is re-entrant,
even in the gnu long name/link hack.

The old code assumed that the buffer already contained the necessary
blocks to satisfy the read file request that contained the long
filename. This is not always the case, specially when we are dealing
with pipes which do shorter reads, thus having more probability
that a long file name will fall across a buffer boundary.

To reproduce, create a tar archive with a lot of gnu-long-names
(pkgsrc/devel/libsigc++2 is a good example), do a tar -tf to get
a list of filenames, compress it and do a tar -tzf to get another
list of the filenames. Notice that the two lists differ.
 1.51  22-Aug-2004  tron Propery handle "cpio" archives where the last hardlink includes the
data of a file. This fixes PR bin/26514.
 1.50  02-Jul-2004  enami Salvage the `create parent directories and try again' path which is
removed by the previous commit.
 1.49  26-Jun-2004  grant break out of the loop and avoid the infinite loop if attempts to
create, unlink and create all fail.
 1.48  26-Jun-2004  grant don't attempt to remove the current directory.
 1.47  20-Jun-2004  jmc Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')

Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).

Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.

Fixes PR's: PR#17762 PR#25944
 1.46  03-May-2004  christos Don't exit with 1 on broken archives that mark directories as files for
the benefit of pkgsrc. I would have prefered that people fixed their
archivers instead.
 1.45  30-Apr-2004  matt Set the chflags *after* the rename, not before.
 1.44  27-Apr-2004  christos PR/25350: Alan Barrett: Treat the sticky bit specially as non-superusers
cannot set it on non-directories (elvis-2.2_0 extraction failed)
 1.43  25-Apr-2004  christos PR/25188: Thomas Klausner: pax-as-tar problem with trailing slashes
The problem is with the program that generates the tar file:
-rwxrwxrwx 1 root wheel 0 Feb 8 16:46 faad2/aacDECdrop/
It creates directory nodes without the 'd' bit set, so that pax thinks
they are files and does the temporary name and dance with them. Added
code to detect this condition, warn about it, and work around it.
 1.42  20-Apr-2004  christos PR/25207: Hubert Feyrer: tar cores on certain archive contents
Don't forget to cleanup xtmp_name when we fail to create the temporary file.
 1.41  13-Feb-2004  matt branches: 1.41.2;
When pax catches a signal and cleans up, make sure to remove any temporary
file that was being extracted to. This will prevent pax from leaving
droppings when you hit ^C.
 1.40  13-Feb-2004  matt Nuke extra mkstemp. Use name, not tmp_name with chk_path.
 1.39  13-Feb-2004  matt Back out last change. Since the name is the entire path, prefixing it
with a '.' will not have the desired effect.
 1.38  13-Feb-2004  matt When creating the temporary file, prefix the name with a '.'
 1.37  12-Feb-2004  matt When restoring files from an archive, initially restore to a temp-file and
once it has been instantiated correctly, rename it to desired name. This
prevents the problem of partially created files being accessed before they
are complete. If said file is a shared library, that can cause ramdon core
dumps.
 1.36  27-Oct-2003  lukem Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.35  13-Oct-2003  agc Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
 1.34  07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.33  23-Jun-2003  grant no need for HAVE_LCHOWN and HAVE_LCHMOD anymore.
 1.32  10-Feb-2003  grant add missing braces.

from HIRATSUKA Kouichirou in PR bin/20276.
 1.31  09-Feb-2003  grant cosmetic error condition improvements.
- sprinkle some fflush() to print filenames correctly.
- print a \n to stdout to fix formatting.
- English, consistently use "Cannot" in error messages.

some whitespace cleanup.
 1.30  02-Feb-2003  wiz Fix various spelling, grammar, and punctuation problems in comments, from Sergey Svishchev in PR 20164.
 1.29  20-Jan-2003  simonb The Double-Semi-Colon Police.
 1.28  06-Jan-2003  wiz writable, not writeable.
 1.27  19-Dec-2002  grant Fix oops in last, chown() failure should be fatal.

Noted by Charles Hannum.
 1.26  19-Dec-2002  grant Don't attempt to chown files if euid != 0, and make chown() non-fatal
if it does fail.

This addresses my PR bin/18912 (running pkg_info as non-root user on a
binary package).
 1.25  17-Oct-2002  christos Add proper longlink support. Previously we handled longname support, and
the longlink support was completely wrong.
 1.24  12-Oct-2002  christos merge OpenBSD changes:
- correct -C processing
- add ability to read filenames and flags from a file
- don't print dangerous escape sequences to the terminal
- use strlcpy/strncpy properly.
- handle tmpfile creation better.
- improve documentation of options.
- handle stdout/stderr list selection correctly.
- kill gzip when we get interrupted.
- simplify gzip setup.
- add more flags to programs.

additional changes:
- librmt processing.
- set POSIXLY_CORRECT in options parsing.
- prevent more string overruns.
- support -T

we don't turn the switch on to replace tar and cpio yet.
 1.23  11-Feb-2002  wiz branches: 1.23.2;
"doesn't" should have an 's'.
 1.22  31-Jan-2002  tv Protect __RCSID and __COPYRIGHT from being invoked if not defined.
 1.21  29-Jan-2002  tv Make almost all tools compile and run properly on non-NetBSD hosts. (In
particular, most tools now run correctly on Solaris 7.)
 1.20  25-Oct-2001  lukem - ansi KNF (just remove all the #ifndef __STDC__ prototype junk,
leaving the ansi stuff)
- use longlong_t instead of quad_t (etc), and rename *uqd*() -> *ull*()
- clean up the NET2_STAT stuff similar to ftpd; provide #defines and
macros which select which cast to use, etc
- clean up the NET2_FTS and NET2_REGEX #define use
 1.19  17-Jun-2000  mrg minor KNF nits.
 1.18  13-Mar-2000  soren branches: 1.18.2;
Fix doubled 'the' in comment.
 1.17  17-Feb-2000  itohy Cleanup and fix typos.
Partially from FreeBSD.
 1.16  17-Feb-2000  itohy Fix SIGINFO botch (PR #8868).
Continue partial write(2) on signals (xwrite()).
Partial read(2) at a few places are also continued (xread()).

Add {read,write}_with_restart() hooks for porting on systems
which don't restart interrupted read()/write() calls.

Reviewed and discussed in tech-kern and tech-userlevel lists.
 1.15  07-Nov-1999  mycroft branches: 1.15.2;
Completely disable all the chflags(2) support for now. With this enabled, I
can't even get a build to finish over NFS. Not acceptable.
 1.14  07-Nov-1999  mycroft Don't try to set file flags for a symlink.
 1.13  01-Nov-1999  mrg add a new -p subflag: 'f' to preserve 4.4BSD fileflags. this only
really works for `pax -rw' but that's where it is most useful.
 1.12  22-Oct-1999  mrg support ././@LongLink extraction, as created by GNU tar.
 1.11  22-Oct-1999  mrg remove some old cruft.
 1.10  28-Feb-1998  mrg branches: 1.10.4;
fix typo in a comment
 1.9  03-Feb-1998  mycroft Deal with GCC warnings.
 1.8  19-Oct-1997  mycroft When copying time stamps, copy the microseconds, too. Also nuke silly
static structure.
 1.7  08-Oct-1997  enami Restore owner/group/mode/atime/mtime of symbolic links.
 1.6  20-Jul-1997  christos - Rename local warn so tty_warn that we can include <err.h> since this program
uses err() and errx().
- Fix printf format strings.
- Added WARNS=1; note
- Added missing prototypes.
- Split overloaded trail function into trail() and subtrail().
 1.5  11-Jan-1997  tls kill 'register'
 1.4  21-Mar-1995  cgd convert to new RCS id conventions.
 1.3  14-Jun-1994  mycroft Fix up RCS ids.
 1.2  13-Jun-1994  jtc Add RCS ID's
 1.1  13-Jun-1994  jtc branches: 1.1.1;
Initial revision
 1.1.1.1  13-Jun-1994  jtc From 4.4 lite
 1.10.4.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.15.2.2  07-Nov-1999  mycroft Completely disable all the chflags(2) support for now. With this enabled, I
can't even get a build to finish over NFS. Not acceptable.
 1.15.2.1  07-Nov-1999  mycroft file file_subs.c was added on branch comdex-fall-1999 on 1999-11-07 15:48:25 +0000
 1.18.2.1  22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.23.2.3  25-Aug-2004  he Pull up revisions 1.42-1.46,1.48-1.50 (requested by cube in ticket #1736):
Fix handling of certain archives, fixing core dump (PR#25207).
Fix problem with trailing slashes (PR#15188).
Treat sticky bit specially for non-superuser (PR#25350).
Set chflags after rename, not before.
Don't exit with 1 on broken archives that mark directories as files.
Don't attempt to remove current directory.
Break out of loop and avoid infinite loop in certain error situations.
Salvage the `create parent directories and try again' patch.
 1.23.2.2  16-Jun-2004  jmc fix botched pullup from ticket #1021 and make sure this compiles on
non-NetBSD hosts again. Also fixes PR#24481
 1.23.2.1  07-Apr-2004  jmc Pullup rev 1.24-1.41 (requested by rafal in ticket #1021)

Pullup pax to current version on trunk. Includes many fixes.
 1.41.2.8  12-Nov-2004  jmc branches: 1.41.2.8.2;
Pullup rev 1.52 (requested by christos in ticket #921)

Keep track of the length of the gnu long name/link hack, so that
we can append to it. Modify the code so that file_write is re-entrant,
even in the gnu long name/link hack.
 1.41.2.7  25-Aug-2004  jmc Pullup rev 1.51 (requested by tron in ticket #784)

Propery handle "cpio" archives where the last hardlink includes the
data of a file. PR#26514
 1.41.2.6  12-Aug-2004  jmc Pullup rev 1.48-1.50 (requested by cube in ticket #754)

Fixes for pax breaking on some archives
 1.41.2.5  22-Jun-2004  tron Pull up revision 1.47 (requested by jmc in ticket #527):
Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')
Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).
Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.
Fixes PR's: PR#17762 PR#25944
 1.41.2.4  06-May-2004  jmc Pullup rev 1.45-1.46 (requested by snj in ticket #252)

Set the chflags *after* the rename, not before.
Don't exit with 1 on broken archives that mark directories as files for
the benefit of pkgsrc.
 1.41.2.3  28-Apr-2004  grant Pull up revision 1.44 (requested by snj in ticket #217):

PR/25350: Alan Barrett: Treat the sticky bit specially as non-superusers
cannot set it on non-directories (elvis-2.2_0 extraction failed)
 1.41.2.2  28-Apr-2004  grant Pull up revision 1.43 (requested by snj in ticket #217):

PR/25188: Thomas Klausner: pax-as-tar problem with trailing slashes
The problem is with the program that generates the tar file:
-rwxrwxrwx 1 root wheel 0 Feb 8 16:46 faad2/aacDECdrop/
It creates directory nodes without the 'd' bit set, so that pax thinks
they are files and does the temporary name and dance with them. Added
code to detect this condition, warn about it, and work around it.
 1.41.2.1  21-Apr-2004  jmc Pullup rev 1.42 (requested by christos in ticket #170)

Fixes for multiple pax pr's. PR#25200. PR#25207.
 1.41.2.8.2.1  23-Jul-2005  snj Apply patch (requested by riz in ticket #5512):
Sync pax with HEAD of 2005-07-22.
 1.60.4.1  23-Mar-2008  matt sync with HEAD
 1.61.12.1  13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.61.10.1  13-Apr-2009  snj Pull up following revision(s) (requested by christo in ticket #678):
bin/pax/extern.h: revision 1.56
bin/pax/file_subs.c: revision 1.62
bin/pax/options.c: revision 1.104
bin/pax/pat_rep.c: revision 1.29
bin/pax/pax.h: revision 1.30
Fixes from christos for pr-41167
XXX -X is still broken, but that wasn't part of this PR.
 1.62.12.1  19-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.62.6.1  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.63.26.3  21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.63.26.2  21-Apr-2020  martin Sync with HEAD
 1.63.26.1  10-Jun-2019  christos Sync with HEAD
 1.64.10.1  07-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #776):

bin/pax/buf_subs.c: revision 1.31
tests/bin/pax/t_pax.sh: revision 1.3
tests/bin/pax/t_pax.sh: revision 1.4
tests/bin/pax/t_pax.sh: revision 1.5
tests/bin/pax/t_pax.sh: revision 1.6
tests/bin/pax/t_pax.sh: revision 1.7
bin/pax/extern.h: revision 1.61
bin/pax/pax.c: revision 1.50
bin/pax/pax.c: revision 1.51
bin/pax/file_subs.c: revision 1.65
bin/pax/ftree.c: revision 1.43
bin/pax/ar_subs.c: revision 1.58

pax: exit 0 if stdin filelist is used and empty

If copying a list of files from stdin, exit zero instead of non-zero
if there are no files supplied.

AFAICT, POSIX doesn't require a non-zero an error in this situation,
since there are no files to not match.

Fix from PR bin/41736 by Lloyd Parkes.

pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.

The partial temporary file is removed. pax still exists non-zero.
Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.
Should fix PR misc/33753.

tests/bin/pax: Add test for pax list in an ungettable cwd.
The list operation has no need to touch the file system, so it should
have no need for open(".") or getcwd() to succeed.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
(The PR was filed about tar(1), which is now bsdtar by default, but
the issue applies to pax(1) too and would continue to apply to tar(1)
if you set MKBSDTAR=no.)
pax(1): Don't require open(".") or getcwd to work for list operation.

PR 44498: tar(1) unnecessarily demands that getcwd() work
tests/bin/pax: Test pax(1) succeeds with empty file list on stdin.

PR bin/41736: pax reports an error when copying zero files
tests/bin/pax: Add some more cwd-related test cases.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
pax(1): Only require getcwd if we're reading without --insecure.

No other paths use the result of getcwd.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
 1.64.2.1  07-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1863):

bin/pax/buf_subs.c: revision 1.31
tests/bin/pax/t_pax.sh: revision 1.3
tests/bin/pax/t_pax.sh: revision 1.4
tests/bin/pax/t_pax.sh: revision 1.5
tests/bin/pax/t_pax.sh: revision 1.6
tests/bin/pax/t_pax.sh: revision 1.7
bin/pax/extern.h: revision 1.61
bin/pax/pax.c: revision 1.50
bin/pax/pax.c: revision 1.51
bin/pax/file_subs.c: revision 1.65
bin/pax/ftree.c: revision 1.43
bin/pax/ar_subs.c: revision 1.58

pax: exit 0 if stdin filelist is used and empty

If copying a list of files from stdin, exit zero instead of non-zero
if there are no files supplied.

AFAICT, POSIX doesn't require a non-zero an error in this situation,
since there are no files to not match.

Fix from PR bin/41736 by Lloyd Parkes.

pax: don't overwrite destination if -r -w copy fails

Add more error handling to pax -r -w so that any failure
during the copy to the temporary file (including a failed flush)
prevents any existing destination file from being replaced
with the partial (including possibly empty) temporary file.

The partial temporary file is removed. pax still exists non-zero.
Thanks to Michael van Elst (mlelstv@) for the analysis
of the problem in the PR.
Should fix PR misc/33753.

tests/bin/pax: Add test for pax list in an ungettable cwd.
The list operation has no need to touch the file system, so it should
have no need for open(".") or getcwd() to succeed.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
(The PR was filed about tar(1), which is now bsdtar by default, but
the issue applies to pax(1) too and would continue to apply to tar(1)
if you set MKBSDTAR=no.)
pax(1): Don't require open(".") or getcwd to work for list operation.

PR 44498: tar(1) unnecessarily demands that getcwd() work
tests/bin/pax: Test pax(1) succeeds with empty file list on stdin.

PR bin/41736: pax reports an error when copying zero files
tests/bin/pax: Add some more cwd-related test cases.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
pax(1): Only require getcwd if we're reading without --insecure.

No other paths use the result of getcwd.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work
 1.65.2.1  02-Aug-2025  perseant Sync with HEAD

RSS XML Feed