This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author brian.curtin
Recipients amaury.forgeotdarc, brian.curtin, eric.smith, jaraco
Date 2010-12-03.00:31:55
SpamBayes Score 4.440892e-16
Marked as misclassified No
Message-id <1291336319.51.0.652544301087.issue9333@psf.upfronthosting.co.za>
In-reply-to
Content
> So the presence of os.symlink depends on some dynamic privilege?

Yes.


> Why not simply raise an exception when the user has not enough
> privileges? (I mean OSError or WindowsError of course, not AttributeError)

My thinking was that anyone writing cross-platform code which uses symlink in any way is already doing hasattr(os, "symlink"), and if they get a symlink attribute, it should work. With an exception they would have to add an additional try/except for the common case that os.symlink would fail due to lack of privilege on Windows.

I suspect that most people are not running with the required privilege, as evidenced by a look around the web at how others have written and tested this area of code in their applications. Even if someone has an account with administrator-level access, the command prompt starts up with regular privileges, so even those users (e.g., myself) would experience os.symlink raising an exception. Until the application is started explicitly with administrator privileges by an account blessed with access to the symlink privilege does the os.symlink even provide value.

This was noticed in virtualenv3 right off the bat when the first os.symlink checkin happened (see msg112322). They do the hasattr check and go ahead expecting it to work, and it would not work in their case no matter what checks they would do. I've seen other applications setup to do the same thing.


In the end, I'd rather not make people do this:

if hasattr(os, "symlink"):
    if not os.path.exists(dest):
        try:
            os.symlink(src, dest)
        except OSError:
            print("no privilege")

but instead allow them to do what they are likely already be doing:            

if hasattr(os, "symlink"):
    if not os.path.exists(dest):
        os.symlink(src, dest)


For new uses of os.symlink on Windows versions which support it, it may appear a bit unorthodox. I accept that, and I wish it could "just work", but we're given a complex set of hoops to jump through in order to make this usable in any case. I made my decision based on the small percentage of times where this functionality is even available, coupled with existing usage of the function.
History
Date User Action Args
2010-12-03 00:31:59brian.curtinsetrecipients: + brian.curtin, amaury.forgeotdarc, jaraco, eric.smith
2010-12-03 00:31:59brian.curtinsetmessageid: <1291336319.51.0.652544301087.issue9333@psf.upfronthosting.co.za>
2010-12-03 00:31:56brian.curtinlinkissue9333 messages
2010-12-03 00:31:56brian.curtincreate