Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/uu/split/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ split-error-unable-to-reopen-file = unable to re-open { $file }; aborting
split-error-file-descriptor-limit = at file descriptor limit, but no file descriptor left to close. Closed { $count } writers before.
split-error-shell-process-returned = Shell process returned { $code }
split-error-shell-process-terminated = Shell process terminated by signal
split-error-is-a-directory = { $dir }: Is a directory

# Help messages for command-line options
split-help-bytes = put SIZE bytes per output file
Expand Down
11 changes: 7 additions & 4 deletions src/uu/split/src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// file that was distributed with this source code.
use std::env;
use std::ffi::OsStr;
use std::io::Write;
use std::io::{BufWriter, Error, Result};
use std::io::{ErrorKind, Write};
use std::path::Path;
use std::process::{Child, Command, Stdio};
use uucore::error::USimpleError;
Expand Down Expand Up @@ -139,10 +139,13 @@ pub fn instantiate_current_writer(
.create(true)
.truncate(true)
.open(Path::new(&filename))
.map_err(|_| {
Error::other(
.map_err(|e| match e.kind() {
ErrorKind::IsADirectory => Error::other(
translate!("split-error-is-a-directory", "dir" => filename),
),
_ => Error::other(
translate!("split-error-unable-to-open-file", "file" => filename),
)
),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust linting in the pre-commit hook doesn't like it not being there, i.e. cargo fmt requires it to be there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK thanks

})?
} else {
// re-open file that we previously created to append to it
Expand Down
11 changes: 8 additions & 3 deletions src/uu/split/src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use std::ffi::OsStr;
use std::io::Write;
use std::io::{BufWriter, Error, Result};
use std::io::{ErrorKind, Write};
use std::path::Path;
use uucore::fs;
use uucore::translate;
Expand All @@ -25,8 +25,13 @@ pub fn instantiate_current_writer(
.create(true)
.truncate(true)
.open(Path::new(&filename))
.map_err(|_| {
Error::other(translate!("split-error-unable-to-open-file", "file" => filename))
.map_err(|e| match e.kind() {
ErrorKind::IsADirectory => {
Error::other(translate!("split-error-is-a-directory", "dir" => filename))
}
_ => {
Error::other(translate!("split-error-unable-to-open-file", "file" => filename))
}
})?
} else {
// re-open file that we previously created to append to it
Expand Down
13 changes: 13 additions & 0 deletions tests/by-util/test_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2078,3 +2078,16 @@ fn test_split_non_utf8_additional_suffix() {
"Expected at least one split file to be created"
);
}

#[test]
#[cfg(target_os = "linux")] // To re-enable on Windows once I work out what goes wrong with it.
fn test_split_directory_already_exists() {
let (at, mut ucmd) = at_and_ucmd!();

at.mkdir("xaa"); // For collision with.
at.touch("file");
ucmd.args(&["file"])
.fails_with_code(1)
.no_stdout()
.stderr_is("split: xaa: Is a directory\n");
}
Loading