Skip to content

Commit

Permalink
Remove win-specific code
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Mar 3, 2024
1 parent 42bbeba commit 58ee578
Showing 1 changed file with 0 additions and 66 deletions.
66 changes: 0 additions & 66 deletions crates/uv-virtualenv/src/bare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,69 +330,3 @@ pub fn create_bare_venv(
executable,
})
}

/// Given a path, return the "real" path.
///
/// The only modifications applied here are for the Windows Store. Specifically, the Windows Store
/// Python executable is located at a path like:
///
/// `C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_qbs5n2kfra8p0`.
///
/// However, users actually aren't allowed to run executables from this path directly. So, instead,
/// we need to use a path like:
///
/// `C:\Users\crmar\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.11_qbs5n2kfra8p0`
///
/// In practice, this is achieved by replacing `%ProgramFiles%\WindowsApps` with `%LocalAppData%\Microsoft\WindowsApps`.
///
/// See: <https://github.com/python-poetry/poetry/pull/5931>
fn real_path(path: &Path) -> io::Result<PathBuf> {
#[cfg(windows)]
if path.is_absolute() {
if path.components().any(|component| component.as_os_str() == "Microsoft") {
return real_windows_path(path);
}
}

Ok(path.to_path_buf())
}

#[cfg(windows)]
fn real_windows_path(path: &Path) -> io::Result<PathBuf> {
use windows_sys::Win32::UI::Shell::{CSIDL_LOCAL_APPDATA, CSIDL_PROFILE};

let program_files = windows_folder(CSIDL_PROGRAM_FILES)?;
let local_appdata = windows_folder(CSIDL_LOCAL_APPDATA)?;

let suffix = path.strip_prefix(&program_files)?;
Ok(local_appdata.join(suffix))
}

#[cfg(windows)]
fn windows_folder(csidl: u32) -> Option<PathBuf> {
use std::env;
use std::ffi::OsString;
use std::os::windows::ffi::OsStringExt;
use std::path::PathBuf;

use windows_sys::Win32::Foundation::{MAX_PATH, S_OK};
use windows_sys::Win32::UI::Shell::{SHGetFolderPathW};

unsafe {
let mut path: Vec<u16> = Vec::with_capacity(MAX_PATH as usize);
match SHGetFolderPathW(0, csidl as i32, 0, 0, path.as_mut_ptr()) {
S_OK => {
let len = wcslen(path.as_ptr());
path.set_len(len);
let s = OsString::from_wide(&path);
Some(PathBuf::from(s))
}
_ => None,
}
}
}

#[cfg(windows)]
extern "C" {
fn wcslen(buf: *const u16) -> usize;
}

0 comments on commit 58ee578

Please sign in to comment.