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

Access to the path is denied when installing to -Scope CurrentUser #39

Open
edouard-lopez opened this issue Jan 22, 2019 · 3 comments
Open

Comments

@edouard-lopez
Copy link

Thanks for the projects, like your documentation and how you make it flexible.

Env

I'm on Linux Mint.

PS>$PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.1
PSEdition                      Core
GitCommitId                    6.1.1
OS                             Linux 4.15.0-43-generic #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Steps to reproduce

PS> Install-Module PowerLine -Scope CurrentUser
PS> Import-Module PowerLine 

Error

P> Set-PowerLinePrompt -SetCurrentDirectory -RestoreVirtualTerminal -Newline -Timestamp -Colors "#00DDFF","#0066FF"
WARNING: The Enterprise path /etc/xdg/xdg-cinnamon/powershell cannot be found
New-Item : Access to the path '/etc/xdg/xdg-cinnamon/powershell/HuddledMasses.org' is denied.
At /home/ed8/.local/share/powershell/Modules/Configuration/1.3.1/Configuration.psm1:232 char:21
+             $null = New-Item $PathRoot -Type Directory -Force
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+CategoryInfo          : PermissionDenied: (/etc/xdg/xdg-ci...ddledMasses.org:String) [New-Item], UnauthorizedAccessException
+FullyQualifiedErrorId : CreateDirectoryUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand

New-Item : Access to the path '/etc/xdg/xdg-cinnamon/powershell/HuddledMasses.org/PowerLine' is denied.
At /home/ed8/.local/share/powershell/Modules/Configuration/1.3.1/Configuration.psm1:232 char:21
+            $null = New-Item $PathRoot -Type Directory -Force
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : PermissionDenied: (/etc/xdg/xdg-ci...s.org/PowerLine:String) [New-Item], UnauthorizedAccessException
+ FullyQualifiedErrorId : CreateDirectoryUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand

WARNING: The Enterprise path /etc/xdg/xdg-cinnamon/powershell cannot be found
New-Item : Access to the path '/etc/xdg/xdg-cinnamon/powershell/HuddledMasses.org' is denied.
At /home/ed8/.local/share/powershell/Modules/Configuration/1.3.1/Configuration.psm1:232 char:21
+             $null = New-Item $PathRoot -Type Directory -Force
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+CategoryInfo          : PermissionDenied: (/etc/xdg/xdg-ci...ddledMasses.org:String) [New-Item], UnauthorizedAccessException
+FullyQualifiedErrorId : CreateDirectoryUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand

New-Item : Access to the path '/etc/xdg/xdg-cinnamon/powershell/HuddledMasses.org/PowerLine' is denied.
At /home/ed8/.local/share/powershell/Modules/Configuration/1.3.1/Configuration.psm1:232 char:21
+             $null = New-Item $PathRoot -Type Directory -Force
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : PermissionDenied: (/etc/xdg/xdg-ci...s.org/PowerLine:String) [New-Item], UnauthorizedAccessException
+FullyQualifiedErrorId : CreateDirectoryUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand

Set-Content : Could not find a part of the path '/etc/xdg/xdg-cinnamon/powershell/HuddledMasses.org/PowerLine/Configuration.psd1'.
At /home/ed8/.local/share/powershell/Modules/Configuration/1.3.1/Metadata.psm1:520 char:9
+         Set-Content -Encoding UTF8 -Path $Path -Value ((@($CommentHea ...
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+CategoryInfo          : ObjectNotFound: (/etc/xdg/xdg-ci...figuration.psd1:String) [Set-Content], DirectoryNotFoundException
+FullyQualifiedErrorId : GetContentWriterDirectoryNotFoundError,Microsoft.PowerShell.Commands.SetContentCommand
@Jaykul
Copy link
Owner

Jaykul commented Mar 4, 2019

I'm using the Configuration module to store the settings. That happens to be another module I wrote, so unfortunately I can't just leave it at that and blame the other module 😉

Bottom line, it looks like I may have misunderstood the free desktop XDG Base Directory specification. Bottom line: it's defaulting to XDG_CONFIG_DIRS (i.e. in PowerShell: $Env:XDG_CONFIG_DIRS) which seems to be set, on your system, to /etc/xdg/xdg-cinnamon -- I chose to make that the default because in my head, it corresponded to Windows "Enterprise Roaming Profile" -- however, looking at the free desktop spec just now, I think I may have gotten that wrong, and that location is more like the Windows "ProgramData" settings -- and worse, it may require root to write to it.

In any case, I should probably just change to using the user-specific location as the default export location (i.e. on Windows, LocalAppData, and on Linux, XDG_CONFIG_HOME).

If anyone knows anything about XDG, I'd love to get this right ...

For you, the quick fix is to reconfigure the Configuration module storage paths to point to paths where you have write access.

Open your local copy of the Configuration.psd1 file, and look around line 50 for the PrivateData PathOverrides, and set the EnterpriseData one (at least) to a location that you can write to -- probably the value of $Env:XDG_CONFIG_HOME but it doesn't really matter.

@Lockszmith-GH
Copy link

Lockszmith-GH commented Jan 4, 2022

Just encountered this - running for the first time on a Ubuntu GUI.

I can confirm that none of the default XDG_... env variable are pointing to a user writable location.

EnterpriseData = "~/.local/share/" Did the trick for me.

@Lockszmith-GH
Copy link

So a bit more about this.
Per the specification, these environment variables, they have default values if they don't exist (fun!)

I think the biggest hurdle here, is that while you are looking for those paths, they don't exist by default. And I'm guessing your code attempts to create the empty directory.

After all, why would saving a local configuration try writing to Enterprise data ?

On a different note, a question:

Any way to manipulate the configuration in Configuration.psd1 programmatically?
I mean PowerShell's object based way and not a string search-replace?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants