cppath.c revision 5c51f1241dbbdf2656d0e10011981411ed0c9673
66448911ac89c254e89afc52e114402115a497e3David Höppner * CDDL HEADER START
66448911ac89c254e89afc52e114402115a497e3David Höppner * The contents of this file are subject to the terms of the
66448911ac89c254e89afc52e114402115a497e3David Höppner * Common Development and Distribution License (the "License").
66448911ac89c254e89afc52e114402115a497e3David Höppner * You may not use this file except in compliance with the License.
66448911ac89c254e89afc52e114402115a497e3David Höppner * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
66448911ac89c254e89afc52e114402115a497e3David Höppner * See the License for the specific language governing permissions
66448911ac89c254e89afc52e114402115a497e3David Höppner * and limitations under the License.
66448911ac89c254e89afc52e114402115a497e3David Höppner * When distributing Covered Code, include this CDDL HEADER in each
66448911ac89c254e89afc52e114402115a497e3David Höppner * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
66448911ac89c254e89afc52e114402115a497e3David Höppner * If applicable, add the following below this CDDL HEADER, with the
66448911ac89c254e89afc52e114402115a497e3David Höppner * fields enclosed by brackets "[]" replaced with your own identifying
66448911ac89c254e89afc52e114402115a497e3David Höppner * information: Portions Copyright [yyyy] [name of copyright owner]
66448911ac89c254e89afc52e114402115a497e3David Höppner * CDDL HEADER END
66448911ac89c254e89afc52e114402115a497e3David Höppner * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
66448911ac89c254e89afc52e114402115a497e3David Höppner * Use is subject to license terms.
66448911ac89c254e89afc52e114402115a497e3David Höppner/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
66448911ac89c254e89afc52e114402115a497e3David Höppner/* All Rights Reserved */
66448911ac89c254e89afc52e114402115a497e3David Höppner * System includes
66448911ac89c254e89afc52e114402115a497e3David Höppner * consolidation pkg command library includes
66448911ac89c254e89afc52e114402115a497e3David Höppner * local pkg command library includes
66448911ac89c254e89afc52e114402115a497e3David Höppner * forward declarations
66448911ac89c254e89afc52e114402115a497e3David Höppnerstatic int write_file(char **r_linknam, int a_ctrl, mode_t a_mode,
66448911ac89c254e89afc52e114402115a497e3David Höppnerstatic int create_path(int a_ctrl, char *a_file);
66448911ac89c254e89afc52e114402115a497e3David Höppner * Name: cppath
66448911ac89c254e89afc52e114402115a497e3David Höppner * Description: copy a path object (install new file on system)
66448911ac89c254e89afc52e114402115a497e3David Höppner * - a_cntrl - determine how the destination file mode is set:
66448911ac89c254e89afc52e114402115a497e3David Höppner * |= MODE_0666 - force mode to 0666
66448911ac89c254e89afc52e114402115a497e3David Höppner * |= MODE_SET - mode is a_mode (no mask SET?ID bits)
66448911ac89c254e89afc52e114402115a497e3David Höppner * |= MODE_SRC - mode from source file (mask SET?ID bits)
66448911ac89c254e89afc52e114402115a497e3David Höppner * |= DIR_DISPLAY - display "%s <implied directory>" if directory created
66448911ac89c254e89afc52e114402115a497e3David Höppner * - a_srcPath - path to source to copy
66448911ac89c254e89afc52e114402115a497e3David Höppner * - a_dstPath - path to copy source to
66448911ac89c254e89afc52e114402115a497e3David Höppner * - a_mode - mode to set a_dstpath to (mode controlled by a_ctrl)
66448911ac89c254e89afc52e114402115a497e3David Höppner * Returns: int
66448911ac89c254e89afc52e114402115a497e3David Höppner * == 0 - success
66448911ac89c254e89afc52e114402115a497e3David Höppner * != 0 - failure
66448911ac89c254e89afc52e114402115a497e3David Höppnercppath(int a_ctrl, char *a_srcPath, char *a_dstPath, mode_t a_mode)
66448911ac89c254e89afc52e114402115a497e3David Höppner /* entry debugging info */
66448911ac89c254e89afc52e114402115a497e3David Höppner echoDebug(DBG_CPPATH_ENTRY, a_ctrl, a_mode, a_srcPath, a_dstPath);
66448911ac89c254e89afc52e114402115a497e3David Höppner /* open source file for reading */
66448911ac89c254e89afc52e114402115a497e3David Höppner /* obtain file status of source file */
66448911ac89c254e89afc52e114402115a497e3David Höppner progerr(ERR_FSTAT, srcFd, a_srcPath, errno, strerror(errno));
66448911ac89c254e89afc52e114402115a497e3David Höppner * Determine the permissions mode for the destination:
66448911ac89c254e89afc52e114402115a497e3David Höppner * - if MODE_SET is specified:
66448911ac89c254e89afc52e114402115a497e3David Höppner * --> use a_mode (do not mask off any portion)
66448911ac89c254e89afc52e114402115a497e3David Höppner * --> If a_mode is unknown (? in the pkgmap), then the file gets
66448911ac89c254e89afc52e114402115a497e3David Höppner * --> installed with the default 0644 mode
66448911ac89c254e89afc52e114402115a497e3David Höppner * - if MODE_SRC is specified:
66448911ac89c254e89afc52e114402115a497e3David Höppner * --> use the mode of the source (srcStatbuf.st_mode) but mask off all
66448911ac89c254e89afc52e114402115a497e3David Höppner * --> non-access mode bits (remove SET?UID bits)
66448911ac89c254e89afc52e114402115a497e3David Höppner * - otherwise:
66448911ac89c254e89afc52e114402115a497e3David Höppner * --> use 0666
66448911ac89c254e89afc52e114402115a497e3David Höppner * Get fd of newly created destination file or, if this
66448911ac89c254e89afc52e114402115a497e3David Höppner * is an overwrite, a temporary file (linknam).
e633f2d79475b51f0a4d46972282225abf851733Richard Lowe dstFd = write_file(&linknam, a_ctrl, a_mode, a_dstPath);
66448911ac89c254e89afc52e114402115a497e3David Höppner * source and target files are open: copy data
66448911ac89c254e89afc52e114402115a497e3David Höppner status = copyFile(srcFd, dstFd, a_srcPath, a_dstPath, &srcStatbuf, 0);
66448911ac89c254e89afc52e114402115a497e3David Höppner progerr(ERR_INPUT, a_srcPath, errno, strerror(errno));
66448911ac89c254e89afc52e114402115a497e3David Höppner * If this is an overwrite, rename temp over original
66448911ac89c254e89afc52e114402115a497e3David Höppner if ((linknam != (char *)NULL) && (rename(linknam, a_dstPath) != 0)) {
66448911ac89c254e89afc52e114402115a497e3David Höppner /* output log message if busy else program error */
66448911ac89c254e89afc52e114402115a497e3David Höppner /* open the log file and append log entry */
66448911ac89c254e89afc52e114402115a497e3David Höppner /* set access/modification times for target */
66448911ac89c254e89afc52e114402115a497e3David Höppner progerr(ERR_MODTIM, a_dstPath, errno, strerror(errno));
66448911ac89c254e89afc52e114402115a497e3David Höppner /* success! */
66448911ac89c254e89afc52e114402115a497e3David Höppner * This function creates all of the directory components of the specified path.
66448911ac89c254e89afc52e114402115a497e3David Höppner /* continue if not at path separator or at start of path */
66448911ac89c254e89afc52e114402115a497e3David Höppner /* at '/' - terminate path at current entry */
66448911ac89c254e89afc52e114402115a497e3David Höppner /* continue if path element exists */
66448911ac89c254e89afc52e114402115a497e3David Höppner /* create directory in path */
66448911ac89c254e89afc52e114402115a497e3David Höppner progerr(ERR_MAKE_DIR, a_file, errno, strerror(errno));
66448911ac89c254e89afc52e114402115a497e3David Höppner /* display 'implied directory created' message */
found++;
return (!found);
int len;
return (fd);
return (fd);