Skip to content

Commit

Permalink
Revert ":sparkles: Add --cd option to create subcommand, it likes…
Browse files Browse the repository at this point in the history
… tar command `-C` option"

This reverts commit 81cecfe.
  • Loading branch information
ChanTsune committed Jan 24, 2025
1 parent 366f41d commit cb21f8c
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions cli/src/command/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use bytesize::ByteSize;
use clap::{ArgGroup, Parser, ValueHint};
use pna::{Archive, SolidEntryBuilder, WriteOptions};
use std::{
env, fs,
fs::{self, File},
io::{self, prelude::*},
path::{Path, PathBuf},
time::Instant,
Expand Down Expand Up @@ -88,15 +88,6 @@ pub(crate) struct CreateCommand {
pub(crate) gitignore: bool,
#[arg(long, help = "Follow symbolic links")]
pub(crate) follow_links: bool,
#[arg(
short = 'C',
long = "cd",
aliases = ["directory"],
value_name = "DIRECTORY",
help = "changes the directory before adding the following files",
value_hint = ValueHint::DirPath
)]
working_dir: Option<PathBuf>,
#[command(flatten)]
pub(crate) compression: CompressionAlgorithmArgs,
#[command(flatten)]
Expand All @@ -119,7 +110,6 @@ impl Command for CreateCommand {
}

fn create_archive(args: CreateCommand) -> io::Result<()> {
let current_dir = env::current_dir()?;
let password = ask_password(args.password)?;
check_password(&password, &args.cipher);
let start = Instant::now();
Expand Down Expand Up @@ -149,10 +139,6 @@ fn create_archive(args: CreateCommand) -> io::Result<()> {
} else {
None
};
let archive_path = current_dir.join(archive);
if let Some(working_dir) = args.working_dir {
env::set_current_dir(working_dir)?;
}
let target_items = collect_items(
&files,
args.recursive,
Expand All @@ -162,7 +148,7 @@ fn create_archive(args: CreateCommand) -> io::Result<()> {
exclude,
)?;

if let Some(parent) = archive_path.parent() {
if let Some(parent) = archive.parent() {
fs::create_dir_all(parent)?;
}
let max_file_size = args
Expand All @@ -186,7 +172,7 @@ fn create_archive(args: CreateCommand) -> io::Result<()> {
let write_option = entry_option(args.compression, args.cipher, args.hash, password);
if let Some(size) = max_file_size {
create_archive_with_split(
&archive_path,
&args.file.archive,
write_option,
keep_options,
owner_options,
Expand All @@ -196,7 +182,7 @@ fn create_archive(args: CreateCommand) -> io::Result<()> {
)?;
} else {
create_archive_file(
|| fs::File::create(&archive_path),
|| File::create(&args.file.archive),
write_option,
keep_options,
owner_options,
Expand All @@ -208,7 +194,6 @@ fn create_archive(args: CreateCommand) -> io::Result<()> {
"Successfully created an archive in {}",
DurationDisplay(start.elapsed())
);
env::set_current_dir(current_dir)?;
Ok(())
}

Expand Down

0 comments on commit cb21f8c

Please sign in to comment.