-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update clap, refactor, support recovery record and fast mode
- Loading branch information
Showing
11 changed files
with
3,183 additions
and
2,709 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use std::path::Path; | ||
|
||
use anyhow::anyhow; | ||
|
||
#[derive(Debug)] | ||
pub enum ArchiveFormat { | ||
Z, | ||
Zip, | ||
Gzip, | ||
Bzip2, | ||
Lz, | ||
Xz, | ||
Lzma, | ||
P7z, | ||
Tar, | ||
TarZ, | ||
TarGzip, | ||
TarBzip2, | ||
TarLz, | ||
TarXz, | ||
TarLzma, | ||
Tar7z, | ||
TarZstd, | ||
Rar, | ||
Zstd, | ||
} | ||
|
||
impl ArchiveFormat { | ||
pub fn get_archive_format_from_file_path<P: AsRef<Path>>( | ||
file_path: P, | ||
) -> anyhow::Result<ArchiveFormat> { | ||
let file_path = file_path.as_ref(); | ||
|
||
if let Some(file_name) = file_path.file_name() { | ||
if let Some(file_name) = file_name.to_str() { | ||
let file_name = file_name.to_ascii_lowercase(); | ||
|
||
if file_name.ends_with("tar.z") { | ||
return Ok(ArchiveFormat::TarZ); | ||
} else if file_name.ends_with(".tar.gz") || file_name.ends_with(".tgz") { | ||
return Ok(ArchiveFormat::TarGzip); | ||
} else if file_name.ends_with(".tar.bz2") || file_name.ends_with(".tbz2") { | ||
return Ok(ArchiveFormat::TarBzip2); | ||
} else if file_name.ends_with(".tar.lz") { | ||
return Ok(ArchiveFormat::TarLz); | ||
} else if file_name.ends_with(".tar.xz") || file_name.ends_with(".txz") { | ||
return Ok(ArchiveFormat::TarXz); | ||
} else if file_name.ends_with(".tar.lzma") || file_name.ends_with(".tlz") { | ||
return Ok(ArchiveFormat::TarLzma); | ||
} else if file_name.ends_with(".tar.7z") | ||
|| file_name.ends_with(".tar.7z.001") | ||
|| file_name.ends_with(".t7z") | ||
{ | ||
return Ok(ArchiveFormat::Tar7z); | ||
} else if file_name.ends_with(".tar.zst") { | ||
return Ok(ArchiveFormat::TarZstd); | ||
} else if file_name.ends_with(".tar") { | ||
return Ok(ArchiveFormat::Tar); | ||
} else if file_name.ends_with(".z") { | ||
return Ok(ArchiveFormat::Z); | ||
} else if file_name.ends_with(".zip") { | ||
return Ok(ArchiveFormat::Zip); | ||
} else if file_name.ends_with(".gz") { | ||
return Ok(ArchiveFormat::Gzip); | ||
} else if file_name.ends_with(".bz2") { | ||
return Ok(ArchiveFormat::Bzip2); | ||
} else if file_name.ends_with(".lz") { | ||
return Ok(ArchiveFormat::Lz); | ||
} else if file_name.ends_with(".xz") { | ||
return Ok(ArchiveFormat::Xz); | ||
} else if file_name.ends_with(".lzma") { | ||
return Ok(ArchiveFormat::Lzma); | ||
} else if file_name.ends_with(".7z") || file_name.ends_with(".7z.001") { | ||
return Ok(ArchiveFormat::P7z); | ||
} else if file_name.ends_with(".rar") { | ||
return Ok(ArchiveFormat::Rar); | ||
} else if file_name.ends_with(".zst") { | ||
return Ok(ArchiveFormat::Zstd); | ||
} | ||
} | ||
} | ||
|
||
Err(anyhow!("Unknown archive format.")) | ||
} | ||
} |
Oops, something went wrong.