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