17096 multi-valued path attributes cause file, link, and directory action traceback in161
authorShawn Walker <shawn.walker@oracle.com>
Fri, 11 Mar 2011 10:43:38 -0800
changeset 2254 ab6a2324f73a
parent 2253 fd7f8e8228ae
child 2255 a7e17274b144
17096 multi-valued path attributes cause file, link, and directory action traceback
src/modules/actions/directory.py
src/modules/actions/file.py
src/modules/actions/generic.py
src/modules/actions/hardlink.py
src/modules/actions/link.py
src/tests/api/t_action.py
--- a/src/modules/actions/directory.py	Fri Mar 11 10:37:57 2011 -0800
+++ b/src/modules/actions/directory.py	Fri Mar 11 10:43:38 2011 -0800
@@ -49,15 +49,6 @@
         refcountable = True
         namespace_group = "path"
 
-        def __init__(self, data=None, **attrs):
-                generic.Action.__init__(self, data, **attrs)
-                if "path" in self.attrs:
-                        self.attrs["path"] = self.attrs["path"].lstrip(
-                            os.path.sep)
-                        if not self.attrs["path"]:
-                                raise pkg.actions.InvalidActionError(
-                                    str(self), _("Empty path attribute"))
-
         def compare(self, other):
                 return cmp(self.attrs["path"], other.attrs["path"])
 
--- a/src/modules/actions/file.py	Fri Mar 11 10:37:57 2011 -0800
+++ b/src/modules/actions/file.py	Fri Mar 11 10:43:38 2011 -0800
@@ -61,11 +61,6 @@
                 generic.Action.__init__(self, data, **attrs)
                 self.hash = "NOHASH"
                 self.replace_required = False
-                if "path" in self.attrs:
-                        self.attrs["path"] = self.attrs["path"].lstrip("/")
-                        if not self.attrs["path"]:
-                                raise pkg.actions.InvalidActionError(
-                                    str(self), _("Empty path attribute"))
 
         # this check is only needed on Windows
         if portable.ostype == "windows":
--- a/src/modules/actions/generic.py	Fri Mar 11 10:37:57 2011 -0800
+++ b/src/modules/actions/generic.py	Fri Mar 11 10:43:38 2011 -0800
@@ -90,6 +90,9 @@
         # Most types of actions do not have a payload.
         has_payload = False
 
+        # By default, leading slashes should be stripped from "path" attribute.
+        _strip_path = True
+
         def loadorderdict(self):
                 ol = [
                         "set",
@@ -138,6 +141,20 @@
                 else:
                         self.set_data(data)
 
+                if not self._strip_path or "path" not in self.attrs:
+                        return
+
+                try:
+                        self.attrs["path"] = self.attrs["path"].lstrip("/")
+                except AttributeError:
+                        raise pkg.actions.InvalidActionError(
+                            str(self), _("path attribute specified multiple "
+                                "times"))
+
+                if not self.attrs["path"]:
+                        raise pkg.actions.InvalidActionError(
+                            str(self), _("Empty path attribute"))
+
         def set_data(self, data):
                 """This function sets the data field of the action.
 
--- a/src/modules/actions/hardlink.py	Fri Mar 11 10:37:57 2011 -0800
+++ b/src/modules/actions/hardlink.py	Fri Mar 11 10:43:38 2011 -0800
@@ -21,7 +21,7 @@
 #
 
 #
-# Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
 #
 
 """module describing a (hard) link packaging object
@@ -46,8 +46,9 @@
 
         name = "hardlink"
 
-        def __init__(self, data=None, **attrs):
-                link.LinkAction.__init__(self, data, **attrs)
+        # Tells parent class that leading slash should not be stripped
+        # from "path" attribute.
+        _strip_path = False
 
         def get_target_path(self):
                 """ return a path for target that is relative to image"""
--- a/src/modules/actions/link.py	Fri Mar 11 10:37:57 2011 -0800
+++ b/src/modules/actions/link.py	Fri Mar 11 10:43:38 2011 -0800
@@ -21,7 +21,7 @@
 #
 
 #
-# Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
 #
 
 """module describing a (symbolic) link packaging object
@@ -49,15 +49,6 @@
         refcountable = True
         namespace_group = "path"
 
-        def __init__(self, data=None, **attrs):
-                generic.Action.__init__(self, data, **attrs)
-                if "path" in self.attrs:
-                        self.attrs["path"] = self.attrs["path"].lstrip(
-                            os.path.sep)
-                        if not self.attrs["path"]:
-                                raise pkg.actions.InvalidActionError(
-                                    str(self), _("Empty path attribute"))
-
         def install(self, pkgplan, orig):
                 """Client-side method that installs a link."""
 
--- a/src/tests/api/t_action.py	Fri Mar 11 10:37:57 2011 -0800
+++ b/src/tests/api/t_action.py	Fri Mar 11 10:43:38 2011 -0800
@@ -361,6 +361,11 @@
                 # Missing key attribute 'fmri'.
                 self.assertInvalid("depend type=require")
 
+                # 'path' attribute specified multiple times
+                self.assertInvalid("file 1234 path=foo path=foo mode=777 owner=root group=root")
+                self.assertInvalid("link path=foo path=foo target=link")
+                self.assertInvalid("dir path=foo path=foo mode=777 owner=root group=root")
+
                 # 'data' used as an attribute key
                 self.assertInvalid("file 1234 path=/tmp/foo data=rubbish")