@@ -43,6 +43,44 @@ string params_fio_handler_base::GetInfos()
4343 info_fio_params.clear ();
4444 return the_return;
4545}
46+ optional<string> params_fio_handler_base::
47+ FileTypeChecker ( const filesystem::path& the_path,
48+ const string&prefix,
49+ const bool &check_exists, const bool & check_not_fifo, const bool &check_not_dev_char)
50+ {
51+ filesystem::file_status the_file_status ( filesystem::status ( the_path ));
52+ if ( filesystem::exists ( the_file_status ) == false )
53+ {
54+ if ( check_exists )
55+ return prefix + string (" file " ) + the_path.filename ().string () + string (" not found" );
56+ else
57+ return nullopt ;
58+ }
59+ if ( filesystem::is_regular_file ( the_file_status ))
60+ return nullopt ;
61+ if ( filesystem::is_fifo ( the_file_status ) )
62+ {
63+ if ( check_not_fifo )
64+ return prefix + string (" " ) + the_path.filename ().string () + string (" should NOT be a fifo" );
65+ else
66+ return nullopt ;
67+ }
68+ if (filesystem::is_directory ( the_file_status ) )
69+ return prefix + string (" " ) + the_path.filename ().string () + string (" should NOT be a directory" );
70+
71+ // Since we ask to follow symlinks to the destination,
72+ // it is claimed as a symlink only if it points on nothing.
73+ if (filesystem::is_symlink ( the_file_status ) )
74+ return prefix + string (" " ) + the_path.filename ().string () + string (" should NOT be a symlink" );
75+ if ( filesystem::is_character_file ( the_file_status ) )
76+ {
77+ if ( check_not_dev_char )
78+ return prefix + string (" " ) + the_path.filename ().string () + string (" should NOT be a char device" );
79+ else
80+ return nullopt ;
81+ }
82+ return prefix + string (" " ) + the_path.filename ().string () + string (" should NOT be a dev block nor socket" );
83+ }
4684
4785
4886params_input_handler::params_input_handler ():
@@ -59,11 +97,11 @@ params_input_handler::params_input_handler():
5997{}
6098
6199
62- /* @breif Validate options in the current channel
100+ /* @brief Validate options in the current channel
63101 *
64102 * Each time the software receives a new input (-i), a new output (-o)
65103 * or a flush (calling parameters are over), the pending input options are tested and
66- * if everythingare is correct, a structure is added to the input channels list.
104+ * if everything is correct, a structure is added to the input channels list.
67105 * If something is wrong, the options of this input are discarded.
68106 * That does NOT prevent the usage of other input channels
69107 */
@@ -101,7 +139,7 @@ void params_input_handler::AddChannelOptions( const options_list_t & opts_list
101139 if ( it.second == in_format->second )
102140 {
103141 info_fio_params << " The input commands format " <<in_format->second ;
104- info_fio_params << " is not yet supported, comming soon" <<endl;
142+ info_fio_params << " is not yet supported, coming soon" <<endl;
105143 return ;
106144 }
107145 info_fio_params << " The input commands format " <<in_format->second ;
@@ -114,7 +152,7 @@ void params_input_handler::AddChannelOptions( const options_list_t & opts_list
114152void params_input_handler::CreateInputChannels (const unsigned short &loop_counter)
115153{
116154 // For the input channels there is a sanity check.
117- // If the type is explicitely defined, the check verifies the input. If false, the input is omitted.
155+ // If the type is explicitly defined, the check verifies the input. If false, the input is omitted.
118156 // If the type is not defined, the software tries to identify with the sanity checks.
119157 for ( auto & chan : fio_channels_with_opts )
120158 {
@@ -136,8 +174,20 @@ void params_input_handler::CreateInputChannels(const unsigned short&loop_counter
136174 ifstream input_stream;
137175 if ( (*in_opt_name).second .compare ( " -" ))
138176 {
139- input_stream.open ( (*in_opt_name).second , ios_base::in );
140- if ( input_stream.is_open () )
177+ bool file_is_opened = false ;
178+ filesystem::path the_path ( (*in_opt_name).second );
179+ optional<string> ftc = FileTypeChecker ( the_path, " Input commands" , true , false , true );
180+ if ( ftc )
181+ info_fio_params << *ftc << endl;
182+ else
183+ {
184+ input_stream.open ( the_path, ios_base::in );
185+ file_is_opened = input_stream.is_open ();
186+ if ( file_is_opened == false )
187+ cout << " Problem opening " << the_path.filename () << " , check the permissions" << endl;
188+ }
189+
190+ if ( file_is_opened )
141191 {
142192 switch ( chan.first )
143193 {
@@ -169,11 +219,6 @@ void params_input_handler::CreateInputChannels(const unsigned short&loop_counter
169219 break ;
170220 }
171221 }
172- else
173- {
174- info_fio_params << " Problem opening file " << (*in_opt_name).second ;
175- info_fio_params << " , check directory and permissions" << endl;
176- }
177222 }
178223 else
179224 switch ( chan.first )
@@ -233,7 +278,7 @@ params_output_handler::params_output_handler():
233278 *
234279 * Each time the software receives a new input (-i), a new output (-o)
235280 * or a flush (calling parameters are over), the pending output options are tested and
236- * if everythingare is correct, a structure is added to the output channels list.
281+ * if everything is correct, a structure is added to the output channels list.
237282 * If something is wrong, the options of this output are discarded.
238283 * That does NOT prevent the usage of other output channels
239284 */
@@ -264,14 +309,14 @@ void params_output_handler::AddChannelOptions( const options_list_t & opts_list
264309 if ( it.second == out_format->second )
265310 {
266311 info_fio_params << " The output commands format " <<out_format->second ;
267- info_fio_params << " is not yet supported, comming soon" <<endl;
312+ info_fio_params << " is not yet supported, coming soon" <<endl;
268313 return ;
269314 }
270315 info_fio_params << " The output commands format " <<out_format->second ;
271316 info_fio_params << " is unknown" <<endl;
272317 return ;
273318 }
274- // no format info, use a defult
319+ // no format info, use a default
275320 else
276321 fio_channels_with_opts.push_back ( make_pair ( params_io_text, opts_list ));
277322}
@@ -301,8 +346,20 @@ void params_output_handler::CreateOutputChannels(void)
301346
302347 if ( (*out_opt_name).second .compare ( " -" ))
303348 {
304- output_stream.open ( (*out_opt_name).second , ios_base::out );
305- if ( output_stream.is_open () )
349+ bool file_is_opened = false ;
350+ filesystem::path the_path ( (*out_opt_name).second );
351+ optional<string> ftc = FileTypeChecker ( the_path, " Output commands" , false , false , true );
352+ if ( ftc )
353+ info_fio_params << *ftc << endl;
354+ else
355+ {
356+ output_stream.open ( the_path, ios_base::out );
357+ file_is_opened = output_stream.is_open ();
358+ if ( file_is_opened == false )
359+ cout << " Problem opening " << the_path.filename () << " , check the permissions" << endl;
360+ }
361+
362+ if ( file_is_opened )
306363 {
307364 switch ( chan.first )
308365 {
@@ -325,11 +382,6 @@ void params_output_handler::CreateOutputChannels(void)
325382 break ;
326383 }
327384 }
328- else
329- {
330- info_fio_params << " Problem opening file " << (*out_opt_name).second ;
331- info_fio_params << " , check directory and permissions" << endl;
332- }
333385 }
334386 else
335387 switch ( chan.first )
@@ -418,22 +470,22 @@ void params_file_handler::AddChannelOptions( const options_list_t & opts_list )
418470 if ( it.second == out_format->second )
419471 {
420472 info_fio_params << " The file format format " <<out_format->second ;
421- info_fio_params << " is not yet supported, comming soon" <<endl;
473+ info_fio_params << " is not yet supported, coming soon" <<endl;
422474 return ;
423475 }
424476 info_fio_params << " The file format " <<out_format->second ;
425477 info_fio_params << " is unknown" <<endl;
426478 return ;
427479 }
428- // no format info, use a defult
480+ // no format info, use a default
429481 else
430482 fio_channels_with_opts.push_back ( make_pair ( params_file_16BE, opts_list ));
431483}
432484void params_file_handler::EnvironementNeeds (void )
433485{}
434486void params_file_handler::CreateOutputFile ()
435487{
436- // This may be temporary as today, there is only one possiblie file at a time
488+ // This may be temporary as today, there is only one possible file at a time
437489 if ( fio_channels_with_opts.empty () == false )
438490 {
439491 auto chan = fio_channels_with_opts.rbegin ();
@@ -458,8 +510,23 @@ void params_file_handler::CreateOutputFile()
458510 {
459511 if ( (*file_opt_name).second .compare ( " -" ))
460512 {
461- output_file_stream.open ( (*file_opt_name).second , ostream::binary | ostream::trunc );
462- info_fio_params << " Opening the output file" << (*file_opt_name).second << endl;
513+ bool file_is_opened = false ;
514+ filesystem::path the_path ( (*file_opt_name).second );
515+ optional<string> ftc = FileTypeChecker ( the_path, " Output sound file" , false , true , true );
516+ if ( ftc )
517+ info_fio_params << *ftc << endl;
518+ else
519+ {
520+ output_file_stream.open ( the_path, ostream::binary | ostream::trunc );
521+ file_is_opened = output_file_stream.is_open ();
522+ if ( file_is_opened == false )
523+ cout << " Problem opening " << the_path.filename () << " , check the permissions" << endl;
524+ else
525+ info_fio_params << " Opening the output file" << the_path.filename () << endl;
526+ }
527+ // *************************************************
528+ // Should do something if the file can not be opened
529+ // *************************************************
463530 }else {
464531 info_fio_params << " Using the standard output for the file output is discourageous" << endl;
465532 }
0 commit comments