[Downloader] Fix problem with copying directory tree. #2690

Merged
Jackenmen merged 2 commits from patch_2685 into V3/develop 2019-05-23 09:08:14 +02:00
Jackenmen commented 2019-05-16 16:43:25 +02:00 (Migrated from github.com)

Type

  • Bugfix
  • Enhancement
  • New feature

Description of the changes

fix #2685
This might not be perfect solution as we have to clear distutils.dir_util._path_created dict, but it seems like the best way to fix this, if we don't want to reimplement distutils.dir_util.copy_tree.

### Type - [x] Bugfix - [ ] Enhancement - [ ] New feature ### Description of the changes fix #2685 This might not be perfect solution as we have to clear `distutils.dir_util._path_created` dict, but it seems like the best way to fix this, if we don't want to reimplement `distutils.dir_util.copy_tree`.
tekulvw (Migrated from github.com) reviewed 2019-05-16 16:43:25 +02:00
mikeshardmind commented 2019-05-22 02:08:24 +02:00 (Migrated from github.com)

I'd like to explore this a bit more before using this particular fix to ensure resetting distutils.dir_util._path_created won'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.utils with proper attribution if this fix does have undesirable side effects.

(see bpo-20849 for more details)

I'd like to explore this a bit more before using this particular fix to ensure resetting `distutils.dir_util._path_created` won'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.utils` with proper attribution if this fix does have undesirable side effects. (see [bpo-20849](https://github.com/python/cpython/commit/9e00d9e88fbf943987e4771c753f5ca8f794103e) for more details)
Tobotimus commented 2019-05-22 04:01:16 +02:00 (Migrated from github.com)

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

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
Jackenmen commented 2019-05-22 07:20:22 +02:00 (Migrated from github.com)

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_created is not used for anything else than checking if path was created previously by dir_util and that variable is only used in 2 places: mkpath which 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_created before using copy_tree) and remove_tree which 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_created in 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.

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_created` is not used for anything else than checking if path was created previously by dir_util and that variable is only used in 2 places: `mkpath` which 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_created` before using `copy_tree`) and `remove_tree` which 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_created` in 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.
mikeshardmind (Migrated from github.com) requested changes 2019-05-23 02:06:10 +02:00
mikeshardmind (Migrated from github.com) left a comment

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.

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.
Jackenmen commented 2019-05-23 08:48:02 +02:00 (Migrated from github.com)

Is this fine?

# clear copy_tree's cache to make sure missing directories are created (GH-2690)
Is this fine? ``` # clear copy_tree's cache to make sure missing directories are created (GH-2690) ```
mikeshardmind commented 2019-05-23 08:50:36 +02:00 (Migrated from github.com)

Yep, just something to prevent people from scratching heads at this later

Yep, just something to prevent people from scratching heads at this later
Jackenmen commented 2019-05-23 09:04:16 +02:00 (Migrated from github.com)

Okay, I added it.

Okay, I added it.
mikeshardmind (Migrated from github.com) approved these changes 2019-05-23 09:08:06 +02:00
Sign in to join this conversation.
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 milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!2690
No description provided.