##// END OF EJS Templates
wix: tell ComponentSearch that it is finding a directory (not a file)...
wix: tell ComponentSearch that it is finding a directory (not a file) This is to fix an issue we've noticed where fresh installations start at `C:\Program Files\Mercurial`, and then upgrades "walk up" the tree and end up in `C:\Program Files` and finally `C:\` (where they stay). ComponentSearch defaults to finding files, which I think means "it produces a string like `C:\Program Files\Mercurial`", whereas with the type being explicitly a directory, it would return `C:\Program Files\Mercurial\` (note the final trailing backslash). Presumably, a latter step then tries to turn that file name into a proper directory, by removing everything after the last `\`. This could likely also be fixed by actually searching for the component for hg.exe itself. That seemed a lot more complicated, as the GUID for hg.exe isn't known in this file (it's one of the "auto-derived" ones). We could also consider adding a Condition that I think could check the Property and ensure it's either empty or ends in a trailing slash, but that would be an installer runtime check and I'm not convinced it'd actually be useful. This will *not* cause existing installations that are in one of the bad directories to fix themselves. Doing that would require a fair amount more understanding of wix and windows installer than I have, and it *probably* wouldn't be possible to be 100% correct about it either (there's nothing preventing a user from intentionally installing it in C:\, though I don't know why they would do so). If someone wants to tackle fixing existing installations, I think that the first installation is actually the only one that shows up in "Add or Remove Programs", and that its registry keys still exist. You might be able to find something under HKEY_USERS that lists both the "good" and the "bad" InstallDirs. Mine was under `HKEY_USERS\S-1-5-18\Software\Mercurial\InstallDir` (C:\), and `HKEY_USERS\S-1-5-21-..numbers..\Software\Mercurial\InstallDir` (C:\Program Files\Mercurial). If you find exactly two, with one being the default path, and the other being a prefix of it, the user almost certainly hit this bug :D We had originally thought that this bug might be due to unattended installations/upgrades, but I no longer think that's the case. We were able to reproduce the issue by uninstalling all copies of Mercurial I could find, installing one version (it chose the correct location), and then starting the installer for a different version (higher or lower didn't matter). I did not need to deal with an unattended or headless installation/upgrade to trigger the issue, but it's possible that my system was "primed" for this bug to happen because of a previous unattended installation/upgrade. Differential Revision: https://phab.mercurial-scm.org/D9891

File last commit:

r46782:8a491439 default
r47159:8deab876 stable
Show More
cat.rs
135 lines | 4.6 KiB | application/rls-services+xml | RustLexer
// list_tracked_files.rs
//
// Copyright 2020 Antoine Cezar <antoine.cezar@octobus.net>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
use std::convert::From;
use std::path::PathBuf;
use crate::repo::Repo;
use crate::revlog::changelog::Changelog;
use crate::revlog::manifest::Manifest;
use crate::revlog::path_encode::path_encode;
use crate::revlog::revlog::Revlog;
use crate::revlog::revlog::RevlogError;
use crate::revlog::Node;
use crate::revlog::NodePrefix;
use crate::revlog::Revision;
use crate::utils::files::get_path_from_bytes;
use crate::utils::hg_path::{HgPath, HgPathBuf};
const METADATA_DELIMITER: [u8; 2] = [b'\x01', b'\n'];
/// Kind of error encountered by `CatRev`
#[derive(Debug)]
pub enum CatRevErrorKind {
/// Error when reading a `revlog` file.
IoError(std::io::Error),
/// The revision has not been found.
InvalidRevision,
/// Found more than one revision whose ID match the requested prefix
AmbiguousPrefix,
/// A `revlog` file is corrupted.
CorruptedRevlog,
/// The `revlog` format version is not supported.
UnsuportedRevlogVersion(u16),
/// The `revlog` data format is not supported.
UnknowRevlogDataFormat(u8),
}
/// A `CatRev` error
#[derive(Debug)]
pub struct CatRevError {
/// Kind of error encountered by `CatRev`
pub kind: CatRevErrorKind,
}
impl From<CatRevErrorKind> for CatRevError {
fn from(kind: CatRevErrorKind) -> Self {
CatRevError { kind }
}
}
impl From<RevlogError> for CatRevError {
fn from(err: RevlogError) -> Self {
match err {
RevlogError::IoError(err) => CatRevErrorKind::IoError(err),
RevlogError::UnsuportedVersion(version) => {
CatRevErrorKind::UnsuportedRevlogVersion(version)
}
RevlogError::InvalidRevision => CatRevErrorKind::InvalidRevision,
RevlogError::AmbiguousPrefix => CatRevErrorKind::AmbiguousPrefix,
RevlogError::Corrupted => CatRevErrorKind::CorruptedRevlog,
RevlogError::UnknowDataFormat(format) => {
CatRevErrorKind::UnknowRevlogDataFormat(format)
}
}
.into()
}
}
/// List files under Mercurial control at a given revision.
///
/// * `root`: Repository root
/// * `rev`: The revision to cat the files from.
/// * `files`: The files to output.
pub fn cat(
repo: &Repo,
rev: &str,
files: &[HgPathBuf],
) -> Result<Vec<u8>, CatRevError> {
let changelog = Changelog::open(repo)?;
let manifest = Manifest::open(repo)?;
let changelog_entry = match rev.parse::<Revision>() {
Ok(rev) => changelog.get_rev(rev)?,
_ => {
let changelog_node = NodePrefix::from_hex(&rev)
.map_err(|_| CatRevErrorKind::InvalidRevision)?;
changelog.get_node(changelog_node.borrow())?
}
};
let manifest_node = Node::from_hex(&changelog_entry.manifest_node()?)
.map_err(|_| CatRevErrorKind::CorruptedRevlog)?;
let manifest_entry = manifest.get_node((&manifest_node).into())?;
let mut bytes = vec![];
for (manifest_file, node_bytes) in manifest_entry.files_with_nodes() {
for cat_file in files.iter() {
if cat_file.as_bytes() == manifest_file.as_bytes() {
let index_path = store_path(manifest_file, b".i");
let data_path = store_path(manifest_file, b".d");
let file_log =
Revlog::open(repo, &index_path, Some(&data_path))?;
let file_node = Node::from_hex(node_bytes)
.map_err(|_| CatRevErrorKind::CorruptedRevlog)?;
let file_rev = file_log.get_node_rev((&file_node).into())?;
let data = file_log.get_rev_data(file_rev)?;
if data.starts_with(&METADATA_DELIMITER) {
let end_delimiter_position = data
[METADATA_DELIMITER.len()..]
.windows(METADATA_DELIMITER.len())
.position(|bytes| bytes == METADATA_DELIMITER);
if let Some(position) = end_delimiter_position {
let offset = METADATA_DELIMITER.len() * 2;
bytes.extend(data[position + offset..].iter());
}
} else {
bytes.extend(data);
}
}
}
}
Ok(bytes)
}
fn store_path(hg_path: &HgPath, suffix: &[u8]) -> PathBuf {
let encoded_bytes =
path_encode(&[b"data/", hg_path.as_bytes(), suffix].concat());
get_path_from_bytes(&encoded_bytes).into()
}