Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
ee5f1c13
Kaydet (Commit)
ee5f1c13
authored
Nis 01, 2014
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
remove directory mode check from makedirs (closes #21082)
üst
b4be376d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
32 deletions
+20
-32
os.rst
Doc/library/os.rst
+9
-5
os.py
Lib/os.py
+5
-23
test_os.py
Lib/test/test_os.py
+3
-4
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/os.rst
Dosyayı görüntüle @
ee5f1c13
...
...
@@ -1188,11 +1188,8 @@ Files and Directories
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 *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.
If *exist_ok* is ``False`` (the default), an :exc:`OSError` is raised if the
target directory already exists.
.. note::
...
...
@@ -1204,6 +1201,13 @@ Files and Directories
.. versionadded:: 3.2
The *exist_ok* parameter.
.. versionchanged:: 3.2.5
Before Python 3.2.5, if *exist_ok* was ``True`` and the directory existed,
:func:`makedirs` would still raise an error if *mode* did not match the
mode of the existing directory. Since this behavior was impossible to
implement safely, it was removed in Python 3.2.6. See :issue:`21082`.
.. function:: pathconf(path, name)
...
...
Lib/os.py
Dosyayı görüntüle @
ee5f1c13
...
...
@@ -114,12 +114,6 @@ SEEK_SET = 0
SEEK_CUR
=
1
SEEK_END
=
2
def
_get_masked_mode
(
mode
):
mask
=
umask
(
0
)
umask
(
mask
)
return
mode
&
~
mask
#'
# Super directory utilities.
...
...
@@ -128,11 +122,10 @@ def _get_masked_mode(mode):
def
makedirs
(
name
,
mode
=
0
o777
,
exist_ok
=
False
):
"""makedirs(path [, mode=0o777][, exist_ok=False])
Super-mkdir; create a leaf directory and all intermediate ones.
Works like mkdir, except that any intermediate path segment (not
just the rightmost) will be created if it does not exist. If the
target directory with the same mode as we specified already exists,
raises an OSError if exist_ok is False, otherwise no exception is
Super-mkdir; create a leaf directory and all intermediate ones. Works like
mkdir, except that any intermediate path segment (not just the rightmost)
will be created if it does not exist. If the target directory already
exists, raise an OSError if exist_ok is False. Otherwise no exception is
raised. This is recursive.
"""
...
...
@@ -154,18 +147,7 @@ def makedirs(name, mode=0o777, exist_ok=False):
try
:
mkdir
(
name
,
mode
)
except
OSError
as
e
:
import
stat
as
st
dir_exists
=
path
.
isdir
(
name
)
expected_mode
=
_get_masked_mode
(
mode
)
if
dir_exists
:
# S_ISGID is automatically copied by the OS from parent to child
# directories on mkdir. Don't consider it being set to be a mode
# mismatch as mkdir does not unset it when not specified in mode.
actual_mode
=
st
.
S_IMODE
(
lstat
(
name
)
.
st_mode
)
&
~
st
.
S_ISGID
else
:
actual_mode
=
-
1
if
not
(
e
.
errno
==
errno
.
EEXIST
and
exist_ok
and
dir_exists
and
actual_mode
==
expected_mode
):
if
not
exist_ok
or
e
.
errno
!=
errno
.
EEXIST
or
not
path
.
isdir
(
name
):
raise
def
removedirs
(
name
):
...
...
Lib/test/test_os.py
Dosyayı görüntüle @
ee5f1c13
...
...
@@ -579,7 +579,7 @@ class MakedirTests(unittest.TestCase):
os
.
makedirs
(
path
,
mode
)
self
.
assertRaises
(
OSError
,
os
.
makedirs
,
path
,
mode
)
self
.
assertRaises
(
OSError
,
os
.
makedirs
,
path
,
mode
,
exist_ok
=
False
)
self
.
assertRaises
(
OSError
,
os
.
makedirs
,
path
,
0
o776
,
exist_ok
=
True
)
os
.
makedirs
(
path
,
0
o776
,
exist_ok
=
True
)
os
.
makedirs
(
path
,
mode
=
mode
,
exist_ok
=
True
)
finally
:
os
.
umask
(
old_mask
)
...
...
@@ -606,9 +606,8 @@ class MakedirTests(unittest.TestCase):
os
.
makedirs
(
path
,
mode
,
exist_ok
=
True
)
# remove the bit.
os
.
chmod
(
path
,
stat
.
S_IMODE
(
os
.
lstat
(
path
)
.
st_mode
)
&
~
S_ISGID
)
with
self
.
assertRaises
(
OSError
):
# Should fail when the bit is not already set when demanded.
os
.
makedirs
(
path
,
mode
|
S_ISGID
,
exist_ok
=
True
)
# May work even when the bit is not already set when demanded.
os
.
makedirs
(
path
,
mode
|
S_ISGID
,
exist_ok
=
True
)
finally
:
os
.
umask
(
old_mask
)
...
...
Misc/NEWS
Dosyayı görüntüle @
ee5f1c13
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.2.6?
Library
-------
- Issue #21082: In os.makedirs, do not set the process-wide umask. Note this
changes behavior of makedirs when exist_ok=True.
- Issue #20246: Fix buffer overflow in socket.recvfrom_into.
- Issue #12226: HTTPS is now used by default when connecting to PyPI.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment