File tree Expand file tree Collapse file tree 4 files changed +29
-7
lines changed
Expand file tree Collapse file tree 4 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ split-error-unable-to-reopen-file = unable to re-open { $file }; aborting
4343split-error-file-descriptor-limit = at file descriptor limit, but no file descriptor left to close. Closed { $count } writers before.
4444split-error-shell-process-returned = Shell process returned { $code }
4545split-error-shell-process-terminated = Shell process terminated by signal
46+ split-error-is-a-directory = { $dir } : Is a directory
4647
4748# Help messages for command-line options
4849split-help-bytes = put SIZE bytes per output file
Original file line number Diff line number Diff line change 44// file that was distributed with this source code.
55use std:: env;
66use std:: ffi:: OsStr ;
7- use std:: io:: Write ;
87use std:: io:: { BufWriter , Error , Result } ;
8+ use std:: io:: { ErrorKind , Write } ;
99use std:: path:: Path ;
1010use std:: process:: { Child , Command , Stdio } ;
1111use uucore:: error:: USimpleError ;
@@ -139,10 +139,13 @@ pub fn instantiate_current_writer(
139139 . create ( true )
140140 . truncate ( true )
141141 . open ( Path :: new ( & filename) )
142- . map_err ( |_| {
143- Error :: other (
142+ . map_err ( |e| match e. kind ( ) {
143+ ErrorKind :: IsADirectory => Error :: other (
144+ translate ! ( "split-error-is-a-directory" , "dir" => filename) ,
145+ ) ,
146+ _ => Error :: other (
144147 translate ! ( "split-error-unable-to-open-file" , "file" => filename) ,
145- )
148+ ) ,
146149 } ) ?
147150 } else {
148151 // re-open file that we previously created to append to it
Original file line number Diff line number Diff line change 33// For the full copyright and license information, please view the LICENSE
44// file that was distributed with this source code.
55use std:: ffi:: OsStr ;
6- use std:: io:: Write ;
76use std:: io:: { BufWriter , Error , Result } ;
7+ use std:: io:: { ErrorKind , Write } ;
88use std:: path:: Path ;
99use uucore:: fs;
1010use uucore:: translate;
@@ -25,8 +25,13 @@ pub fn instantiate_current_writer(
2525 . create ( true )
2626 . truncate ( true )
2727 . open ( Path :: new ( & filename) )
28- . map_err ( |_| {
29- Error :: other ( translate ! ( "split-error-unable-to-open-file" , "file" => filename) )
28+ . map_err ( |e| match e. kind ( ) {
29+ ErrorKind :: IsADirectory => {
30+ Error :: other ( translate ! ( "split-error-is-a-directory" , "dir" => filename) )
31+ }
32+ _ => {
33+ Error :: other ( translate ! ( "split-error-unable-to-open-file" , "file" => filename) )
34+ }
3035 } ) ?
3136 } else {
3237 // re-open file that we previously created to append to it
Original file line number Diff line number Diff line change @@ -2078,3 +2078,16 @@ fn test_split_non_utf8_additional_suffix() {
20782078 "Expected at least one split file to be created"
20792079 ) ;
20802080}
2081+
2082+ #[ test]
2083+ #[ cfg( target_os = "linux" ) ] // To re-enable on Windows once I work out what goes wrong with it.
2084+ fn test_split_directory_already_exists ( ) {
2085+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
2086+
2087+ at. mkdir ( "xaa" ) ; // For collision with.
2088+ at. touch ( "file" ) ;
2089+ ucmd. args ( & [ "file" ] )
2090+ . fails_with_code ( 1 )
2091+ . no_stdout ( )
2092+ . stderr_is ( "split: xaa: Is a directory\n " ) ;
2093+ }
You can’t perform that action at this time.
0 commit comments