2016-04-16 21:05:50 +00:00
|
|
|
|
//! Tests for various types of file (video, image, compressed, etc).
|
|
|
|
|
//!
|
|
|
|
|
//! Currently this is dependent on the file’s name and extension, because
|
|
|
|
|
//! those are the only metadata that we have access to without reading the
|
|
|
|
|
//! file’s contents.
|
|
|
|
|
|
2016-04-16 17:59:25 +00:00
|
|
|
|
use fs::File;
|
2014-06-17 08:35:40 +00:00
|
|
|
|
|
2015-06-08 20:33:39 +00:00
|
|
|
|
|
2016-03-17 20:40:04 +00:00
|
|
|
|
impl<'_> File<'_> {
|
2016-04-16 21:05:50 +00:00
|
|
|
|
|
|
|
|
|
/// An “immediate” file is something that can be run or activated somehow
|
|
|
|
|
/// in order to kick off the build of a project. It’s usually only present
|
|
|
|
|
/// in directories full of source code.
|
2016-03-18 12:19:51 +00:00
|
|
|
|
pub fn is_immediate(&self) -> bool {
|
2015-05-09 15:10:26 +00:00
|
|
|
|
self.name.starts_with("README") || self.name_is_one_of( &[
|
|
|
|
|
"Makefile", "Cargo.toml", "SConstruct", "CMakeLists.txt",
|
|
|
|
|
"build.gradle", "Rakefile", "Gruntfile.js",
|
|
|
|
|
"Gruntfile.coffee",
|
|
|
|
|
])
|
2015-05-12 02:08:24 +00:00
|
|
|
|
}
|
2015-05-09 15:10:26 +00:00
|
|
|
|
|
2016-03-18 12:19:51 +00:00
|
|
|
|
pub fn is_image(&self) -> bool {
|
2015-05-09 15:10:26 +00:00
|
|
|
|
self.extension_is_one_of( &[
|
|
|
|
|
"png", "jpeg", "jpg", "gif", "bmp", "tiff", "tif",
|
|
|
|
|
"ppm", "pgm", "pbm", "pnm", "webp", "raw", "arw",
|
|
|
|
|
"svg", "stl", "eps", "dvi", "ps", "cbr",
|
|
|
|
|
"cbz", "xpm", "ico",
|
|
|
|
|
])
|
2015-05-12 02:08:24 +00:00
|
|
|
|
}
|
2015-05-09 15:10:26 +00:00
|
|
|
|
|
2016-03-18 12:19:51 +00:00
|
|
|
|
pub fn is_video(&self) -> bool {
|
2015-05-09 15:10:26 +00:00
|
|
|
|
self.extension_is_one_of( &[
|
|
|
|
|
"avi", "flv", "m2v", "mkv", "mov", "mp4", "mpeg",
|
|
|
|
|
"mpg", "ogm", "ogv", "vob", "wmv",
|
|
|
|
|
])
|
2015-05-12 02:08:24 +00:00
|
|
|
|
}
|
2015-05-09 15:10:26 +00:00
|
|
|
|
|
2016-03-18 12:19:51 +00:00
|
|
|
|
pub fn is_music(&self) -> bool {
|
2015-05-09 15:10:26 +00:00
|
|
|
|
self.extension_is_one_of( &[
|
|
|
|
|
"aac", "m4a", "mp3", "ogg", "wma",
|
|
|
|
|
])
|
2015-05-12 02:08:24 +00:00
|
|
|
|
}
|
2015-05-09 15:10:26 +00:00
|
|
|
|
|
2016-04-16 21:05:50 +00:00
|
|
|
|
// Lossless music, rather than any other kind of data...
|
2016-03-18 12:19:51 +00:00
|
|
|
|
pub fn is_lossless(&self) -> bool {
|
2015-05-09 15:10:26 +00:00
|
|
|
|
self.extension_is_one_of( &[
|
|
|
|
|
"alac", "ape", "flac", "wav",
|
|
|
|
|
])
|
2015-05-12 02:08:24 +00:00
|
|
|
|
}
|
2015-05-09 15:10:26 +00:00
|
|
|
|
|
2016-03-18 12:19:51 +00:00
|
|
|
|
pub fn is_crypto(&self) -> bool {
|
2015-05-09 15:10:26 +00:00
|
|
|
|
self.extension_is_one_of( &[
|
2016-04-16 21:17:12 +00:00
|
|
|
|
"asc", "enc", "gpg", "pgp", "sig", "signature", "pfx", "p12",
|
2015-05-09 15:10:26 +00:00
|
|
|
|
])
|
2015-05-12 02:08:24 +00:00
|
|
|
|
}
|
2015-05-09 15:10:26 +00:00
|
|
|
|
|
2016-03-18 12:19:51 +00:00
|
|
|
|
pub fn is_document(&self) -> bool {
|
2015-05-09 15:10:26 +00:00
|
|
|
|
self.extension_is_one_of( &[
|
|
|
|
|
"djvu", "doc", "docx", "dvi", "eml", "eps", "fotd",
|
|
|
|
|
"odp", "odt", "pdf", "ppt", "pptx", "rtf",
|
|
|
|
|
"xls", "xlsx",
|
|
|
|
|
])
|
2015-05-12 02:08:24 +00:00
|
|
|
|
}
|
2015-05-09 15:10:26 +00:00
|
|
|
|
|
2016-03-18 12:19:51 +00:00
|
|
|
|
pub fn is_compressed(&self) -> bool {
|
2015-05-09 15:10:26 +00:00
|
|
|
|
self.extension_is_one_of( &[
|
|
|
|
|
"zip", "tar", "Z", "gz", "bz2", "a", "ar", "7z",
|
|
|
|
|
"iso", "dmg", "tc", "rar", "par"
|
|
|
|
|
])
|
2015-05-12 02:08:24 +00:00
|
|
|
|
}
|
2015-05-09 15:10:26 +00:00
|
|
|
|
|
2016-03-18 12:19:51 +00:00
|
|
|
|
pub fn is_temp(&self) -> bool {
|
2015-05-09 15:10:26 +00:00
|
|
|
|
self.name.ends_with("~")
|
|
|
|
|
|| (self.name.starts_with("#") && self.name.ends_with("#"))
|
|
|
|
|
|| self.extension_is_one_of( &[ "tmp", "swp", "swo", "swn", "bak" ])
|
2015-05-12 02:08:24 +00:00
|
|
|
|
}
|
2015-05-09 15:10:26 +00:00
|
|
|
|
|
2016-03-18 12:19:51 +00:00
|
|
|
|
pub fn is_compiled(&self) -> bool {
|
2015-05-09 15:10:26 +00:00
|
|
|
|
if self.extension_is_one_of( &[ "class", "elc", "hi", "o", "pyc" ]) {
|
|
|
|
|
true
|
Use new io + path + fs libraries (LOTS OF CHANGES)
Exa now uses the new IO, Path, and Filesystem libraries that have been out for a while now.
Unfortunately, the new libraries don't *entirely* cover the range of the old libraries just yet: in particular, to become more cross-platform, the data in `UnstableFileStat` isn't available in the Unix `MetadataExt` yet. Much of this is contained in rust-lang/rfcs#1044 (which is due to be implemented in rust-lang/rust#14711), but it's not *entirely* there yet.
As such, this commits a serious loss of functionality: no symlink viewing, no hard links or blocks, or users or groups. Also, some of the code could now be optimised. I just wanted to commit this to sort out most of the 'teething problems' of having a different path system in advance.
Here's an example problem that took ages to fix for you, just because you read this far: when I first got exa to compile, it worked mostly fine, except calling `exa` by itself didn't list the current directory. I traced where the command-line options were being generated, to where files and directories were sorted, to where the threads were spawned... and the problem turned out to be that it was using the full path as the file name, rather than just the last component, and these paths happened to begin with `.`, so it thought they were dotfiles.
2015-04-23 12:00:34 +00:00
|
|
|
|
}
|
2015-05-09 15:10:26 +00:00
|
|
|
|
else if let Some(dir) = self.dir {
|
|
|
|
|
self.get_source_files().iter().any(|path| dir.contains(path))
|
2014-06-17 08:35:40 +00:00
|
|
|
|
}
|
2015-05-09 15:10:26 +00:00
|
|
|
|
else {
|
|
|
|
|
false
|
2014-06-17 08:35:40 +00:00
|
|
|
|
}
|
2015-05-12 02:08:24 +00:00
|
|
|
|
}
|
2014-06-17 08:35:40 +00:00
|
|
|
|
}
|
2015-01-26 01:16:19 +00:00
|
|
|
|
|
2015-06-08 20:33:39 +00:00
|
|
|
|
|
2015-04-23 12:47:46 +00:00
|
|
|
|
#[cfg(broken_test)]
|
2015-01-26 01:16:19 +00:00
|
|
|
|
mod test {
|
2015-02-04 01:12:08 +00:00
|
|
|
|
use file::test::{dummy_stat, new_file};
|
2015-01-26 01:16:19 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn lowercase() {
|
2015-02-04 01:12:08 +00:00
|
|
|
|
let file = new_file(dummy_stat(), "/barracks.wav");
|
2015-01-26 01:16:19 +00:00
|
|
|
|
assert_eq!(FileType::Lossless, file.get_type())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn uppercase() {
|
2015-02-04 01:12:08 +00:00
|
|
|
|
let file = new_file(dummy_stat(), "/BARRACKS.WAV");
|
2015-01-26 01:16:19 +00:00
|
|
|
|
assert_eq!(FileType::Lossless, file.get_type())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn cargo() {
|
2015-02-04 01:12:08 +00:00
|
|
|
|
let file = new_file(dummy_stat(), "/Cargo.toml");
|
2015-01-26 01:16:19 +00:00
|
|
|
|
assert_eq!(FileType::Immediate, file.get_type())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn not_cargo() {
|
2015-02-04 01:12:08 +00:00
|
|
|
|
let file = new_file(dummy_stat(), "/cargo.toml");
|
2015-01-26 01:16:19 +00:00
|
|
|
|
assert_eq!(FileType::Normal, file.get_type())
|
|
|
|
|
}
|
|
|
|
|
}
|