hardlink.py revision 96
5253N/A#!/usr/bin/python
5253N/A#
5253N/A# CDDL HEADER START
5253N/A#
5253N/A# The contents of this file are subject to the terms of the
5253N/A# Common Development and Distribution License (the "License").
5253N/A# You may not use this file except in compliance with the License.
5253N/A#
5253N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5253N/A# or http://www.opensolaris.org/os/licensing.
5253N/A# See the License for the specific language governing permissions
5253N/A# and limitations under the License.
5253N/A#
5253N/A# When distributing Covered Code, include this CDDL HEADER in each
5253N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5253N/A# If applicable, add the following below this CDDL HEADER, with the
5253N/A# fields enclosed by brackets "[]" replaced with your own identifying
5253N/A# information: Portions Copyright [yyyy] [name of copyright owner]
5253N/A#
5253N/A# CDDL HEADER END
5253N/A#
5253N/A
5253N/A#
5253N/A# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
5253N/A# Use is subject to license terms.
5253N/A#
5253N/A
5253N/A"""module describing a (hard) link packaging object
5253N/A
5253N/AThis module contains the HardLinkAction class, which represents a hardlink-type
5253N/Apackaging object."""
5253N/A
5253N/Aimport os
5253N/A
5253N/Aimport link
5253N/A
5253N/Aclass HardLinkAction(link.LinkAction):
5253N/A """Class representing a hardlink-type packaging object."""
5253N/A
5253N/A name = "hardlink"
5253N/A
5253N/A def __init__(self, data=None, **attrs):
5253N/A link.LinkAction.__init__(self, data, **attrs)
5253N/A
5253N/A def install(self, image, orig):
5253N/A """Client-side method that installs a hard link."""
5253N/A
5253N/A path = self.attrs["path"]
5253N/A target = self.attrs["target"]
5253N/A
5253N/A path = os.path.normpath(os.path.sep.join(
5253N/A (image.get_root(), path)))
5253N/A
5253N/A if os.path.exists(path):
5253N/A os.unlink(path)
5253N/A
5253N/A # If the target has a relative path, we need to construct its
5253N/A # absolute path.
5253N/A if target[0] != "/":
5253N/A target = os.path.normpath(
5253N/A os.path.join(os.path.split(path)[0], target))
5253N/A
5253N/A os.link(target, path)
5253N/A