Message123149
> 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. |
|
Date |
User |
Action |
Args |
2010-12-03 00:31:59 | brian.curtin | set | recipients:
+ brian.curtin, amaury.forgeotdarc, jaraco, eric.smith |
2010-12-03 00:31:59 | brian.curtin | set | messageid: <1291336319.51.0.652544301087.issue9333@psf.upfronthosting.co.za> |
2010-12-03 00:31:56 | brian.curtin | link | issue9333 messages |
2010-12-03 00:31:56 | brian.curtin | create | |
|