File: rpm.c

package info (click to toggle)
ytree 1.94-1.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 836 kB
  • ctags: 1,510
  • sloc: ansic: 15,271; makefile: 208
file content (167 lines) | stat: -rw-r--r-- 3,466 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/***************************************************************************
 *
 * $Header: /usr/local/cvsroot/utils/ytree/rpm.c,v 1.3 2000/05/20 20:41:11 werner Exp $
 *
 * Read RPM-Files
 * Currently no extraction supported
 *
 ***************************************************************************/


#include "ytree.h"



static int GetStatFromRPM(char *rpm_line, char *name, struct stat *stat);



/* Dateibaum aus RPM-Listing lesen */
/*---------------------------------*/

int ReadTreeFromRPM(DirEntry *dir_entry, FILE *f)
{ 
  char rpm_line[RPM_LINE_LENGTH + 1];
  char path_name[PATH_LENGTH +1];
  struct stat stat;
  BOOL   dir_flag = FALSE;

  *dir_entry->name = '\0';

  while( fgets( rpm_line, RPM_LINE_LENGTH, f ) != NULL )
  {
    /* \n loeschen */
    /*-------------*/

    rpm_line[ strlen( rpm_line ) - 1 ] = '\0';

    if( GetStatFromRPM( rpm_line, path_name, &stat ) )
    {
      (void) sprintf( message, "unknown rpminfo*%s", rpm_line );
      MESSAGE( message );
    }
    else
    {
      if( (path_name[strlen( path_name ) - 1] == FILE_SEPARATOR_CHAR) ||
	  !strcmp( path_name, "." ) || S_ISDIR(stat.st_mode)
	)
      {
        /* Directory */
        /*-----------*/
        
#ifdef DEBUG
  fprintf( stderr, "DIR: %s\n", path_name );
#endif

	if( strcmp( path_name, "./" ) )
	{
	  /* "./" wird ignoriert */
	  /*---------------------*/

          (void) TryInsertArchiveDirEntry( dir_entry, path_name, &stat );
	  DisplayDiskStatistic();
	  doupdate();
	}
      }
      else
      {
        /* File */
        /*------*/
  
#ifdef DEBUG
  fprintf( stderr, "FILE: \"%s\"\n", path_name );
#endif
        (void) InsertArchiveFileEntry( dir_entry, path_name, &stat );
      }
    }
  }
  
  if( dir_flag == FALSE )
  {
    statistic.disk_total_directories++;
    (void) memset( (char *) &dir_entry->stat_struct, 0, sizeof( struct stat ) );
    dir_entry->stat_struct.st_mode = S_IFDIR;
  }
  return( MinimizeArchiveTree( dir_entry ) );
}





static int GetStatFromRPM(char *rpm_line, char *name, struct stat *stat)
{
  char *t, *old;
  int  id;


  (void) memset( stat, 0, sizeof( struct stat ) );

  stat->st_nlink = 1;

  t = Strtok_r( rpm_line, " \t", &old ); if( t == NULL ) return( -1 );

  /* Dateiname */
  /*-----------*/

  (void) strcpy( name, t );
  t = Strtok_r( NULL, " \t", &old ); if( t == NULL ) return( -1 );

  /* Dateilaenge */
  /*-------------*/

  if( !isdigit( *t ) ) return( -1 );
  stat->st_size = AtoLL( t );
  t = Strtok_r( NULL, " \t", &old ); if( t == NULL ) return( -1 );

  /* M-Datum */
  /*---------*/

  stat->st_atime = 0;
  stat->st_ctime = 0;

  stat->st_mtime = atoi( t );
  t = Strtok_r( NULL, " \t", &old ); if( t == NULL ) return( -1 );
  
  /* M5 */
  if(strlen(t) > 20) {
    t = Strtok_r( NULL, " \t/", &old ); if( t == NULL ) return( -1 );
  }

  /* Attribute */
  /*-----------*/

  stat->st_mode = strtoul(t, NULL, 8);
  t = Strtok_r( NULL, " \t/", &old ); if( t == NULL ) return( -1 );


  /* Owner */
  /*-------*/

  id = GetPasswdUid( t );
  if( id == -1 ) id = atoi( t );
  stat->st_uid = (unsigned) id;

  t = Strtok_r( NULL, " \t", &old ); if( t == NULL ) return( -1 );

  /* Group */
  /*-------*/

  id = GetGroupId( t );
  if( id == -1 ) id = atoi( t );
  stat->st_gid = (unsigned) id;
  

  if( S_ISLNK( stat->st_mode ) )
  {
    /* Symbolischer Link */
    /*-------------------*/

    t = "symlink";
    (void) strcpy( &name[ strlen( name ) + 1 ], t );
  }

  return( 0 );
}