This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: shutil.move creates a new directory even on failure
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: JelleZijlstra, miss-islington, orsenthil, winsonluk
Priority: normal Keywords: patch

Created on 2020-12-29 18:38 by winsonluk, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 24001 merged winsonluk, 2020-12-29 18:39
PR 24709 closed miss-islington, 2021-03-02 20:53
PR 24710 closed miss-islington, 2021-03-02 20:53
PR 24711 closed miss-islington, 2021-03-02 21:16
PR 24724 merged miss-islington, 2021-03-03 15:17
PR 24725 merged orsenthil, 2021-03-03 15:34
PR 31971 merged JelleZijlstra, 2022-03-18 01:44
Messages (6)
msg384021 - (view) Author: Winson Luk (winsonluk) * Date: 2020-12-29 18:42
shutil.move calls shutil.copytree(), then os.rmtree() (in that order). If the user does not have permission to delete the source directory, copytree succeeds but rmtree fails. The user sees an error (Permission Denied), but the destination directory is still created. The expected behavior should be a Permission Denied without the creation of the destination directory.
msg384023 - (view) Author: Winson Luk (winsonluk) * Date: 2020-12-29 18:53
To replicate:

$ mkdir foo
$ sudo chown root foo
$ sudo touch foo/child
$ python3
>>> import shutil
>>> shutil.move('foo', 'bar')
PermissionError
$ ls foo
child
$ ls bar
child

If shutil.move() encountered a permission error and failed, bar should not have been created.
msg387969 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2021-03-02 20:53
New changeset 132131b404e06ee1a19b040a1f96cd1118abed0c by Winson Luk in branch 'master':
bpo-42782: Fail fast for permission errors in shutil.move() (GH-24001)
https://github.com/python/cpython/commit/132131b404e06ee1a19b040a1f96cd1118abed0c
msg388024 - (view) Author: miss-islington (miss-islington) Date: 2021-03-03 15:37
New changeset 59e857650cf49a5e28cb82acc2641b1b53efeeeb by Miss Islington (bot) in branch '3.8':
bpo-42782: Fail fast for permission errors in shutil.move() (GH-24001)
https://github.com/python/cpython/commit/59e857650cf49a5e28cb82acc2641b1b53efeeeb
msg388026 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2021-03-03 16:04
New changeset bf566847f5a97e6ce391f8fb94185ee756cb94a2 by Senthil Kumaran in branch '3.9':
[3.9] bpo-42782: Fail fast for permission errors in shutil.move() (GH-24001) (#24725)
https://github.com/python/cpython/commit/bf566847f5a97e6ce391f8fb94185ee756cb94a2
msg415466 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2022-03-18 02:46
New changeset e808c9d5c78e5a7a9d804eced013a02c0c7df1a5 by Jelle Zijlstra in branch '3.9':
[3.9] bpo-42782: fix broken shutil test (GH-31971)
https://github.com/python/cpython/commit/e808c9d5c78e5a7a9d804eced013a02c0c7df1a5
History
Date User Action Args
2022-04-11 14:59:39adminsetgithub: 86948
2022-03-18 02:46:04orsenthilsetmessages: + msg415466
2022-03-18 01:44:26JelleZijlstrasetnosy: + JelleZijlstra

pull_requests: + pull_request30061
2021-03-03 18:20:35orsenthilsetstage: resolved -> patch review
2021-03-03 16:04:24orsenthilsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-03-03 16:04:08orsenthilsetmessages: + msg388026
2021-03-03 15:37:29miss-islingtonsetmessages: + msg388024
2021-03-03 15:34:48orsenthilsetpull_requests: + pull_request23498
2021-03-03 15:17:03miss-islingtonsetpull_requests: + pull_request23497
2021-03-02 21:16:20miss-islingtonsetpull_requests: + pull_request23489
2021-03-02 20:53:56miss-islingtonsetpull_requests: + pull_request23488
2021-03-02 20:53:49miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request23487
2021-03-02 20:53:27orsenthilsetmessages: + msg387969
2021-03-02 20:52:51orsenthilsetassignee: orsenthil

nosy: + orsenthil
2021-03-02 20:52:46orsenthilsetversions: - Python 3.6, Python 3.7
2020-12-29 18:53:22winsonluksetmessages: + msg384023
2020-12-29 18:42:56winsonluksetmessages: + msg384021
2020-12-29 18:39:41winsonluksetkeywords: + patch
stage: patch review
pull_requests: + pull_request22843
2020-12-29 18:38:15winsonlukcreate