1
0
mirror of https://github.com/elua/elua.git synced 2025-01-08 20:56:17 +08:00

improved file type reporting

This commit is contained in:
Bogdan Marinescu 2013-01-16 01:54:34 +02:00
parent 0afbbecc17
commit ee737d717e
4 changed files with 7 additions and 5 deletions

View File

@ -29,6 +29,7 @@
#define CMN_FS_TYPE_ERROR 3
#define CMN_FS_TYPE_FILE_NOT_FOUND 4
#define CMN_FS_TYPE_DIR_NOT_FOUND 5
#define CMN_FS_TYPE_UNKNOWN_NOT_FOUND 6
typedef int ( *p_cmn_fs_walker_cb )( const char*, const struct dm_dirent*, void*, int );

View File

@ -128,7 +128,7 @@ int cmn_fs_get_type( const char *path )
return CMN_FS_TYPE_FILE;
}
if( ( d = dm_opendir( path ) ) == NULL )
return CMN_FS_TYPE_DIR_NOT_FOUND;
return CMN_FS_TYPE_UNKNOWN_NOT_FOUND;
dm_closedir( d );
return CMN_FS_TYPE_DIR;
}

View File

@ -196,9 +196,10 @@ static void shellh_adv_cp_mv_common( int argc, char **argv, int is_move )
goto done;
}
if( srctype == CMN_FS_TYPE_ERROR || srctype == CMN_FS_TYPE_FILE_NOT_FOUND ||
srctype == CMN_FS_TYPE_DIR_NOT_FOUND || dsttype == CMN_FS_TYPE_ERROR ||
dsttype == CMN_FS_TYPE_DIR_NOT_FOUND )
srctype == CMN_FS_TYPE_DIR_NOT_FOUND || srctype == CMN_FS_TYPE_UNKNOWN_NOT_FOUND ||
dsttype == CMN_FS_TYPE_ERROR || dsttype == CMN_FS_TYPE_DIR_NOT_FOUND )
{
printf( "%d %d\n", srctype, dsttype );
printf( "Invalid source and/or destination.\n" );
return;
}
@ -207,7 +208,7 @@ static void shellh_adv_cp_mv_common( int argc, char **argv, int is_move )
// Check valid source/destination combinations
if( srctype == CMN_FS_TYPE_FILE )
{
if( dsttype == CMN_FS_TYPE_FILE || dsttype == CMN_FS_TYPE_FILE_NOT_FOUND ) // direct file-to-file operation
if( dsttype == CMN_FS_TYPE_FILE || dsttype == CMN_FS_TYPE_FILE_NOT_FOUND || dsttype == CMN_FS_TYPE_UNKNOWN_NOT_FOUND ) // direct file-to-file operation
{
shellh_cp_or_mv_file( srcpath, dstpath, flags );
goto done;

View File

@ -131,7 +131,7 @@ void shell_adv_rm( int argc, char **argv )
masktype = cmn_fs_get_type( fmask );
if( masktype == CMN_FS_TYPE_FILE )
shellh_rm_one( fmask, flags );
else if( masktype == CMN_FS_TYPE_ERROR || masktype == CMN_FS_TYPE_FILE_NOT_FOUND || masktype == CMN_FS_TYPE_DIR_NOT_FOUND )
else if( masktype == CMN_FS_TYPE_ERROR || masktype == CMN_FS_TYPE_FILE_NOT_FOUND || masktype == CMN_FS_TYPE_DIR_NOT_FOUND || masktype == CMN_FS_TYPE_UNKNOWN_NOT_FOUND )
printf( "Invalid argument '%s'.\n", fmask );
else if( masktype == CMN_FS_TYPE_DIR && ( ( flags & SHELL_F_RECURSIVE ) == 0 ) )
printf( "'%s': unable to remove directory (use '-R').\n", fmask );