7908 publishing api and tools should use os.stat not os.lstat for file size
authorShawn Walker <srw@sun.com>
Fri, 10 Apr 2009 22:41:41 -0500
changeset 1038 2514d758e462
parent 1037 56ff5f4fab83
child 1039 2fbbec57abed
7908 publishing api and tools should use os.stat not os.lstat for file size
src/modules/actions/generic.py
src/modules/misc.py
src/publish.py
src/tests/baseline.txt
src/tests/cli/t_pkgsend.py
--- a/src/modules/actions/generic.py	Fri Apr 10 11:44:15 2009 -0700
+++ b/src/modules/actions/generic.py	Fri Apr 10 22:41:41 2009 -0500
@@ -129,7 +129,7 @@
                         self.data = file_opener
                         if "pkg.size" not in self.attrs:
                                 try:
-                                        fs = os.lstat(data)
+                                        fs = os.stat(data)
                                         self.attrs["pkg.size"] = str(fs.st_size)
                                 except EnvironmentError, e:
                                         raise \
--- a/src/modules/misc.py	Fri Apr 10 11:44:15 2009 -0700
+++ b/src/modules/misc.py	Fri Apr 10 22:41:41 2009 -0500
@@ -544,7 +544,7 @@
                 f = data
 
         if length is None:
-                length = os.lstat(data).st_size
+                length = os.stat(data).st_size
 
         # Read the data in chunks and compute the SHA1 hash as it comes in.  A
         # large read on some platforms (e.g. Windows XP) may fail.
--- a/src/publish.py	Fri Apr 10 11:44:15 2009 -0700
+++ b/src/publish.py	Fri Apr 10 22:41:41 2009 -0500
@@ -173,27 +173,24 @@
 
         if not args:
                 usage(_("No arguments specified for subcommand."), cmd="add")
-        elif args[0] in ("file", "license"):
+
+        atype = args[0]
+        data = None
+        if atype in ("file", "license"):
                 if len(args) < 2:
                         raise RuntimeError, _("A filename must be provided "
                             "for this action.")
 
-                try:
-                        action = pkg.actions.fromlist(args[0], args[2:],
-                            data=args[1])
-                except ValueError, e:
-                        error(e[0], cmd="add")
-                        return 1
+                aargs = args[2:]
+                data = args[1]
+        else:
+                aargs = args[1:]
 
-                if "pkg.size" not in action.attrs:
-                        fs = os.lstat(args[1])
-                        action.attrs["pkg.size"] = str(fs.st_size)
-        else:
-                try:
-                        action = pkg.actions.fromlist(args[0], args[1:])
-                except ValueError, e:
-                        error(e[0], cmd="add")
-                        return 1
+        try:
+                action = pkg.actions.fromlist(atype, aargs, data=data)
+        except ValueError, e:
+                error(e[0], cmd="add")
+                return 1
 
         t = trans.Transaction(repo_uri, trans_id=trans_id)
         t.add(action)
--- a/src/tests/baseline.txt	Fri Apr 10 11:44:15 2009 -0700
+++ b/src/tests/baseline.txt	Fri Apr 10 22:41:41 2009 -0500
@@ -455,6 +455,7 @@
 cli.t_pkgsend.py TestPkgsendBasics.test_5_bad_open|pass
 cli.t_pkgsend.py TestPkgsendBasics.test_6_help|pass
 cli.t_pkgsend.py TestPkgsendBasics.test_7_create_repo|pass
+cli.t_pkgsend.py TestPkgsendBasics.test_8_bug_7908|pass
 cli.t_pkgsend.py TestPkgsendRename.test_rename1|pass
 cli.t_pkgsend.py TestPkgsendRename.test_rename2|pass
 cli.t_pkgsend.py TestPkgsendRename.test_rename3|pass
--- a/src/tests/cli/t_pkgsend.py	Fri Apr 10 11:44:15 2009 -0700
+++ b/src/tests/cli/t_pkgsend.py	Fri Apr 10 22:41:41 2009 -0500
@@ -29,6 +29,7 @@
 
 import os
 import shutil
+import tempfile
 import unittest
 
 class TestPkgsendBasics(testutils.SingleDepotTestCase):
@@ -214,6 +215,37 @@
                 # create-repository fails as expected.
                 self.pkgsend("https://invalid.test2", "create-repository bobcat", exit=2)
 
+        def test_8_bug_7908(self):
+                """Verify that when provided the name of a symbolic link to a
+                file, that publishing will still work as expected."""
+
+                # First create our dummy data file.
+                fd, fpath = tempfile.mkstemp(dir=self.get_test_prefix())
+                fp = os.fdopen(fd, "wb")
+                fp.write("foo")
+                fp.close()
+
+                # Then, create a link to it.
+                lpath = os.path.join(self.get_test_prefix(), "test_8_foo")
+                os.symlink(fpath, lpath)
+
+                # Next, publish it using both the real path and the linked path
+                # but using different names.
+                dhurl = self.dc.get_depot_url()
+                self.pkgsend_bulk(dhurl,
+                    """open [email protected]
+                    add file %s mode=0755 owner=root group=bin path=/tmp/f.foo
+                    add file %s mode=0755 owner=root group=bin path=/tmp/l.foo
+                    close""" % (fpath, lpath))
+
+                # Finally, verify that both files were published.
+                self.image_create(dhurl)
+                self.pkg("contents -r -H -o action.raw -t file testlinkedfile |"
+                   " grep 'f.foo.*pkg.size=3'")
+                self.pkg("contents -r -H -o action.raw -t file testlinkedfile |"
+                   " grep 'l.foo.*pkg.size=3'")
+                self.image_destroy()
+
 class TestPkgsendRename(testutils.SingleDepotTestCase):
 
         def test_rename1(self):