#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#
"""module describing a directory packaging object
This module contains the DirectoryAction class, which represents a
directory-type packaging object."""
import errno
from . import generic
import os
import stat
"""Class representing a directory-type packaging object."""
__slots__ = []
"""Returns a list of attributes that have different values
between 'other' and 'self'. This differs from the generic
Action's differences() method in that it normalizes the 'mode'
attribute so that, say, '0755' and '755' are treated as
identical."""
if "mode" in diffs and \
return diffs
"""Create a directory."""
try:
except OSError as e:
# makedirs failed for some component
# of the path.
raise
# Treat EROFS like EEXIST if both are
# applicable, since we'll end up with
# EROFS instead.
return
raise
raise
# User has replaced directory with a
# link, or a package has been poorly
# implemented. It isn't safe to
# simply re-create the directory as
# that won't restore the files that
# are supposed to be contained within.
err_txt = _("Unable to create "
"directory {0}; it has been "
"replaced with a link. To "
"continue, please remove the "
"link or restore the directory "
"to its original location and "
raise apx.ActionExecutionError(
# User has replaced directory with a
# file, or a package has been poorly
# implemented. Salvage what's there,
# and drive on.
# The directory already exists, but
# ensure that the mode matches what's
# expected.
"""Client-side method that installs a directory."""
mode = None
try:
except (TypeError, ValueError):
# Mode isn't valid, so let validate raise a more
# informative error.
if orig:
try:
except (TypeError, ValueError):
# Mode isn't valid, so let validate raise a more
# informative error.
# Don't allow installation through symlinks.
# XXX Hack! (See below comment.)
if not orig:
# The downside of chmodding the directory is that as a non-root
# user, if we set perms u-w, we won't be able to put anything in
# it, which is often not what we want at install time. We save
# the chmods for the postinstall phase, but it's always possible
# that a later package install will want to place something in
# this directory and then be unable to. So perhaps we need to
# (in all action types) chmod the parent directory to u+w on
# failure, and chmod it back aftwards. The trick is to
# recognize failure due to missing file_dac_write in contrast to
# other failures. Or can we require that everyone simply have
# file_dac_write who wants to use the tools. Probably not.
try:
except Exception as e:
# Assume chmod failed due to a
# recoverable error.
mode)
# if we're salvaging contents, move 'em now.
# directories with "salvage-from" attribute
# set will scavenge any available contents
# that matches specified directory and
# move it underneath itself on install or update.
# This is here to support directory rename
# when old directory has unpackaged contents, or
# consolidation of content from older directories.
try:
except OSError as e:
# Assume chown failed due to a
# recoverable error.
"""Returns a tuple of lists of the form (errors, warnings,
info). The error list will be empty if the action has been
correctly installed in the given image."""
try:
except OSError as e:
pass
# Cannot remove directory since it's
# not empty.
# Either the user or another package has changed
# this directory into a link or file. Salvage
# what's there and drive on.
# User has replaced directory with mountpoint,
# or a package has been poorly implemented.
err_txt = _("Unable to remove {0}; it is "
"in use as a mountpoint. To "
"continue, please unmount the "
"filesystem at the target "
"location and try again.").format(
path)
# os.path.ismount() is broken for lofs
# filesystems, so give a more generic
# error.
err_txt = _("Unable to remove {0}; it "
"is in use by the system, another "
"process, or as a "
raise
"""Generates the indices needed by the search dictionary. See
generic.py for a more detailed explanation."""
return [
None),
None)
]
"""Performs additional validation of action attributes that
for performance or other reasons cannot or should not be done
during Action object creation. An ActionError exception (or
subclass of) will be raised if any attributes are not valid.
This is primarily intended for use during publication or during
error handling to provide additional diagonostics.
'fmri' is an optional package FMRI (object or string) indicating
what package contained this action."""
if errors: