src/modules/actions/link.py
author Shawn Walker <shawn.walker@oracle.com>
Fri, 11 Mar 2011 10:43:38 -0800
changeset 2254 ab6a2324f73a
parent 2205 53d0be594162
permissions -rw-r--r--
17096 multi-valued path attributes cause file, link, and directory action traceback
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1516
8c950a3b4171 10485 move pkg(5) to Python 2.6
Rich Burridge <rich.burridge@sun.com>
parents: 1507
diff changeset
     1
#!/usr/bin/python
49
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
     2
#
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
     3
# CDDL HEADER START
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
     4
#
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
     8
#
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    12
# and limitations under the License.
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    13
#
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    19
#
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    20
# CDDL HEADER END
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    21
#
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    22
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    23
#
2254
ab6a2324f73a 17096 multi-valued path attributes cause file, link, and directory action traceback
Shawn Walker <shawn.walker@oracle.com>
parents: 2205
diff changeset
    24
# Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
49
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    25
#
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    26
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    27
"""module describing a (symbolic) link packaging object
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    28
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    29
This module contains the LinkAction class, which represents a link-type
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    30
packaging object."""
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    31
1507
b956ea23d3a6 11735 pkg history data files should not be executable
Richard Lowe <richlowe@richlowe.net>
parents: 1281
diff changeset
    32
import errno
51
d04d55e16d0b Simplify the action API and add real support for client-side installation
Danek Duvall <danek.duvall@sun.com>
parents: 49
diff changeset
    33
import os
1507
b956ea23d3a6 11735 pkg history data files should not be executable
Richard Lowe <richlowe@richlowe.net>
parents: 1281
diff changeset
    34
import stat
51
d04d55e16d0b Simplify the action API and add real support for client-side installation
Danek Duvall <danek.duvall@sun.com>
parents: 49
diff changeset
    35
49
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    36
import generic
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 583
diff changeset
    37
import pkg.actions
1507
b956ea23d3a6 11735 pkg history data files should not be executable
Richard Lowe <richlowe@richlowe.net>
parents: 1281
diff changeset
    38
from pkg import misc
49
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    39
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    40
class LinkAction(generic.Action):
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    41
        """Class representing a link-type packaging object."""
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    42
1846
37cc4d517320 15386 action fromstr could pool attribute names to reduce memory usage
Shawn Walker <shawn.walker@oracle.com>
parents: 1713
diff changeset
    43
        __slots__ = []
37cc4d517320 15386 action fromstr could pool attribute names to reduce memory usage
Shawn Walker <shawn.walker@oracle.com>
parents: 1713
diff changeset
    44
51
d04d55e16d0b Simplify the action API and add real support for client-side installation
Danek Duvall <danek.duvall@sun.com>
parents: 49
diff changeset
    45
        name = "link"
72
9deed41412b3 Support for proper package upgrade.
Danek Duvall <danek.duvall@sun.com>
parents: 71
diff changeset
    46
        key_attr = "path"
2205
53d0be594162 3822 image plans should prevent conflicting actions from being installed
Danek Duvall <danek.duvall@oracle.com>
parents: 1859
diff changeset
    47
        unique_attrs = "path", "target"
53d0be594162 3822 image plans should prevent conflicting actions from being installed
Danek Duvall <danek.duvall@oracle.com>
parents: 1859
diff changeset
    48
        globally_identical = True
53d0be594162 3822 image plans should prevent conflicting actions from being installed
Danek Duvall <danek.duvall@oracle.com>
parents: 1859
diff changeset
    49
        refcountable = True
53d0be594162 3822 image plans should prevent conflicting actions from being installed
Danek Duvall <danek.duvall@oracle.com>
parents: 1859
diff changeset
    50
        namespace_group = "path"
51
d04d55e16d0b Simplify the action API and add real support for client-side installation
Danek Duvall <danek.duvall@sun.com>
parents: 49
diff changeset
    51
136
da65641c4607 Add the license action
Danek Duvall <danek.duvall@sun.com>
parents: 72
diff changeset
    52
        def install(self, pkgplan, orig):
49
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    53
                """Client-side method that installs a link."""
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 53
diff changeset
    54
51
d04d55e16d0b Simplify the action API and add real support for client-side installation
Danek Duvall <danek.duvall@sun.com>
parents: 49
diff changeset
    55
                path = self.attrs["path"]
d04d55e16d0b Simplify the action API and add real support for client-side installation
Danek Duvall <danek.duvall@sun.com>
parents: 49
diff changeset
    56
                target = self.attrs["target"]
d04d55e16d0b Simplify the action API and add real support for client-side installation
Danek Duvall <danek.duvall@sun.com>
parents: 49
diff changeset
    57
53
68b135443ad9 fix usage os.path.join() for absolute paths
Danek Duvall <danek.duvall@sun.com>
parents: 51
diff changeset
    58
                path = os.path.normpath(os.path.sep.join(
136
da65641c4607 Add the license action
Danek Duvall <danek.duvall@sun.com>
parents: 72
diff changeset
    59
                    (pkgplan.image.get_root(), path)))
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 53
diff changeset
    60
1859
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1846
diff changeset
    61
                # Don't allow installation through symlinks.
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1846
diff changeset
    62
                self.fsobj_checkpath(pkgplan, path)
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1846
diff changeset
    63
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 242
diff changeset
    64
                if not os.path.exists(os.path.dirname(path)):
1507
b956ea23d3a6 11735 pkg history data files should not be executable
Richard Lowe <richlowe@richlowe.net>
parents: 1281
diff changeset
    65
                        self.makedirs(os.path.dirname(path),
1859
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1846
diff changeset
    66
                            mode=misc.PKG_DIR_MODE,
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1846
diff changeset
    67
                            fmri=pkgplan.destination_fmri)
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 242
diff changeset
    68
1050
54c841d1fad9 1770 Invalid "Not owner" error when path is delivered as both directory and symlink
Danek Duvall <danek.duvall@sun.com>
parents: 941
diff changeset
    69
                # XXX The exists-unlink-symlink path appears to be as safe as it
54c841d1fad9 1770 Invalid "Not owner" error when path is delivered as both directory and symlink
Danek Duvall <danek.duvall@sun.com>
parents: 941
diff changeset
    70
                # gets to modify a link with the current symlink(2) interface.
71
d1c84919bea6 Fix link install when the link already exists.
Danek Duvall <danek.duvall@sun.com>
parents: 66
diff changeset
    71
                if os.path.lexists(path):
1859
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1846
diff changeset
    72
                        self.remove(pkgplan)
51
d04d55e16d0b Simplify the action API and add real support for client-side installation
Danek Duvall <danek.duvall@sun.com>
parents: 49
diff changeset
    73
                os.symlink(target, path)
49
c3a70bdc4527 First cut of actions; make file transfer generic.
Danek Duvall <danek.duvall@sun.com>
parents:
diff changeset
    74
237
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 222
diff changeset
    75
        def verify(self, img, **args):
1685
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    76
                """Returns a tuple of lists of the form (errors, warnings,
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    77
                info).  The error list will be empty if the action has been
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    78
                correctly installed in the given image."""
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    79
222
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 144
diff changeset
    80
                path = self.attrs["path"]
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 144
diff changeset
    81
                target = self.attrs["target"]
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 144
diff changeset
    82
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 144
diff changeset
    83
                path = os.path.normpath(os.path.sep.join(
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 144
diff changeset
    84
                    (img.get_root(), path)))
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 409
diff changeset
    85
1685
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    86
                lstat, errors, warnings, info, abort = \
1281
b05bb3f65f58 10394 link action emits cryptic message when target is wrong
Dan Price <dp@eng.sun.com>
parents: 1100
diff changeset
    87
                    self.verify_fsobj_common(img, stat.S_IFLNK)
b05bb3f65f58 10394 link action emits cryptic message when target is wrong
Dan Price <dp@eng.sun.com>
parents: 1100
diff changeset
    88
b05bb3f65f58 10394 link action emits cryptic message when target is wrong
Dan Price <dp@eng.sun.com>
parents: 1100
diff changeset
    89
                if abort:
b05bb3f65f58 10394 link action emits cryptic message when target is wrong
Dan Price <dp@eng.sun.com>
parents: 1100
diff changeset
    90
                        assert errors
1685
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    91
                        return errors, warnings, info
222
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 144
diff changeset
    92
237
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 222
diff changeset
    93
                atarget = os.readlink(path)
222
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 144
diff changeset
    94
237
6ece196588cb 348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 222
diff changeset
    95
                if target != atarget:
1685
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    96
                        errors.append(_("Target: '%(found)s' should be "
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    97
                            "'%(expected)s'") % { "found": atarget,
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    98
                            "expected": target })
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    99
                return errors, warnings, info
222
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 144
diff changeset
   100
136
da65641c4607 Add the license action
Danek Duvall <danek.duvall@sun.com>
parents: 72
diff changeset
   101
        def remove(self, pkgplan):
1859
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1846
diff changeset
   102
                """Removes the installed link from the system.  If something
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1846
diff changeset
   103
                other than a link is found at the destination location, it
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1846
diff changeset
   104
                will be removed or salvaged."""
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1846
diff changeset
   105
66
e307f4f837c3 support package removal
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
   106
                path = os.path.normpath(os.path.sep.join(
136
da65641c4607 Add the license action
Danek Duvall <danek.duvall@sun.com>
parents: 72
diff changeset
   107
                    (pkgplan.image.get_root(), self.attrs["path"])))
1859
6e6e866921e7 529 client can traceback with EBUSY during action removal
Shawn Walker <shawn.walker@oracle.com>
parents: 1846
diff changeset
   108
                return self.remove_fsobj(pkgplan, path)
140
7b51de906b2d add 'path' search index
Danek Duvall <danek.duvall@sun.com>
parents: 136
diff changeset
   109
144
ce619e0b453f Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents: 140
diff changeset
   110
        def generate_indices(self):
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1050
diff changeset
   111
                """Generates the indices needed by the search dictionary.  See
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1050
diff changeset
   112
                generic.py for a more detailed explanation."""
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1050
diff changeset
   113
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 583
diff changeset
   114
                return [
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 583
diff changeset
   115
                    (self.name, "basename", os.path.basename(self.attrs["path"]),
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 583
diff changeset
   116
                    None),
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 583
diff changeset
   117
                    (self.name, "path", os.path.sep + self.attrs["path"], None)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 583
diff changeset
   118
                ]