|
@@ -7,21 +7,24 @@
|
|
|
use fs::File;
|
|
use fs::File;
|
|
|
|
|
|
|
|
|
|
|
|
|
-impl<'a> File<'a> {
|
|
|
|
|
|
|
+#[derive(Debug)]
|
|
|
|
|
+pub struct FileExtensions;
|
|
|
|
|
+
|
|
|
|
|
+impl FileExtensions {
|
|
|
|
|
|
|
|
/// An “immediate” file is something that can be run or activated somehow
|
|
/// 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 order to kick off the build of a project. It’s usually only present
|
|
|
/// in directories full of source code.
|
|
/// in directories full of source code.
|
|
|
- pub fn is_immediate(&self) -> bool {
|
|
|
|
|
- self.name.starts_with("README") || self.name_is_one_of( &[
|
|
|
|
|
|
|
+ pub fn is_immediate(&self, file: &File) -> bool {
|
|
|
|
|
+ file.name.starts_with("README") || file.name_is_one_of( &[
|
|
|
"Makefile", "Cargo.toml", "SConstruct", "CMakeLists.txt",
|
|
"Makefile", "Cargo.toml", "SConstruct", "CMakeLists.txt",
|
|
|
"build.gradle", "Rakefile", "Gruntfile.js",
|
|
"build.gradle", "Rakefile", "Gruntfile.js",
|
|
|
"Gruntfile.coffee",
|
|
"Gruntfile.coffee",
|
|
|
])
|
|
])
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- pub fn is_image(&self) -> bool {
|
|
|
|
|
- self.extension_is_one_of( &[
|
|
|
|
|
|
|
+ pub fn is_image(&self, file: &File) -> bool {
|
|
|
|
|
+ file.extension_is_one_of( &[
|
|
|
"png", "jpeg", "jpg", "gif", "bmp", "tiff", "tif",
|
|
"png", "jpeg", "jpg", "gif", "bmp", "tiff", "tif",
|
|
|
"ppm", "pgm", "pbm", "pnm", "webp", "raw", "arw",
|
|
"ppm", "pgm", "pbm", "pnm", "webp", "raw", "arw",
|
|
|
"svg", "stl", "eps", "dvi", "ps", "cbr",
|
|
"svg", "stl", "eps", "dvi", "ps", "cbr",
|
|
@@ -29,92 +32,62 @@ impl<'a> File<'a> {
|
|
|
])
|
|
])
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- pub fn is_video(&self) -> bool {
|
|
|
|
|
- self.extension_is_one_of( &[
|
|
|
|
|
|
|
+ pub fn is_video(&self, file: &File) -> bool {
|
|
|
|
|
+ file.extension_is_one_of( &[
|
|
|
"avi", "flv", "m2v", "mkv", "mov", "mp4", "mpeg",
|
|
"avi", "flv", "m2v", "mkv", "mov", "mp4", "mpeg",
|
|
|
"mpg", "ogm", "ogv", "vob", "wmv",
|
|
"mpg", "ogm", "ogv", "vob", "wmv",
|
|
|
])
|
|
])
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- pub fn is_music(&self) -> bool {
|
|
|
|
|
- self.extension_is_one_of( &[
|
|
|
|
|
|
|
+ pub fn is_music(&self, file: &File) -> bool {
|
|
|
|
|
+ file.extension_is_one_of( &[
|
|
|
"aac", "m4a", "mp3", "ogg", "wma",
|
|
"aac", "m4a", "mp3", "ogg", "wma",
|
|
|
])
|
|
])
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Lossless music, rather than any other kind of data...
|
|
// Lossless music, rather than any other kind of data...
|
|
|
- pub fn is_lossless(&self) -> bool {
|
|
|
|
|
- self.extension_is_one_of( &[
|
|
|
|
|
|
|
+ pub fn is_lossless(&self, file: &File) -> bool {
|
|
|
|
|
+ file.extension_is_one_of( &[
|
|
|
"alac", "ape", "flac", "wav",
|
|
"alac", "ape", "flac", "wav",
|
|
|
])
|
|
])
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- pub fn is_crypto(&self) -> bool {
|
|
|
|
|
- self.extension_is_one_of( &[
|
|
|
|
|
|
|
+ pub fn is_crypto(&self, file: &File) -> bool {
|
|
|
|
|
+ file.extension_is_one_of( &[
|
|
|
"asc", "enc", "gpg", "pgp", "sig", "signature", "pfx", "p12",
|
|
"asc", "enc", "gpg", "pgp", "sig", "signature", "pfx", "p12",
|
|
|
])
|
|
])
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- pub fn is_document(&self) -> bool {
|
|
|
|
|
- self.extension_is_one_of( &[
|
|
|
|
|
|
|
+ pub fn is_document(&self, file: &File) -> bool {
|
|
|
|
|
+ file.extension_is_one_of( &[
|
|
|
"djvu", "doc", "docx", "dvi", "eml", "eps", "fotd",
|
|
"djvu", "doc", "docx", "dvi", "eml", "eps", "fotd",
|
|
|
"odp", "odt", "pdf", "ppt", "pptx", "rtf",
|
|
"odp", "odt", "pdf", "ppt", "pptx", "rtf",
|
|
|
"xls", "xlsx",
|
|
"xls", "xlsx",
|
|
|
])
|
|
])
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- pub fn is_compressed(&self) -> bool {
|
|
|
|
|
- self.extension_is_one_of( &[
|
|
|
|
|
|
|
+ pub fn is_compressed(&self, file: &File) -> bool {
|
|
|
|
|
+ file.extension_is_one_of( &[
|
|
|
"zip", "tar", "Z", "gz", "bz2", "a", "ar", "7z",
|
|
"zip", "tar", "Z", "gz", "bz2", "a", "ar", "7z",
|
|
|
"iso", "dmg", "tc", "rar", "par", "tgz",
|
|
"iso", "dmg", "tc", "rar", "par", "tgz",
|
|
|
])
|
|
])
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- pub fn is_temp(&self) -> bool {
|
|
|
|
|
- self.name.ends_with('~')
|
|
|
|
|
- || (self.name.starts_with('#') && self.name.ends_with('#'))
|
|
|
|
|
- || self.extension_is_one_of( &[ "tmp", "swp", "swo", "swn", "bak" ])
|
|
|
|
|
|
|
+ pub fn is_temp(&self, file: &File) -> bool {
|
|
|
|
|
+ file.name.ends_with('~')
|
|
|
|
|
+ || (file.name.starts_with('#') && file.name.ends_with('#'))
|
|
|
|
|
+ || file.extension_is_one_of( &[ "tmp", "swp", "swo", "swn", "bak" ])
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- pub fn is_compiled(&self) -> bool {
|
|
|
|
|
- if self.extension_is_one_of( &[ "class", "elc", "hi", "o", "pyc" ]) {
|
|
|
|
|
|
|
+ pub fn is_compiled(&self, file: &File) -> bool {
|
|
|
|
|
+ if file.extension_is_one_of( &[ "class", "elc", "hi", "o", "pyc" ]) {
|
|
|
true
|
|
true
|
|
|
}
|
|
}
|
|
|
- else if let Some(dir) = self.parent_dir {
|
|
|
|
|
- self.get_source_files().iter().any(|path| dir.contains(path))
|
|
|
|
|
|
|
+ else if let Some(dir) = file.parent_dir {
|
|
|
|
|
+ file.get_source_files().iter().any(|path| dir.contains(path))
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
false
|
|
false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-#[cfg(broken_test)]
|
|
|
|
|
-mod test {
|
|
|
|
|
- use file::test::{dummy_stat, new_file};
|
|
|
|
|
-
|
|
|
|
|
- #[test]
|
|
|
|
|
- fn lowercase() {
|
|
|
|
|
- let file = new_file(dummy_stat(), "/barracks.wav");
|
|
|
|
|
- assert_eq!(FileType::Lossless, file.get_type())
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- #[test]
|
|
|
|
|
- fn uppercase() {
|
|
|
|
|
- let file = new_file(dummy_stat(), "/BARRACKS.WAV");
|
|
|
|
|
- assert_eq!(FileType::Lossless, file.get_type())
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- #[test]
|
|
|
|
|
- fn cargo() {
|
|
|
|
|
- let file = new_file(dummy_stat(), "/Cargo.toml");
|
|
|
|
|
- assert_eq!(FileType::Immediate, file.get_type())
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- #[test]
|
|
|
|
|
- fn not_cargo() {
|
|
|
|
|
- let file = new_file(dummy_stat(), "/cargo.toml");
|
|
|
|
|
- assert_eq!(FileType::Normal, file.get_type())
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|