Skip to content

Commit

Permalink
Override and copy single file bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
abdolence committed Aug 15, 2024
1 parent e517766 commit 2ba5414
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "redacter"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
authors = ["Abdulla Abdurakhmanov <[email protected]>"]
license = "Apache-2.0"
Expand Down
20 changes: 13 additions & 7 deletions src/commands/copy_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,7 @@ pub async fn command_copy(
}
bar.println("Copying directory and listing source files...");
let source_files_result = source_fs.list_files(Some(&options.file_matcher)).await?;
let source_files: Vec<FileSystemRef> = source_files_result
.files
.into_iter()
.map(|f| options.file_mime_override.override_for_file_ref(f))
.collect();
let source_files: Vec<FileSystemRef> = source_files_result.files;
let files_found = source_files.len();
let files_total_size: u64 = source_files
.iter()
Expand Down Expand Up @@ -221,6 +217,7 @@ async fn transfer_and_redact_file<
) -> AppResult<TransferFileResult> {
let bold_style = Style::new().bold().white();
let (base_file_ref, source_reader) = source_fs.download(source_file_ref).await?;

let base_resolved_file_ref = source_fs.resolve(Some(&base_file_ref));
match options.file_matcher.matches(&base_file_ref) {
FileMatcherResult::SkippedDueToSize | FileMatcherResult::SkippedDueToName => {
Expand All @@ -231,6 +228,7 @@ async fn transfer_and_redact_file<
}

let file_ref = source_file_ref.unwrap_or(&base_file_ref);

let dest_file_ref = FileSystemRef {
relative_path: file_ref.relative_path.clone(),
media_type: file_ref.media_type.clone(),
Expand Down Expand Up @@ -284,6 +282,7 @@ async fn transfer_and_redact_file<
bold_style,
source_reader,
file_ref,
options,
redacter_with_options,
file_converters,
)
Expand All @@ -298,6 +297,7 @@ async fn transfer_and_redact_file<
Ok(transfer_result)
}

#[allow(clippy::too_many_arguments)]
async fn redact_upload_file<
'a,
SFS: FileSystemConnection<'a>,
Expand All @@ -309,13 +309,19 @@ async fn redact_upload_file<
bold_style: Style,
source_reader: S,
dest_file_ref: &FileSystemRef,
options: &CopyCommandOptions,
redacter_with_options: &(RedacterBaseOptions, Vec<impl Redacter>),
file_converters: &FileConverters,
) -> AppResult<TransferFileResult> {
let (redacter_base_options, redacters) = redacter_with_options;
let mut support_redacters = Vec::new();
let dest_file_ref_overridden = options
.file_mime_override
.override_for_file_ref(dest_file_ref.clone());
for redacter in redacters {
let redacter_supported_options = redacter.redact_supported_options(dest_file_ref).await?;
let redacter_supported_options = redacter
.redact_supported_options(&dest_file_ref_overridden)
.await?;
if redacter_supported_options != RedactSupportedOptions::Unsupported {
support_redacters.push(redacter);
}
Expand All @@ -325,7 +331,7 @@ async fn redact_upload_file<
&support_redacters,
redacter_base_options,
source_reader,
dest_file_ref,
&dest_file_ref_overridden,
file_converters,
bar,
)
Expand Down
1 change: 0 additions & 1 deletion src/file_systems/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ impl<'a> FileSystemConnection<'a> for LocalFileSystem<'a> {
message: "Filename is empty".to_string(),
})?
.to_string_lossy()
.replace(self.root_path.as_str(), "")
.to_string();
let file_metadata = tokio::fs::metadata(&file_path).await?;
let file_ref = FileSystemRef {
Expand Down

0 comments on commit 2ba5414

Please sign in to comment.