Repository: Cog-Creators/Red-DiscordBot

Issue:
Can't remove paths added before backup
# Command bugs

<!-- 
Did you find a bug with a command? Fill out the following:
-->

#### Command name

`removepath`

#### What cog is this command from?

CogManagerUI

#### What were you expecting to happen?

The path to be removed

#### What actually happened?

It errored: 

<details>
<summary>Traceback</summary>

```py
Exception in command 'removepath'
Traceback (most recent call last):
  File "C:\Users\host\redenv\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\host\redenv\lib\site-packages\redbot\core\cog_manager.py", line 383, in removepath
    await ctx.bot._cog_mgr.remove_path(to_remove)
  File "C:\Users\host\redenv\lib\site-packages\redbot\core\cog_manager.py", line 183, in remove_path
    paths.remove(path)
ValueError: list.remove(x): x not in list

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\host\redenv\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\host\redenv\lib\site-packages\discord\ext\commands\core.py", line 859, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\host\redenv\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ValueError: list.remove(x): x not in list
```

</details>

#### How can we reproduce this issue?

1. Set up a bot with a custom path added
2. Back it up and restore on another machine (I reproduced this on Linux -> Windows, might work on the same operating system, idk)
3. Attempt to remove the path that was added on the original machine


![theres an image here that only embeds nicely on github, not in discord webhooks. sorry.](http://i.vex.my.to/Vo0pUA)

[V3 CogManager] removepath breaks when changing OS
# Command bugs

TL;DR: Answer to [this](https://github.com/Cog-Creators/Red-DiscordBot/blob/V3/develop/redbot/core/cog_manager.py#L153-L154) is yes, because, when removing it, [this](https://github.com/Cog-Creators/Red-DiscordBot/blob/V3/develop/redbot/core/cog_manager.py#L179) causes [this](https://github.com/Cog-Creators/Red-DiscordBot/blob/V3/develop/redbot/core/cog_manager.py#L182) to not find the path.

#### Command name

[p]removepath

#### What cog is this command from?

CogManagerUI

#### What were you expecting to happen?

The specified path to be removed

#### What actually happened?

```
[23/04/2019 21:40] ERROR events on_command_error 207: Exception in command 'removepath'
Traceback (most recent call last):
  File "<my path to red>/RedBotV3/.venv/lib/python3.6/site-packages/discord/ext/commands/core.py", line 79, in wrapped
    ret = await coro(*args, **kwargs)
  File "<my path to red>/RedBotV3/.venv/lib/python3.6/site-packages/redbot/core/cog_manager.py", line 372, in removepath
    await ctx.bot.cog_mgr.remove_path(to_remove)
  File "<my path to red>/RedBotV3/.venv/lib/python3.6/site-packages/redbot/core/cog_manager.py", line 182, in remove_path
    paths.remove(path)
ValueError: list.remove(x): x not in list
```

#### How can we reproduce this issue?

1. Launch bot on Windows
2. Run `[p]addpath <valid Windows path>`
3. Stop bot
4. Launch bot on Ubuntu
5. Run `[p]paths`
6. Run `[p]removepath` with the number of the Windows path


Discussion:

A simple fix I'd see is removing [the `.resolve()` in remove_path](https://github.com/Cog-Creators/Red-DiscordBot/blob/V3/develop/redbot/core/cog_manager.py#L179).

The path literally comes from a pop of the list at the given index, so I don't see why we'd need to resolve it again. If remove_path is called from elsewhere, it should be giving a valid path already (and otherwise will receive an exception).

Resolving patch:
diff --git a/redbot/core/cog_manager.py b/redbot/core/cog_manager.py
--- a/redbot/core/cog_manager.py
+++ b/redbot/core/cog_manager.py
@@ -127,11 +127,7 @@ def _ensure_path_obj(path: Union[Path, str]) -> Path:
         pathlib.Path
 
         """
-        try:
-            path.exists()
-        except AttributeError:
-            path = Path(path)
-        return path
+        return Path(path)
 
     async def add_path(self, path: Union[Path, str]) -> None:
         """Add a cog path to current list.
@@ -177,7 +173,7 @@ async def remove_path(self, path: Union[Path, str]) -> None:
             Path to remove.
 
         """
-        path = self._ensure_path_obj(path).resolve()
+        path = self._ensure_path_obj(path)
         paths = await self.user_defined_paths()
 
         paths.remove(path)


Test patch: