[Downloader] Fix problem with copying directory tree. #2690
No reviewers
Labels
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!2690
Loading…
Reference in a new issue
No description provided.
Delete branch "patch_2685"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type
Description of the changes
fix #2685
This might not be perfect solution as we have to clear
distutils.dir_util._path_createddict, but it seems like the best way to fix this, if we don't want to reimplementdistutils.dir_util.copy_tree.I'd like to explore this a bit more before using this particular fix to ensure resetting
distutils.dir_util._path_createdwon't have extra side effects which aren't acceptable.Additionally, shutil.copy_tree doesn't directly call any platform specific code, and we can copy the 3.8 implementation of it into
redbot.core.utilswith proper attribution if this fix does have undesirable side effects.(see bpo-20849 for more details)
When moving a directory tree in Python comes down to messing with the internals of distutils... Makes me wonder whether it's worth looking elsewhere (3rd party) or implementing it ourselves
Okay, while I understand why we may not want to mess with internals just to copy directory directory tree, it seemed as a better option than having to copy updated implementation of shutil.copy_tree from Python 3.8 just for
Before crating this PR I checked to make sure, that
_path_createdis not used for anything else than checking if path was created previously by dir_util and that variable is only used in 2 places:mkpathwhich check if path was created before trying to create it again (which is only put there to eliminate redundant calls and that will still happen as we only clear_path_createdbefore usingcopy_tree) andremove_treewhich removes paths from this cache after removing a particular directory.Not sure if it makes it any better for you, that even Python's tests clear
_path_createdin tests running multiple times to make sure, that dir_util's cache won't cause any issues.https://github.com/python/cpython/blob/3.7/Lib/test/libregrtest/refleak.py#L201
I know it makes a code look a little obscure, but I still believe this solution is better than pretty much duplicating code of what is already available in Python.
I'm not super happy about this, but I can't find any reason for which this is unsafe to use.
I'd prefer if you added a comment linking to the issue and this PR next to that line prior to merge, but I'm fine with this being the solution used.
Is this fine?
Yep, just something to prevent people from scratching heads at this later
Okay, I added it.