Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A drive with this name already exists #1029

Closed
Badgerati opened this issue Nov 6, 2022 · 6 comments · Fixed by #1058
Closed

A drive with this name already exists #1029

Badgerati opened this issue Nov 6, 2022 · 6 comments · Fixed by #1058
Assignees
Labels
Milestone

Comments

@Badgerati
Copy link
Owner

I was sure I'd fixed this one, but I just got the A drive with name already exists error again from testing Pode.Web - on linux.

pode-web-example  | New-PSDrive: /usr/local/share/powershell/Modules/Pode/Private/Helpers.ps1:853
pode-web-example  | Line |
pode-web-example  |  853 |  …   $drive = (New-PSDrive -Name $Name -PSProvider FileSystem -Root $Pat …
pode-web-example  |      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pode-web-example  |      | A drive with the name
pode-web-example  |      | 'PodeDir45ee17d2-3c82-4958-97f6-7948622147d6' already exists.
pode-web-example  |
pode-web-example  | at New-PodePSDrive, /usr/local/share/powershell/Modules/Pode/Private/Helpers.ps1: line 853
pode-web-example  | at Add-PodePSDrives, /usr/local/share/powershell/Modules/Pode/Private/Helpers.ps1: line 905
pode-web-example  | at Open-PodeRunspace, /usr/local/share/powershell/Modules/Pode/Private/Helpers.ps1: line 604
pode-web-example  | at <ScriptBlock>, <No file>: line 1
@jbaechtelMT
Copy link

jbaechtelMT commented Nov 9, 2022

I had this same error and corrected it by commenting out (add # at the beginning of the line) line 853 in Helpers.ps1. Then add this line just below it:

if (!(Get-PSDrive -Name $Name -ErrorAction SilentlyContinue)) {

This will fix you problem. Enjoy!

@jbaechtelMT
Copy link

@Badgerati - The true error is in the Test-PodePSDrive function. My response (above) is just a work around for now. THX. Keep up the good work!

@Badgerati Badgerati added this to the 2.8.0 milestone Nov 15, 2022
@ittchmh
Copy link
Contributor

ittchmh commented Dec 22, 2022

I saw this error only if relative path to folder was used, if absolute path is used - no issues

@ili101
Copy link
Contributor

ili101 commented Dec 29, 2022

Badgerati I think adding Resolve-Path could be a solution

[DBG]: [Process:47918]: [Runspace40]: PS /PsF/Scripts/Tool>> $drive.Root
/PsF/Scripts/Tool/Logs
[DBG]: [Process:47918]: [Runspace40]: PS /PsF/Scripts/Tool>> $Path                                
/PsF/Scripts/Tool/./Logs
[DBG]: [Process:47918]: [Runspace40]: PS /PsF/Scripts/Tool>> $drive.Root -ieq $Path               
False
[DBG]: [Process:47918]: [Runspace40]: PS /PsF/Scripts/Tool>> $drive.Root -ieq (Resolve-Path $Path)
True

As @ittchmh mentioned using a full path is a good workaround, like:

Add-PodeStaticRoute -Path '/logs' -Source (Join-Path (Get-PodeServerPath) 'Logs')

@Badgerati
Copy link
Owner Author

Aah! Yes, you're both right!

Adding a Resolve-Path into New-PodePSDrive should resolve this then 😄

Badgerati added a commit that referenced this issue Jan 1, 2023
@Badgerati Badgerati self-assigned this Jan 1, 2023
@Badgerati
Copy link
Owner Author

The above commit should now resolve this; I've tested locally where I could always get the error to trip, but no linger see it with the changes.

I've also altered references of Resolve-Path to [System.IO.Path]::GetFullPath(...) as it's substantially faster.

The main change is to add $Path = [System.IO.Path]::GetFullPath($Path) just before the if (!(Test-PodePSDrive -Name $Name -Path $Path)) { line in New-PodePSDrive. If anyone's able to test this themselves let me know 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants