Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6b5b013b
Commit
6b5b013b
authored
May 04, 2019
by
Joannah Nanjekye
Committed by
Antoine Pitrou
May 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-26978: Implement pathlib.Path.link_to (Using os.link) (GH-12990)
parent
f0900199
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
0 deletions
+42
-0
Doc/library/pathlib.rst
Doc/library/pathlib.rst
+7
-0
Doc/whatsnew/3.8.rst
Doc/whatsnew/3.8.rst
+4
-0
Lib/pathlib.py
Lib/pathlib.py
+10
-0
Lib/test/test_pathlib.py
Lib/test/test_pathlib.py
+19
-0
Misc/NEWS.d/next/Library/2019-04-28-01-52-39.bpo-26978.Lpm-SI.rst
...S.d/next/Library/2019-04-28-01-52-39.bpo-26978.Lpm-SI.rst
+2
-0
No files found.
Doc/library/pathlib.rst
View file @
6b5b013b
...
...
@@ -1054,6 +1054,13 @@ call fails (for example because the path doesn't exist).
use :func:`Path.rmdir` instead.
.. method:: Path.link_to(target)
Create a hard link pointing to a path named *target*.
.. versionchanged:: 3.8
.. method:: Path.write_bytes(data)
Open the file pointed to in bytes mode, write *data* to it, and close the
...
...
Doc/whatsnew/3.8.rst
View file @
6b5b013b
...
...
@@ -369,6 +369,10 @@ pathlib
contain characters unrepresentable at the OS level.
(Contributed by Serhiy Storchaka in :issue:`33721`.)
Added :meth:`pathlib.Path.link_to()` which creates a hard link pointing
to a path.
(Contributed by Joannah Nanjekye in :issue:`26978`)
socket
------
...
...
Lib/pathlib.py
View file @
6b5b013b
...
...
@@ -411,6 +411,8 @@ class _NormalAccessor(_Accessor):
unlink
=
os
.
unlink
link_to
=
os
.
link
rmdir
=
os
.
rmdir
rename
=
os
.
rename
...
...
@@ -1303,6 +1305,14 @@ class Path(PurePath):
self
.
_raise_closed
()
return
self
.
_accessor
.
lstat
(
self
)
def
link_to
(
self
,
target
):
"""
Create a hard link pointing to a path named target.
"""
if
self
.
_closed
:
self
.
_raise_closed
()
self
.
_accessor
.
link_to
(
self
,
target
)
def
rename
(
self
,
target
):
"""
Rename this path to the given path.
...
...
Lib/test/test_pathlib.py
View file @
6b5b013b
...
...
@@ -1643,6 +1643,25 @@ class _BasePathTest(object):
self
.
assertFileNotFound
(
p
.
stat
)
self
.
assertFileNotFound
(
p
.
unlink
)
def
test_link_to
(
self
):
P
=
self
.
cls
(
BASE
)
p
=
P
/
'fileA'
size
=
p
.
stat
().
st_size
# linking to another path.
q
=
P
/
'dirA'
/
'fileAA'
try
:
p
.
link_to
(
q
)
except
PermissionError
as
e
:
self
.
skipTest
(
'os.link(): %s'
%
e
)
self
.
assertEqual
(
q
.
stat
().
st_size
,
size
)
self
.
assertEqual
(
os
.
path
.
samefile
(
p
,
q
),
True
)
self
.
assertTrue
(
p
.
stat
)
# Linking to a str of a relative path.
r
=
rel_join
(
'fileAAA'
)
q
.
link_to
(
r
)
self
.
assertEqual
(
os
.
stat
(
r
).
st_size
,
size
)
self
.
assertTrue
(
q
.
stat
)
def
test_rename
(
self
):
P
=
self
.
cls
(
BASE
)
p
=
P
/
'fileA'
...
...
Misc/NEWS.d/next/Library/2019-04-28-01-52-39.bpo-26978.Lpm-SI.rst
0 → 100644
View file @
6b5b013b
`pathlib.path.link_to()` is now implemented. It creates a hard link pointing
to a path.
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