JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.61k stars 5.48k forks source link

Adding packages to an environment requires administrator privileges on Windows #49247

Open evanfields opened 1 year ago

evanfields commented 1 year ago

Summary

On Windows with Julia 1.9.0-rc2, adding a package to an environment (and maybe other operations that trigger git operations?) fails with the error ERROR: GitError(Code:ENOTFOUND, Class:Config, config value 'safe.directory' was not found). Running Julia with administrator privileges allows package operations to complete as expected. Prior Julia versions didn't have this problem.

Example

julia> pwd()
"C:\\Users\\ejfie"

(@v1.9) pkg> generate PkgProblem
  Generating  project PkgProblem:
    PkgProblem\Project.toml
    PkgProblem\src\PkgProblem.jl

julia> cd("PkgProblem\\")

(@v1.9) pkg> activate .
  Activating project at `C:\Users\ejfie\PkgProblem`

(PkgProblem) pkg> add Dates
    Updating registry at `C:\Users\ejfie\.julia\registries\General`
ERROR: GitError(Code:ENOTFOUND, Class:Config, config value 'safe.directory' was not found)
Stacktrace:
  [1] macro expansion
    @ C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\LibGit2\src\error.jl:111 [inlined]
  [2] LibGit2.GitRepo(path::String)
    @ LibGit2 C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\LibGit2\src\repository.jl:11
  [3] (::Pkg.Registry.var"#73#78"{Base.TTY, Day, Dict{String, Any}, String, Vector{Pkg.Registry.RegistryInstance}})()
    @ Pkg.Registry C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\Pkg\src\Registry\Registry.jl:449
  [4] mkpidlock(f::Pkg.Registry.var"#73#78"{Base.TTY, Day, Dict{String, Any}, String, Vector{Pkg.Registry.RegistryInstance}}, at::String, pid::Int32; kwopts::Base.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:stale_age,), Tuple{Int64}}})
    @ FileWatching.Pidfile C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\FileWatching\src\pidfile.jl:82
  [5] #mkpidlock#6
    @ C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\FileWatching\src\pidfile.jl:77 [inlined]
  [6] mkpidlock
    @ C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\FileWatching\src\pidfile.jl:77 [inlined]
  [7] update(regs::Vector{Pkg.Registry.RegistrySpec}; io::Base.TTY, force::Bool, depots::Vector{String}, update_cooldown::Day)
    @ Pkg.Registry C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\Pkg\src\Registry\Registry.jl:379
  [8] update
    @ C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\Pkg\src\Registry\Registry.jl:372 [inlined]
  [9] update_registries(ctx::Pkg.Types.Context; force::Bool, kwargs::Base.Pairs{Symbol, Day, Tuple{Symbol}, NamedTuple{(:update_cooldown,), Tuple{Day}}})
    @ Pkg.Operations C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\Pkg\src\Operations.jl:1265
 [10] update_registries
    @ C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\Pkg\src\Operations.jl:1262 [inlined]
 [11] add(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; preserve::Pkg.Types.PreserveLevel, platform::Base.BinaryPlatforms.Platform, kwargs::Base.Pairs{Symbol, Base.TTY, Tuple{Symbol}, NamedTuple{(:io,), Tuple{Base.TTY}}})
    @ Pkg.API C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\Pkg\src\API.jl:259
 [12] add(pkgs::Vector{Pkg.Types.PackageSpec}; io::Base.TTY, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Pkg.API C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\Pkg\src\API.jl:156
 [13] add(pkgs::Vector{Pkg.Types.PackageSpec})
    @ Pkg.API C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\Pkg\src\API.jl:145
 [14] do_cmd!(command::Pkg.REPLMode.Command, repl::REPL.LineEditREPL)
    @ Pkg.REPLMode C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\Pkg\src\REPLMode\REPLMode.jl:412
 [15] do_cmd(repl::REPL.LineEditREPL, input::String; do_rethrow::Bool)
    @ Pkg.REPLMode C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\Pkg\src\REPLMode\REPLMode.jl:390
 [16] do_cmd
    @ C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\Pkg\src\REPLMode\REPLMode.jl:380 [inlined]
 [17] (::Pkg.REPLMode.var"#24#27"{REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::IOBuffer, ok::Bool)
    @ Pkg.REPLMode C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\Pkg\src\REPLMode\REPLMode.jl:557
 [18] #invokelatest#2
    @ .\essentials.jl:816 [inlined]
 [19] invokelatest
    @ .\essentials.jl:813 [inlined]
 [20] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\REPL\src\LineEdit.jl:2647
 [21] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\REPL\src\REPL.jl:1298
 [22] (::REPL.var"#62#68"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL .\task.jl:514

versioninfo

julia> versioninfo()
Julia Version 1.9.0-rc2
Commit 72aec423c2 (2023-04-01 10:41 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 12 × AMD Ryzen 5 1600X Six-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, znver1)
  Threads: 4 on 12 virtual cores
Environment:
  JULIA_NUM_THREADS = 4

Possible duplicate

I reported this a little while ago in Pkg, but wasn't sure if there or this repo was the correct place to open an issue. Since the release is coming up and this could be breaking for some Windows users I'm reporting here too, but of course no worries if this is closed as duplicate. Thanks!

bilderbuchi commented 1 year ago

Is it possible that the user that owns the Registry folder C:\Users\ejfie\.julia\registries\General is different from the user that you are using Julia under? That git tries to access the safe.directory config suggests to me that it thinks that you are trying to access a Git repo that is not "yours", which is a relatively new behaviour fixing a security problem: https://git-scm.com/docs/git-config/2.35.2#Documentation/git-config.txt-safedirectory You can test for this (maybe) by running git status in C:\Users\ejfie\.julia\registries\General (outside Julia and/or maybe from inside if you know how) and see what happens.

evanfields commented 1 year ago

Thanks for the response!

Is it possible that the user that owns the Registry folder C:\Users\ejfie.julia\registries\General is different from the user that you are using Julia under?

I guess possible, but unlikely: the machine in question is a personal computer at home, no other users. Windows shows that for the C:\Users\ejfie\.julia\registries\General folder, user ejfie has the same permissions as the administrator and system usergroups.

Running git status from git bash:

ejfie@DESKTOP-12KR94V MINGW64 /
$ cd ~/.julia/registries/General/

ejfie@DESKTOP-12KR94V MINGW64 ~/.julia/registries/General (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

In Julia though:

julia> using LibGit2

julia> repo = GitRepo("C:\\Users\\ejfie\\.julia\\registries\\General\\")
ERROR: GitError(Code:ENOTFOUND, Class:Config, config value 'safe.directory' was not found)
Stacktrace:
 [1] macro expansion
   @ C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\LibGit2\src\error.jl:111 [inlined]
 [2] GitRepo(path::String)
   @ LibGit2 C:\Users\ejfie\AppData\Local\Programs\Julia-1.9.0-rc2\share\julia\stdlib\v1.9\LibGit2\src\repository.jl:11
 [3] top-level scope
   @ REPL[2]:1
Zentrik commented 1 year ago

I am also having this issue sometimes when using 1.9 rc2. I think it's only happened when adding packages on my local drive, using admin privileges didn't fix it for me. The registries folder only contains a General.toml and General.tar.gz, there is no General folder. I have no issues on 1.8.5.

Zentrik commented 1 year ago

I fixed the problem by running git config --global --add safe.directory [PATH TO YOUR REPO]

matteyas commented 1 year ago

Have the same problem with 1.9.0 release. git config did not fix the issue, unless I specified the wrong path (pointed it to the julia-1.9.0 folder). Works if I use admin cmd.

nilshg commented 1 year ago

I also see this when I start my terminal without admin rights, weirdly enough I've been running 1.9 since the first beta and did not see this before. In contrast to the OP above I also can update non-default environments, and only see this error when in the default environment.

hakkelt commented 1 year ago

Have the same problem with 1.9.0 release. git config did not fix the issue, unless I specified the wrong path (pointed it to the julia-1.9.0 folder). Works if I use admin cmd.

I assume you indeed specified the wrong path: the problem was fixed after running git config --global --add safe.directory C:\Users\<my username>\.julia\registries\General (that's the location of the problematic git repo).

Zentrik commented 1 year ago

git config --global --add safe.directory "*" should work on the next release of julia if https://github.com/JuliaLang/julia/commit/6905c8ebf1f1d20f281cb9a434f4d4996adf4236 is in that branch, not sure why it wasn't included in 1.9.

As a hacky fix, I copied libgit2.dll in julia installation/bin from master into my 1.9 installation, it seems to work fine.