Skip to content

Commit

Permalink
UPDATE TO V0.28.1
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinwilliams committed Feb 1, 2019
1 parent 2b06ada commit c55e2ca
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 20 deletions.
3 changes: 3 additions & 0 deletions ChangeLog-CN
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
0.28.1 2019-02-01 calvin
* ����readdir�ķ��ؽṹ��Աd_type��ijЩ�ļ�ϵͳ�п��ܹ���������������stat����ж�

0.28.0 2018-11-28 calvin
* ������cockerָ��'-a create'��'-a boot'ʱ��������������ʱ���ڵ�����
* �ĵ������½� 3.3.5. ��������������
Expand Down
4 changes: 2 additions & 2 deletions src/cocker/action_del_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ int DoAction_del_image( struct CockerEnvironment *env )

if( IsDirectoryEmpty( version_path_base ) == 0 )
{
nret = SnprintfAndSystem( cmd , sizeof(cmd) , "rm -rf %s" , version_path_base ) ;
INTER1( "*** ERROR : SnprintfAndSystem [rm -rf %s] failed[%d] , errno[%d]\n" , version_path_base , nret , errno )
nret = SnprintfAndSystem( cmd , sizeof(cmd) , "rmdir %s" , version_path_base ) ;
INTER1( "*** ERROR : SnprintfAndSystem [rmdir %s] failed[%d] , errno[%d]\n" , version_path_base , nret , errno )
EIDTI( "system [%s] ok\n" , cmd )
}

Expand Down
11 changes: 10 additions & 1 deletion src/cocker/show_containers.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ int DoShow_containers( struct CockerEnvironment *cocker_env )
{
DIR *dir = NULL ;
struct dirent *dirent = NULL ;
char container_path_base[ PATH_MAX + 1 ] ;
struct stat dir_stat ;
int count ;

char container_image_file[ PATH_MAX + 1 ] ;
Expand Down Expand Up @@ -45,7 +47,14 @@ int DoShow_containers( struct CockerEnvironment *cocker_env )

if( STRCMP( dirent->d_name , == , "." ) || STRCMP( dirent->d_name , == , ".." ) )
continue;
if( dirent->d_type != DT_DIR )

if( Snprintf( container_path_base , sizeof(container_path_base) , "%s/%s" , cocker_env->containers_path_base , dirent->d_name ) == NULL )
continue;
memset( & dir_stat , 0x00 , sizeof(struct stat) );
nret = stat( container_path_base , & dir_stat ) ;
if( nret == -1 )
continue;
if( S_ISDIR(dir_stat.st_mode) )
continue;

/* image */
Expand Down
25 changes: 20 additions & 5 deletions src/cocker/show_images.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ int DoShow_images( struct CockerEnvironment *cocker_env )
struct dirent *dirent = NULL ;
DIR *dir2 = NULL ;
struct dirent *dirent2 = NULL ;
int count ;
char version_path_base[ PATH_MAX + 1 ] ;
char image_path_base[ PATH_MAX + 1 ] ;
struct stat dir_stat ;
int count ;
char version[ VERSION_LEN_MAX + 1 ] ;
char image_id[ IMAGES_ID_LEN_MAX + 1 ] ;
char image_path_base[ PATH_MAX + 1 ] ;
struct stat image_path_stat ;
struct tm image_path_modifytm ;
char image_path_modifytime_buf[ 32 + 1 ] ;
Expand All @@ -41,12 +42,19 @@ int DoShow_images( struct CockerEnvironment *cocker_env )

if( STRCMP( dirent->d_name , == , "." ) || STRCMP( dirent->d_name , == , ".." ) )
continue;
if( dirent->d_type != DT_DIR )

if( Snprintf( version_path_base , sizeof(version_path_base) , "%s/%s" , cocker_env->images_path_base , dirent->d_name ) == NULL )
continue;
memset( & dir_stat , 0x00 , sizeof(struct stat) );
nret = stat( version_path_base , & dir_stat ) ;
if( nret == -1 )
continue;

if( ! S_ISDIR(dir_stat.st_mode) )
continue;

Snprintf( image_id , sizeof(image_id) , "%s" , dirent->d_name );

Snprintf( version_path_base , sizeof(version_path_base) , "%s/%s" , cocker_env->images_path_base , image_id );
dir2 = opendir( version_path_base ) ;
while( dir2 )
{
Expand All @@ -56,7 +64,14 @@ int DoShow_images( struct CockerEnvironment *cocker_env )

if( STRCMP( dirent2->d_name , == , "." ) || STRCMP( dirent2->d_name , == , ".." ) )
continue;
if( dirent2->d_type != DT_DIR )

if( Snprintf( image_path_base , sizeof(image_path_base) , "%s/%s" , cocker_env->version_path_base , dirent2->d_name ) == NULL )
continue;
memset( & dir_stat , 0x00 , sizeof(struct stat) );
nret = stat( image_path_base , & dir_stat ) ;
if( nret == -1 )
continue;
if( ! S_ISDIR(dir_stat.st_mode) )
continue;

Snprintf( version , sizeof(version) , "%s" , dirent2->d_name );
Expand Down
20 changes: 19 additions & 1 deletion src/cocker/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ int GetMaxVersionPath( char *version_path_base , char *max_version , int max_ver
{
DIR *dir = NULL ;
struct dirent *dirent = NULL ;
char sub_path[ PATH_MAX + 1 ] ;
struct stat dir_stat ;
int max_v1 , max_v2 , max_v3 , max_v4 ;
int v1 , v2 , v3 , v4 ;
char version[ PATH_MAX + 1 ] = "" ;

int nret = 0 ;

dir = opendir( version_path_base ) ;
if( dir == NULL )
return -1;
Expand All @@ -74,7 +78,21 @@ int GetMaxVersionPath( char *version_path_base , char *max_version , int max_ver
break;
if( STRCMP( dirent->d_name , == , "." ) || STRCMP( dirent->d_name , == , ".." ) )
continue;
if( dirent->d_type != DT_DIR )

if( Snprintf( sub_path , sizeof(sub_path) , "%s/%s" , version_path_base , dirent->d_name ) == NULL )
{
closedir( dir );
return -2;
}

memset( & dir_stat , 0x00 , sizeof(struct stat) );
nret = stat( sub_path , & dir_stat ) ;
if( nret == -1 )
{
closedir( dir );
return -3;
}
if( ! S_ISDIR(dir_stat.st_mode) )
continue;

sscanf( dirent->d_name , "%d.%d.%d.%d" , & v1 , & v2 , & v3 , & v4 );
Expand Down
21 changes: 10 additions & 11 deletions src/util/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,21 +270,22 @@ static int _GetDirectorySize( char *path , int *p_directory_size )
return -2;
}

if( dirent->d_type == DT_DIR )
memset( & file_stat , 0x00 , sizeof(struct stat) );
nret = stat( sub_path , & file_stat ) ;
if( nret == -1 )
{
closedir( dir );
return -3;
}

if( S_ISDIR(file_stat.st_mode) )
{
nret = _GetDirectorySize( sub_path , p_directory_size ) ;
if( nret )
return nret;
}
else if( dirent->d_type == DT_REG )
else if( S_ISREG(file_stat.st_mode) )
{
memset( & file_stat , 0x00 , sizeof(struct stat) );
nret = stat( sub_path , & file_stat ) ;
if( nret == -1 )
{
closedir( dir );
return -3;
}
(*p_directory_size) += file_stat.st_size ;
}
}
Expand Down Expand Up @@ -316,8 +317,6 @@ int IsDirectoryEmpty( char *version_path_base )
break;
if( STRCMP( dirent->d_name , == , "." ) || STRCMP( dirent->d_name , == , ".." ) )
continue;
if( dirent->d_type != DT_DIR )
continue;

closedir( dir );
return 1;
Expand Down

0 comments on commit c55e2ca

Please sign in to comment.