@@ -1858,6 +1858,12 @@ features:
1858
1858
.. versionchanged :: 3.6
1859
1859
Accepts a :term: `path-like object ` for *src * and *dst *.
1860
1860
1861
+ .. versionchanged :: 3.8
1862
+ On Windows, now opens reparse points that represent another path
1863
+ (name surrogates), including symbolic links and directory junctions.
1864
+ Other kinds of reparse points are resolved by the operating system as
1865
+ for :func: `~os.stat `.
1866
+
1861
1867
1862
1868
.. function :: mkdir(path, mode=0o777, *, dir_fd=None)
1863
1869
@@ -2039,6 +2045,10 @@ features:
2039
2045
This function can also support :ref: `paths relative to directory descriptors
2040
2046
<dir_fd>`.
2041
2047
2048
+ When trying to resolve a path that may contain links, use
2049
+ :func: `~os.path.realpath ` to properly handle recursion and platform
2050
+ differences.
2051
+
2042
2052
.. availability :: Unix, Windows.
2043
2053
2044
2054
.. versionchanged :: 3.2
@@ -2053,6 +2063,11 @@ features:
2053
2063
.. versionchanged :: 3.8
2054
2064
Accepts a :term: `path-like object ` and a bytes object on Windows.
2055
2065
2066
+ .. versionchanged :: 3.8
2067
+ Added support for directory junctions, and changed to return the
2068
+ substitution path (which typically includes ``\\?\ `` prefix) rather
2069
+ than the optional "print name" field that was previously returned.
2070
+
2056
2071
.. function :: remove(path, *, dir_fd=None)
2057
2072
2058
2073
Remove (delete) the file *path *. If *path * is a directory, an
@@ -2366,7 +2381,8 @@ features:
2366
2381
2367
2382
On Unix, this method always requires a system call. On Windows, it
2368
2383
only requires a system call if *follow_symlinks * is ``True `` and the
2369
- entry is a symbolic link.
2384
+ entry is a reparse point (for example, a symbolic link or directory
2385
+ junction).
2370
2386
2371
2387
On Windows, the ``st_ino ``, ``st_dev `` and ``st_nlink `` attributes of the
2372
2388
:class: `stat_result ` are always set to zero. Call :func: `os.stat ` to
@@ -2403,6 +2419,17 @@ features:
2403
2419
This function can support :ref: `specifying a file descriptor <path_fd >` and
2404
2420
:ref: `not following symlinks <follow_symlinks >`.
2405
2421
2422
+ On Windows, passing ``follow_symlinks=False `` will disable following all
2423
+ name-surrogate reparse points, which includes symlinks and directory
2424
+ junctions. Other types of reparse points that do not resemble links or that
2425
+ the operating system is unable to follow will be opened directly. When
2426
+ following a chain of multiple links, this may result in the original link
2427
+ being returned instead of the non-link that prevented full traversal. To
2428
+ obtain stat results for the final path in this case, use the
2429
+ :func: `os.path.realpath ` function to resolve the path name as far as
2430
+ possible and call :func: `lstat ` on the result. This does not apply to
2431
+ dangling symlinks or junction points, which will raise the usual exceptions.
2432
+
2406
2433
.. index :: module: stat
2407
2434
2408
2435
Example::
@@ -2427,6 +2454,14 @@ features:
2427
2454
.. versionchanged :: 3.6
2428
2455
Accepts a :term: `path-like object `.
2429
2456
2457
+ .. versionchanged :: 3.8
2458
+ On Windows, all reparse points that can be resolved by the operating
2459
+ system are now followed, and passing ``follow_symlinks=False ``
2460
+ disables following all name surrogate reparse points. If the operating
2461
+ system reaches a reparse point that it is not able to follow, *stat * now
2462
+ returns the information for the original path as if
2463
+ ``follow_symlinks=False `` had been specified instead of raising an error.
2464
+
2430
2465
2431
2466
.. class :: stat_result
2432
2467
@@ -2578,7 +2613,7 @@ features:
2578
2613
2579
2614
File type.
2580
2615
2581
- On Windows systems, the following attribute is also available:
2616
+ On Windows systems, the following attributes are also available:
2582
2617
2583
2618
.. attribute :: st_file_attributes
2584
2619
@@ -2587,6 +2622,12 @@ features:
2587
2622
:c:func: `GetFileInformationByHandle `. See the ``FILE_ATTRIBUTE_* ``
2588
2623
constants in the :mod: `stat ` module.
2589
2624
2625
+ .. attribute :: st_reparse_tag
2626
+
2627
+ When :attr: `st_file_attributes ` has the ``FILE_ATTRIBUTE_REPARSE_POINT ``
2628
+ set, this field contains the tag identifying the type of reparse point.
2629
+ See the ``IO_REPARSE_TAG_* `` constants in the :mod: `stat ` module.
2630
+
2590
2631
The standard module :mod: `stat ` defines functions and constants that are
2591
2632
useful for extracting information from a :c:type: `stat ` structure. (On
2592
2633
Windows, some items are filled with dummy values.)
@@ -2614,6 +2655,14 @@ features:
2614
2655
.. versionadded :: 3.7
2615
2656
Added the :attr: `st_fstype ` member to Solaris/derivatives.
2616
2657
2658
+ .. versionadded :: 3.8
2659
+ Added the :attr: `st_reparse_tag ` member on Windows.
2660
+
2661
+ .. versionchanged :: 3.8
2662
+ On Windows, the :attr: `st_mode ` member now identifies special
2663
+ files as :const: `S_IFCHR `, :const: `S_IFIFO ` or :const: `S_IFBLK `
2664
+ as appropriate.
2665
+
2617
2666
.. function :: statvfs(path)
2618
2667
2619
2668
Perform a :c:func: `statvfs ` system call on the given path. The return value is
0 commit comments