##// 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
list_tracked_files.rs
165 lines | 5.2 KiB | application/rls-services+xml | RustLexer
/ rust / hg-core / src / operations / list_tracked_files.rs
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 // 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 crate::dirstate::parsers::parse_dirstate;
Simon Sapin
rust: introduce Repo and Vfs types for filesystem abstraction...
r46782 use crate::repo::Repo;
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107 use crate::revlog::changelog::Changelog;
use crate::revlog::manifest::{Manifest, ManifestEntry};
Simon Sapin
rust: use NodePrefix::from_hex instead of hex::decode directly...
r46647 use crate::revlog::node::{Node, NodePrefix};
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107 use crate::revlog::revlog::RevlogError;
use crate::revlog::Revision;
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 use crate::utils::hg_path::HgPath;
use crate::{DirstateParseError, EntryState};
use rayon::prelude::*;
use std::convert::From;
Antoine Cezar
hg-core: simplify `list_tracked_files` operation...
r46106 /// Kind of error encountered by `ListDirstateTrackedFiles`
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 #[derive(Debug)]
Antoine Cezar
hg-core: simplify `list_tracked_files` operation...
r46106 pub enum ListDirstateTrackedFilesErrorKind {
/// Error when reading the `dirstate` file
IoError(std::io::Error),
/// Error when parsing the `dirstate` file
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 ParseError(DirstateParseError),
}
Antoine Cezar
hg-core: simplify `list_tracked_files` operation...
r46106 /// A `ListDirstateTrackedFiles` error
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 #[derive(Debug)]
Antoine Cezar
hg-core: simplify `list_tracked_files` operation...
r46106 pub struct ListDirstateTrackedFilesError {
/// Kind of error encountered by `ListDirstateTrackedFiles`
pub kind: ListDirstateTrackedFilesErrorKind,
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 }
Antoine Cezar
hg-core: simplify `list_tracked_files` operation...
r46106 impl From<ListDirstateTrackedFilesErrorKind>
for ListDirstateTrackedFilesError
{
fn from(kind: ListDirstateTrackedFilesErrorKind) -> Self {
ListDirstateTrackedFilesError { kind }
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 }
}
Antoine Cezar
hg-core: simplify `list_tracked_files` operation...
r46106 impl From<std::io::Error> for ListDirstateTrackedFilesError {
fn from(err: std::io::Error) -> Self {
let kind = ListDirstateTrackedFilesErrorKind::IoError(err);
ListDirstateTrackedFilesError { kind }
Raphaël Gomès
rhg: make output of `files` relative to the current directory and the root...
r46007 }
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 }
/// List files under Mercurial control in the working directory
/// by reading the dirstate
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 pub struct Dirstate {
Antoine Cezar
hg-core: simplify `list_tracked_files` operation...
r46106 /// The `dirstate` content.
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 content: Vec<u8>,
}
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 impl Dirstate {
Simon Sapin
rust: introduce Repo and Vfs types for filesystem abstraction...
r46782 pub fn new(repo: &Repo) -> Result<Self, ListDirstateTrackedFilesError> {
let content = repo.hg_vfs().read("dirstate")?;
Antoine Cezar
hg-core: simplify `list_tracked_files` operation...
r46106 Ok(Self { content })
}
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 pub fn tracked_files(
&self,
Antoine Cezar
hg-core: simplify `list_tracked_files` operation...
r46106 ) -> Result<Vec<&HgPath>, ListDirstateTrackedFilesError> {
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 let (_, entries, _) = parse_dirstate(&self.content)
Antoine Cezar
hg-core: simplify `list_tracked_files` operation...
r46106 .map_err(ListDirstateTrackedFilesErrorKind::ParseError)?;
Antoine Cezar
hg-core: define a `ListTrackedFiles` `Operation`...
r45918 let mut files: Vec<&HgPath> = entries
.into_iter()
.filter_map(|(path, entry)| match entry.state {
EntryState::Removed => None,
_ => Some(path),
})
.collect();
files.par_sort_unstable();
Ok(files)
}
}
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107
/// Kind of error encountered by `ListRevTrackedFiles`
#[derive(Debug)]
pub enum ListRevTrackedFilesErrorKind {
/// Error when reading a `revlog` file.
IoError(std::io::Error),
/// The revision has not been found.
InvalidRevision,
Simon Sapin
rhg: allow specifying a changeset ID prefix...
r46646 /// Found more than one revision whose ID match the requested prefix
AmbiguousPrefix,
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107 /// 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 `ListRevTrackedFiles` error
#[derive(Debug)]
pub struct ListRevTrackedFilesError {
/// Kind of error encountered by `ListRevTrackedFiles`
pub kind: ListRevTrackedFilesErrorKind,
}
impl From<ListRevTrackedFilesErrorKind> for ListRevTrackedFilesError {
fn from(kind: ListRevTrackedFilesErrorKind) -> Self {
ListRevTrackedFilesError { kind }
}
}
impl From<RevlogError> for ListRevTrackedFilesError {
fn from(err: RevlogError) -> Self {
match err {
RevlogError::IoError(err) => {
ListRevTrackedFilesErrorKind::IoError(err)
}
RevlogError::UnsuportedVersion(version) => {
ListRevTrackedFilesErrorKind::UnsuportedRevlogVersion(version)
}
RevlogError::InvalidRevision => {
ListRevTrackedFilesErrorKind::InvalidRevision
}
Simon Sapin
rhg: allow specifying a changeset ID prefix...
r46646 RevlogError::AmbiguousPrefix => {
ListRevTrackedFilesErrorKind::AmbiguousPrefix
}
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107 RevlogError::Corrupted => {
ListRevTrackedFilesErrorKind::CorruptedRevlog
}
RevlogError::UnknowDataFormat(format) => {
ListRevTrackedFilesErrorKind::UnknowRevlogDataFormat(format)
}
}
.into()
}
}
/// List files under Mercurial control at a given revision.
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 pub fn list_rev_tracked_files(
Simon Sapin
rust: introduce Repo and Vfs types for filesystem abstraction...
r46782 repo: &Repo,
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 rev: &str,
) -> Result<FilesForRev, ListRevTrackedFilesError> {
Simon Sapin
rust: introduce Repo and Vfs types for filesystem abstraction...
r46782 let changelog = Changelog::open(repo)?;
let manifest = Manifest::open(repo)?;
Simon Sapin
rust: replace most "operation" structs with functions...
r46751
let changelog_entry = match rev.parse::<Revision>() {
Ok(rev) => changelog.get_rev(rev)?,
_ => {
let changelog_node = NodePrefix::from_hex(&rev)
.or(Err(ListRevTrackedFilesErrorKind::InvalidRevision))?;
changelog.get_node(changelog_node.borrow())?
}
};
let manifest_node = Node::from_hex(&changelog_entry.manifest_node()?)
.or(Err(ListRevTrackedFilesErrorKind::CorruptedRevlog))?;
let manifest_entry = manifest.get_node((&manifest_node).into())?;
Ok(FilesForRev(manifest_entry))
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107 }
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 pub struct FilesForRev(ManifestEntry);
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107
Simon Sapin
rust: replace most "operation" structs with functions...
r46751 impl FilesForRev {
pub fn iter(&self) -> impl Iterator<Item = &HgPath> {
self.0.files()
Antoine Cezar
hg-core: add a `ListRevTrackedFiles` operation...
r46107 }
}