Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue13498] os.makedirs exist_ok documentation is incorrect, as is some of the behavior

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Jul 31, 2012, 2:23 AM

Post #1 of 11 (179 views)
Permalink
[issue13498] os.makedirs exist_ok documentation is incorrect, as is some of the behavior

Hynek Schlawack added the comment:

So, IMHO if someone calls os.makedirs with a mode != 0o777, they expect to have the directories having those modes afterward. So raising no error if they exist and have the wrong mode would be a plain bug.

Python 3.3 already has a helpful error message:

FileExistsError: [Errno 17] File exists (mode 777 != expected mode 755): 'foo'

and it also handles the sticky issue gracefully: http://hg.python.org/cpython/file/3a08d766eee3/Lib/os.py#l270

So this are an non-issues for 3.3. I'm not sure if it's severe enough to be back ported to 3.2.

So there’s only one thing left: the docs are wrong and should be fixed about exist_ok's behavior for both 3.2 & 3.3.


That said, I see the rationale for fixing the permissions but we can't just change os.makedirs at this point.

So I'd propose to add a "fix_permissions" bool flag that would allow the "no matter what the state is now, I want dir x with permissions y, do whatever is necessary workflow."

Opinions?

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13498>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 3, 2012, 7:37 AM

Post #2 of 11 (170 views)
Permalink
[issue13498] os.makedirs exist_ok documentation is incorrect, as is some of the behavior [In reply to]

R. David Murray added the comment:

I want the opposite: a way to say I don't care what the mode is as long as it exists. Currently there is no way to do that, as far as I remember.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13498>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 4, 2012, 3:59 AM

Post #3 of 11 (169 views)
Permalink
[issue13498] os.makedirs exist_ok documentation is incorrect, as is some of the behavior [In reply to]

Hynek Schlawack added the comment:

do you want it by default or a new flag? default sounds like a source for obscure bugs to me.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13498>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 4, 2012, 12:28 PM

Post #4 of 11 (167 views)
Permalink
[issue13498] os.makedirs exist_ok documentation is incorrect, as is some of the behavior [In reply to]

R. David Murray added the comment:

I *want* it to be the default, since I think that is the typical use case, but the existing default behavior means that such a backward incompatible change would not be acceptable for exactly the reason you state. So yes, I want it as a new flag. ("exist_really_ok", he says with tongue in cheek.) I haven't given much thought to the API, but perhaps there could be a value for the umask that means "don't care"?

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13498>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 5, 2012, 4:28 AM

Post #5 of 11 (165 views)
Permalink
[issue13498] os.makedirs exist_ok documentation is incorrect, as is some of the behavior [In reply to]

Hynek Schlawack added the comment:

How about something along of:

new arg on_wrong_perm=

1. WRONG_PERM_IGNORE
2. WRONG_PERM_FAIL
3. callable that gets called with the directory name and maybe the existing perms to save stat call_

?

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13498>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 13, 2012, 3:19 AM

Post #6 of 11 (151 views)
Permalink
[issue13498] os.makedirs exist_ok documentation is incorrect, as is some of the behavior [In reply to]

Hynek Schlawack added the comment:

Silence means consent, so I will supply a patch as soon as 3.4 is open.

Meanwhile, I reworded the docs for os.makedirs, the patch is attached. Please have a look at it so we can get it in for 3.3.

----------
keywords: +patch
stage: needs patch -> patch review
Added file: http://bugs.python.org/file26781/os-makedirs.diff

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13498>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 13, 2012, 5:40 AM

Post #7 of 11 (146 views)
Permalink
[issue13498] os.makedirs exist_ok documentation is incorrect, as is some of the behavior [In reply to]

R. David Murray added the comment:

Silence doesn't mean consent, but it does mean you can go ahead and see if anyone complains :)

I think your proposal is fine, but I'd prefer making the sentinels just "IGNORE" and "FAIL". The module namespace means the names themselves don't have to be fully qualified.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13498>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 13, 2012, 7:52 AM

Post #8 of 11 (145 views)
Permalink
[issue13498] os.makedirs exist_ok documentation is incorrect, as is some of the behavior [In reply to]

Hynek Schlawack added the comment:

> Silence doesn't mean consent, but it does mean you can go ahead and see if anyone complains :)

Well that's what I meant. :)

> I think your proposal is fine, but I'd prefer making the sentinels just "IGNORE" and "FAIL". The module namespace means the names themselves don't have to be fully qualified.

I thought about that but found them pretty...generic.

Anyway, that's 3.4-fodder. Could you have a look at the doc fix please?
It applies against 3.2.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13498>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 13, 2012, 8:13 AM

Post #9 of 11 (145 views)
Permalink
[issue13498] os.makedirs exist_ok documentation is incorrect, as is some of the behavior [In reply to]

R. David Murray added the comment:

English-wise I would drop the "Also".

You say "differs from the one supplied", but given the rest of the text I would expect that it is really "differs from the supplied mode masked with the current umask, on systems where the mode is respected", which is a mouthful :(.

Perhaps it would flow better if the discussion of exists_ok came after the discussion of mode (that is, as the last thing in the paragraph).

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13498>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 18, 2012, 8:14 AM

Post #10 of 11 (151 views)
Permalink
[issue13498] os.makedirs exist_ok documentation is incorrect, as is some of the behavior [In reply to]

Hynek Schlawack added the comment:

Ok, let’s do it here, that’s easier:


.. function:: makedirs(path, mode=0o777, exist_ok=False)

.. index::
single: directory; creating
single: UNC paths; and os.makedirs()

Recursive directory creation function. Like :func:`mkdir`, but makes all
intermediate-level directories needed to contain the leaf directory.

The default *mode* is ``0o777`` (octal). On some systems, *mode* is
ignored. Where it is used, the current umask value is first masked out.

If the target directory exists, :exc:`OSError` is raised unless *exist_ok*
is set to ``True`` and the mode doesn't contradict the designated mode as
discussed in the previous paragraph. If the mode doesn't match,
:exc:`OSError` is raised regardless of the value of *exist_ok*. If the
directory cannot be created in other cases, an :exc:`OSError` exception is
raised too.

.. note::

:func:`makedirs` will become confused if the path elements to create
include :data:`pardir`.

This function handles UNC paths correctly.

.. versionadded:: 3.2
The *exist_ok* parameter.


Python is so much easier than English. :'(

----------
versions: +Python 3.4

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13498>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 18, 2012, 9:14 AM

Post #11 of 11 (144 views)
Permalink
[issue13498] os.makedirs exist_ok documentation is incorrect, as is some of the behavior [In reply to]

R. David Murray added the comment:

This is much better. But let me try tuning the problem paragraph a bit, since I'm a native English speaker:

If *exists_ok* is ``False`` (the default), an :exc:`OSError` is raised if
the target directory already exists. If *exists_ok* is ``True`` an
:exc:`OSError` is still raised if the umask-masked *mode* is different from
the existing mode, on systems where the mode is used. :exc:`OSError` will
also be raised if the directory creation fails.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue13498>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.