File tree Expand file tree Collapse file tree 3 files changed +17
-10
lines changed
opamp/instance_id/on_host Expand file tree Collapse file tree 3 files changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ use crate::opamp::instance_id::getter::DataStored;
44use crate :: opamp:: instance_id:: storer:: InstanceIDStorer ;
55use fs:: directory_manager:: { DirectoryManagementError , DirectoryManager , DirectoryManagerFs } ;
66use fs:: file_reader:: { FileReader , FileReaderError } ;
7+ use fs:: utils:: FsError ;
78use fs:: writer_file:: { FileWriter , WriteError } ;
89use fs:: LocalFile ;
910use std:: fs:: Permissions ;
8889 // Get a ref to the target file's parent directory
8990 let dest_dir = dest_file
9091 . parent ( )
91- . expect ( "parent directory dest_file should be valid (not empty nor root dir)" ) ;
92+ . ok_or ( WriteError :: from ( FsError :: InvalidPath ( format ! (
93+ "no parent directory found for {} (empty or root dir)" ,
94+ dest_file. display( )
95+ ) ) ) ) ?;
9296
9397 self . dir_manager
9498 . create ( dest_dir, Permissions :: from_mode ( DIRECTORY_PERMISSIONS ) ) ?;
Original file line number Diff line number Diff line change @@ -59,9 +59,9 @@ pub mod tests {
5959 ErrorDeletingDirectory ( delete_error. to_string ( ) ) ,
6060 ) ,
6161 InvalidDirectory ( invalid_dir_error) => match invalid_dir_error {
62- FsError :: InvalidPath ( ) => {
63- PersistError :: DirectoryError ( InvalidDirectory ( FsError :: InvalidPath ( ) ) )
64- }
62+ FsError :: InvalidPath ( s ) => PersistError :: DirectoryError ( InvalidDirectory (
63+ FsError :: InvalidPath ( s . to_string ( ) ) ,
64+ ) ) ,
6565 FsError :: DotsDisallowed ( msg) => PersistError :: DirectoryError (
6666 InvalidDirectory ( FsError :: DotsDisallowed ( msg. to_string ( ) ) ) ,
6767 ) ,
@@ -76,9 +76,9 @@ pub mod tests {
7676 ) ) )
7777 }
7878 InvalidPath ( fs_error) => match fs_error {
79- FsError :: InvalidPath ( ) => {
80- PersistError :: FileError ( InvalidPath ( FsError :: InvalidPath ( ) ) )
81- }
79+ FsError :: InvalidPath ( s ) => PersistError :: FileError ( InvalidPath (
80+ FsError :: InvalidPath ( s . to_string ( ) ) ,
81+ ) ) ,
8282 FsError :: DotsDisallowed ( path) => PersistError :: FileError ( InvalidPath (
8383 FsError :: DotsDisallowed ( path. to_string ( ) ) ,
8484 ) ) ,
Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ use thiserror::Error;
44
55#[ derive( Error , Debug , Clone ) ]
66pub enum FsError {
7- #[ error( "invalid path" ) ]
8- InvalidPath ( ) ,
7+ #[ error( "invalid path: `{0}` " ) ]
8+ InvalidPath ( String ) ,
99
1010 #[ error( "dots disallowed in path `{0}`" ) ]
1111 DotsDisallowed ( String ) ,
@@ -14,7 +14,10 @@ pub enum FsError {
1414#[ cfg( target_family = "unix" ) ]
1515pub fn validate_path ( path : & Path ) -> Result < ( ) , FsError > {
1616 match path. to_str ( ) {
17- None => Err ( FsError :: InvalidPath ( ) ) ,
17+ None => Err ( FsError :: InvalidPath ( format ! (
18+ "{} is not valid unicode" ,
19+ path. to_string_lossy( )
20+ ) ) ) ,
1821 Some ( valid_path) => {
1922 // disallow dots
2023 let dots_regex = Regex :: new ( r"\.\." ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments