hardlink.py revision 1685
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen# CDDL HEADER START
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen# The contents of this file are subject to the terms of the
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen# Common Development and Distribution License (the "License").
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen# You may not use this file except in compliance with the License.
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen# See the License for the specific language governing permissions
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen# and limitations under the License.
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen# When distributing Covered Code, include this CDDL HEADER in each
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen# If applicable, add the following below this CDDL HEADER, with the
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen# fields enclosed by brackets "[]" replaced with your own identifying
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen# information: Portions Copyright [yyyy] [name of copyright owner]
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen# CDDL HEADER END
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen# Use is subject to license terms.
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen"""module describing a (hard) link packaging object
5f08b0309190ec818d46bfe0e497468b30714a93Timo SirainenThis module contains the HardLinkAction class, which represents a hardlink-type
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainenpackaging object."""
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainenfrom pkg.client.api_errors import ActionExecutionError
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen """Class representing a hardlink-type packaging object."""
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen """ return a path for target that is relative to image"""
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen # paths are either relative to path or absolute;
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen # both need to be passed through os.path.normpath to ensure
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen # that all ".." are removed to constrain target to image
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen """Client-side method that installs a hard link."""
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen fulltarget = os.path.normpath(os.path.sep.join(
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen """Returns a tuple of lists of the form (errors, warnings,
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen info). The error list will be empty if the action has been
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen correctly installed in the given image."""
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen # We only allow hard links to regular files, so the hard
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen # link should lstat() as a regular file.
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen errors.append(_("Target '%s' does not exist") %
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen # No point in continuing if no target
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen if os.stat(path).st_ino != os.stat(target).st_ino:
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen errors.append(_("Broken: Path and Target (%s) "
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen "inodes not the same") %