##// END OF EJS Templates
rust-status: explicitly track bad file types...
Spencer Baugh -
r51755:5efccea9 default
parent child Browse files
Show More
@@ -20,7 +20,7 b' use std::{borrow::Cow, fmt};'
20
20
21 /// Wrong type of file from a `BadMatch`
21 /// Wrong type of file from a `BadMatch`
22 /// Note: a lot of those don't exist on all platforms.
22 /// Note: a lot of those don't exist on all platforms.
23 #[derive(Debug, Copy, Clone)]
23 #[derive(Debug, Copy, Clone, PartialEq, Eq)]
24 pub enum BadType {
24 pub enum BadType {
25 CharacterDevice,
25 CharacterDevice,
26 BlockDevice,
26 BlockDevice,
@@ -14,6 +14,7 b' use crate::utils::files::get_bytes_from_'
14 use crate::utils::files::get_path_from_bytes;
14 use crate::utils::files::get_path_from_bytes;
15 use crate::utils::hg_path::HgPath;
15 use crate::utils::hg_path::HgPath;
16 use crate::BadMatch;
16 use crate::BadMatch;
17 use crate::BadType;
17 use crate::DirstateStatus;
18 use crate::DirstateStatus;
18 use crate::HgPathCow;
19 use crate::HgPathCow;
19 use crate::PatternFileWarning;
20 use crate::PatternFileWarning;
@@ -24,6 +25,7 b' use rayon::prelude::*;'
24 use sha1::{Digest, Sha1};
25 use sha1::{Digest, Sha1};
25 use std::borrow::Cow;
26 use std::borrow::Cow;
26 use std::io;
27 use std::io;
28 use std::os::unix::prelude::FileTypeExt;
27 use std::path::Path;
29 use std::path::Path;
28 use std::path::PathBuf;
30 use std::path::PathBuf;
29 use std::sync::Mutex;
31 use std::sync::Mutex;
@@ -388,11 +390,7 b" impl<'a, 'tree, 'on_disk> StatusCommon<'"
388 ));
390 ));
389 match std::fs::symlink_metadata(&fs_path) {
391 match std::fs::symlink_metadata(&fs_path) {
390 Ok(fs_metadata) => {
392 Ok(fs_metadata) => {
391 let file_type =
393 let file_type = fs_metadata.file_type().into();
392 match fs_metadata.file_type().try_into() {
393 Ok(file_type) => file_type,
394 Err(_) => return Ok(()),
395 };
396 let entry = DirEntry {
394 let entry = DirEntry {
397 hg_path: Cow::Borrowed(
395 hg_path: Cow::Borrowed(
398 dirstate_node
396 dirstate_node
@@ -513,6 +511,15 b" impl<'a, 'tree, 'on_disk> StatusCommon<'"
513 // replaced by a directory or something else.
511 // replaced by a directory or something else.
514 self.mark_removed_or_deleted_if_file(&dirstate_node)?;
512 self.mark_removed_or_deleted_if_file(&dirstate_node)?;
515 }
513 }
514 if let Some(bad_type) = fs_entry.is_bad() {
515 if self.matcher.exact_match(hg_path) {
516 let path = dirstate_node.full_path(self.dmap.on_disk)?;
517 self.outcome.lock().unwrap().bad.push((
518 path.to_owned().into(),
519 BadMatch::BadType(bad_type),
520 ))
521 }
522 }
516 if fs_entry.is_dir() {
523 if fs_entry.is_dir() {
517 if self.options.collect_traversed_dirs {
524 if self.options.collect_traversed_dirs {
518 self.outcome
525 self.outcome
@@ -866,21 +873,27 b' enum FakeFileType {'
866 File,
873 File,
867 Directory,
874 Directory,
868 Symlink,
875 Symlink,
876 BadType(BadType),
869 }
877 }
870
878
871 impl TryFrom<std::fs::FileType> for FakeFileType {
879 impl From<std::fs::FileType> for FakeFileType {
872 type Error = ();
880 fn from(f: std::fs::FileType) -> Self {
873
874 fn try_from(f: std::fs::FileType) -> Result<Self, Self::Error> {
875 if f.is_dir() {
881 if f.is_dir() {
876 Ok(Self::Directory)
882 Self::Directory
877 } else if f.is_file() {
883 } else if f.is_file() {
878 Ok(Self::File)
884 Self::File
879 } else if f.is_symlink() {
885 } else if f.is_symlink() {
880 Ok(Self::Symlink)
886 Self::Symlink
887 } else if f.is_fifo() {
888 Self::BadType(BadType::FIFO)
889 } else if f.is_block_device() {
890 Self::BadType(BadType::BlockDevice)
891 } else if f.is_char_device() {
892 Self::BadType(BadType::CharacterDevice)
893 } else if f.is_socket() {
894 Self::BadType(BadType::Socket)
881 } else {
895 } else {
882 // Things like FIFO etc.
896 Self::BadType(BadType::Unknown)
883 Err(())
884 }
897 }
885 }
898 }
886 }
899 }
@@ -942,10 +955,7 b" impl<'a> DirEntry<'a> {"
942 };
955 };
943 let filename =
956 let filename =
944 Cow::Owned(get_bytes_from_os_string(file_name).into());
957 Cow::Owned(get_bytes_from_os_string(file_name).into());
945 let file_type = match FakeFileType::try_from(file_type) {
958 let file_type = FakeFileType::from(file_type);
946 Ok(file_type) => file_type,
947 Err(_) => continue,
948 };
949 results.push(DirEntry {
959 results.push(DirEntry {
950 hg_path: filename,
960 hg_path: filename,
951 fs_path: Cow::Owned(full_path.to_path_buf()),
961 fs_path: Cow::Owned(full_path.to_path_buf()),
@@ -974,6 +984,13 b" impl<'a> DirEntry<'a> {"
974 fn is_symlink(&self) -> bool {
984 fn is_symlink(&self) -> bool {
975 self.file_type == FakeFileType::Symlink
985 self.file_type == FakeFileType::Symlink
976 }
986 }
987
988 fn is_bad(&self) -> Option<BadType> {
989 match self.file_type {
990 FakeFileType::BadType(ty) => Some(ty),
991 _ => None,
992 }
993 }
977 }
994 }
978
995
979 /// Return the `mtime` of a temporary file newly-created in the `.hg` directory
996 /// Return the `mtime` of a temporary file newly-created in the `.hg` directory
General Comments 0
You need to be logged in to leave comments. Login now