Repository: mamba-org/mamba (C++)

Issue:
critical libmamba permissions: The system cannot find the path specified.: "testenv\Scripts\pip.exe"
### Troubleshooting docs

- [X] My problem is not solved in the Troubleshooting docs

### How did you install Mamba?

Micromamba

### Search tried in issue tracker

critical libmamba permissions: The system cannot find the path specified

### Latest version of Mamba

- [X] My problem is not solved with the latest version

### Tried in Conda?

I didn't try

### Describe your issue

This command:
```
micromamba create -y -p ./testenv -c conda-forge pip
```
produces this error:
```
error    libmamba Error opening for writing "testenv\\Scripts\\pip-script.py": No such file or directory
error    libmamba Error opening for writing "testenv\\Scripts\\pip.exe": No such file or directory
critical libmamba permissions: The system cannot find the path specified.: "testenv\Scripts\pip.exe"
```

It appears to only occur with micromamba v1.4.3 (the latest version on conda-forge) on Windows.

I have observed it locally, in CI and I've had a couple of bug reports with the same issue on a package of mine which depends on micromamba.

### mamba info / micromamba info

```shell
__
          __  ______ ___  ____ _____ ___  / /_  ____ _
         / / / / __ `__ \/ __ `/ __ `__ \/ __ \/ __ `/
        / /_/ / / / / / / /_/ / / / / / / /_/ / /_/ /
       / .___/_/ /_/ /_/\__,_/_/ /_/ /_/_.___/\__,_/
      /_/


            environment : None (not found)
           env location : -
      user config files : C:\Users\chris\.mambarc
 populated config files :
       libmamba version : 1.4.3
     micromamba version : 1.4.3
           curl version : libcurl/7.86.0-DEV Schannel zlib/1.2.13
     libarchive version : libarchive 3.6.1 zlib/1.2.13 liblzma/5.4.0 bz2lib/1.0.8 libzstd/1.5.2
       virtual packages : __win=0=0
                          __archspec=1=x86_64
                          __cuda=10.1=0
               channels :
       base environment : C:\Users\chris\AppData\Local\micromamba\root
               platform : win-64
```


### Logs

```shell
__
          __  ______ ___  ____ _____ ___  / /_  ____ _
         / / / / __ `__ \/ __ `/ __ `__ \/ __ \/ __ `/
        / /_/ / / / / / / /_/ / / / / / / /_/ / /_/ /
       / .___/_/ /_/ /_/\__,_/_/ /_/ /_/_.___/\__,_/
      /_/

conda-forge/win-64                                          Using cache
conda-forge/noarch                                          Using cache

Transaction

  Prefix: testenv

  Updating specs:

   - pip


  Package                 Version  Build               Channel           Size
-------------------------------------------------------------------------------
  Install:
-------------------------------------------------------------------------------

  + bzip2                   1.0.8  h8ffe710_4          conda-forge     Cached
  + ca-certificates      2023.5.7  h56e8100_0          conda-forge     Cached
  + libexpat                2.5.0  h63175ca_1          conda-forge     Cached
  + libffi                  3.4.2  h8ffe710_5          conda-forge     Cached
  + libsqlite              3.42.0  hcfcfb64_0          conda-forge     Cached
  + libzlib                1.2.13  hcfcfb64_4          conda-forge     Cached
  + openssl                 3.1.0  hcfcfb64_3          conda-forge     Cached
  + pip                    23.1.2  pyhd8ed1ab_0        conda-forge     Cached
  + python                 3.11.3  h2628c8c_0_cpython  conda-forge     Cached
  + setuptools             67.7.2  pyhd8ed1ab_0        conda-forge     Cached
  + tk                     8.6.12  h8ffe710_0          conda-forge     Cached
  + tzdata                  2023c  h71feb2d_0          conda-forge     Cached
  + ucrt             10.0.22621.0  h57928b3_0          conda-forge     Cached
  + vc                       14.3  hb25d44b_16         conda-forge     Cached
  + vc14_runtime      14.34.31931  h5081d32_16         conda-forge     Cached
  + vs2015_runtime    14.34.31931  hed1258a_16         conda-forge     Cached
  + wheel                  0.40.0  pyhd8ed1ab_0        conda-forge     Cached
  + xz                      5.2.6  h8d14728_0          conda-forge     Cached

  Summary:

  Install: 18 packages

  Total download: 0 B

-------------------------------------------------------------------------------



Transaction starting
Linking libexpat-2.5.0-h63175ca_1
Linking ucrt-10.0.22621.0-h57928b3_0
Linking ca-certificates-2023.5.7-h56e8100_0
Linking vc14_runtime-14.34.31931-h5081d32_16
Linking vc-14.3-hb25d44b_16
Linking vs2015_runtime-14.34.31931-hed1258a_16
Linking libsqlite-3.42.0-hcfcfb64_0
Linking openssl-3.1.0-hcfcfb64_3
Linking libffi-3.4.2-h8ffe710_5
Linking bzip2-1.0.8-h8ffe710_4
Linking xz-5.2.6-h8d14728_0
Linking tk-8.6.12-h8ffe710_0
Linking libzlib-1.2.13-hcfcfb64_4
Linking tzdata-2023c-h71feb2d_0
Linking pip-23.1.2-pyhd8ed1ab_0
error    libmamba Error opening for writing "testenv\\Scripts\\pip-script.py": No such file or directory
error    libmamba Error opening for writing "testenv\\Scripts\\pip.exe": No such file or directory
critical libmamba permissions: The system cannot find the path specified.: "testenv\Scripts\pip.exe"
```


### environment.yml

_No response_

### ~/.condarc

_No response_


Discussion: Hi, getting this as well.

* Started when updated micromamba from v1.4.2 to v1.4.3 (also reproduces on v1.4.4)
* Works on Linux, fails on Windows
Is this the same as https://github.com/mamba-org/mamba/issues/2609?
Yes, this is very likely the same bug.



Fix (patch):
diff --git a/libmamba/src/core/repo.cpp b/libmamba/src/core/repo.cpp
index 3c615ffbd4..78e8a32bf6 100644
--- a/libmamba/src/core/repo.cpp
+++ b/libmamba/src/core/repo.cpp
@@ -19,7 +19,6 @@ extern "C"  // Incomplete header
 #include <solv/repo_conda.h>
 }
 
-#include "mamba/core/channel.hpp"
 #include "mamba/core/context.hpp"
 #include "mamba/core/mamba_fs.hpp"
 #include "mamba/core/output.hpp"
@@ -27,6 +26,7 @@ extern "C"  // Incomplete header
 #include "mamba/core/pool.hpp"
 #include "mamba/core/prefix_data.hpp"
 #include "mamba/core/repo.hpp"
+#include "mamba/core/util.hpp"
 #include "solv-cpp/pool.hpp"
 #include "solv-cpp/repo.hpp"
 
@@ -228,18 +228,13 @@ namespace mamba
         srepo(*this).for_each_solvable(
             [&](solv::ObjSolvableView s)
             {
-                if (s.name() == "python")
+                if ((s.name() == "python") && !s.version().empty() && (s.version()[0] >= '2'))
                 {
-                    if (!s.version().empty() && (s.version()[0] >= '2'))
-                    {
-                        s.add_dependency(pip_id);
-                    }
+                    s.add_dependency(pip_id);
                 }
                 if (s.name() == "pip")
                 {
-                    auto deps = s.dependencies();
-                    deps.insert(deps.begin(), python_id);  // TODO is this right?
-                    s.set_dependencies(std::move(deps));
+                    s.add_dependency(python_id, SOLVABLE_PREREQMARKER);
                 }
             }
         );
diff --git a/libmamba/src/solv-cpp/ids.hpp b/libmamba/src/solv-cpp/ids.hpp
index 7a40b0e6af..9c6c68056f 100644
--- a/libmamba/src/solv-cpp/ids.hpp
+++ b/libmamba/src/solv-cpp/ids.hpp
@@ -17,6 +17,7 @@ namespace mamba::solv
     using SolvableId = ::Id;
     using RuleId = ::Id;
     using ProblemId = ::Id;
+    using DependencyMarker = ::Id;
 
     using RelationFlag = int;
     using DistType = int;
diff --git a/libmamba/src/solv-cpp/solvable.cpp b/libmamba/src/solv-cpp/solvable.cpp
index d5abcbd517..774dfacd37 100644
--- a/libmamba/src/solv-cpp/solvable.cpp
+++ b/libmamba/src/solv-cpp/solvable.cpp
@@ -349,37 +349,32 @@ namespace mamba::solv
         return set_subdir(str.c_str());
     }
 
-    auto ObjSolvableViewConst::dependencies() const -> ObjQueue
+    auto ObjSolvableViewConst::dependencies(DependencyMarker marker) const -> ObjQueue
     {
         auto q = ObjQueue{};
-        ::solvable_lookup_deparray(
-            const_cast<::Solvable*>(raw()),
-            SOLVABLE_REQUIRES,
-            q.raw(),
-            /* marker= */ -1
-        );
+        ::solvable_lookup_deparray(const_cast<::Solvable*>(raw()), SOLVABLE_REQUIRES, q.raw(), marker);
         return q;
     }
 
-    void ObjSolvableView::set_dependencies(const ObjQueue& q) const
+    void ObjSolvableView::set_dependencies(const ObjQueue& q, DependencyMarker marker) const
     {
-        ::solvable_set_deparray(
-            raw(),
-            SOLVABLE_REQUIRES,
-            const_cast<::Queue*>(q.raw()),
-            /* marker= */ 0
-        );
+        ::solvable_set_deparray(raw(), SOLVABLE_REQUIRES, const_cast<::Queue*>(q.raw()), marker);
     }
 
-    void ObjSolvableView::add_dependency(DependencyId dep) const
+    void ObjSolvableView::add_dependency(DependencyId dep, DependencyMarker marker) const
     {
-        raw()->requires = ::repo_addid_dep(raw()->repo, raw()->requires, dep, /* marker= */ 0);
+        raw()->requires = ::repo_addid_dep(raw()->repo, raw()->requires, dep, marker);
     }
 
     auto ObjSolvableViewConst::provides() const -> ObjQueue
     {
         auto q = ObjQueue{};
-        ::solvable_lookup_deparray(const_cast<::Solvable*>(raw()), SOLVABLE_PROVIDES, q.raw(), -1);
+        ::solvable_lookup_deparray(
+            const_cast<::Solvable*>(raw()),
+            SOLVABLE_PROVIDES,
+            q.raw(),
+            /* marker= */ -1
+        );
         return q;
     }
 
diff --git a/libmamba/src/solv-cpp/solvable.hpp b/libmamba/src/solv-cpp/solvable.hpp
index 5327cdd3f0..00e4453397 100644
--- a/libmamba/src/solv-cpp/solvable.hpp
+++ b/libmamba/src/solv-cpp/solvable.hpp
@@ -71,8 +71,15 @@ namespace mamba::solv
          **/
         auto subdir() const -> std::string_view;
 
-        /** Queue of ``DependencyId``. */
-        auto dependencies() const -> ObjQueue;
+        /**
+         * Queue of ``DependencyId``.
+         *
+         * When the array is split in two using a maker, @p marker can be used to get
+         * only a part of the the dependency array.
+         * Use ``-1`` to get the first part, ``1`` to get the second part, and ``0`` to get
+         * eveything including the marker.
+         */
+        auto dependencies(DependencyMarker marker = -1) const -> ObjQueue;
 
         /** Queue of ``DependencyId``. */
         auto provides() const -> ObjQueue;
@@ -241,10 +248,16 @@ namespace mamba::solv
         void set_subdir(const std::string& str) const;
 
         /** Set the dependencies of the solvable. */
-        void set_dependencies(const ObjQueue& q) const;
+        void set_dependencies(const ObjQueue& q, DependencyMarker marker = 0) const;
 
-        /** Add a additional dependency to the solvable. */
-        void add_dependency(DependencyId dep) const;
+        /**
+         * Add a additional dependency to the solvable.
+         *
+         * Dependency array can be split in two using the given @p marker.
+         *
+         * @see dependencies
+         */
+        void add_dependency(DependencyId dep, DependencyMarker marker = 0) const;
 
         /** Add multiple additional dependencies to the solvable. */
         template <typename Iter>