Subversion Repositories SvarDOS

Rev

Rev 184 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 184 Rev 185
Line 1... Line 1...
1
/*
1
/*
2
  FDNPKG idx builder
2
  SvarDOS repo index builder
3
  Copyright (C) Mateusz Viste 2012, 2013, 2014, 2015, 2016, 2017
3
  Copyright (C) Mateusz Viste 2012-2021
4

4

5
  buildidx computes idx files for FDNPKG-compatible repositories.
5
  buildidx computes an index tsv file for the SvarDOS repository.
6
  it must be executed pointing to a directory that stores FreeDOS
6
  it must be executed pointing to a directory that stores packages (zip)
7
  packages (zip) files. buildidx will generate the index file and
7
  files. buildidx will generate the index file and save it into the package
8
  save it into the package repository.
8
  repository.
9

9

-
 
10
  13 jan 2021: removed the identification line, changed CRC32 to bsum, not creating the listing.txt file and stopped compressing index
10
  23 apr 2017: uncompressed index is no longer created, added CRC32 of zib (bin only) files, if present
11
  23 apr 2017: uncompressed index is no longer created, added CRC32 of zib (bin only) files, if present
11
  28 aug 2016: listing.txt is always written inside the repo dir (instead of inside current dir)
12
  28 aug 2016: listing.txt is always written inside the repo dir (instead of inside current dir)
12
  27 aug 2016: accepting full paths to repos (starting with /...)
13
  27 aug 2016: accepting full paths to repos (starting with /...)
13
  07 dec 2013: rewritten buildidx in ANSI C89
14
  07 dec 2013: rewritten buildidx in ANSI C89
14
  19 aug 2013: add a compressed version of the index file to repos (index.gz)
15
  19 aug 2013: add a compressed version of the index file to repos (index.gz)
Line 20... Line 21...
20
  22 sep 2012: forked 1st version from FDUPDATE builder
21
  22 sep 2012: forked 1st version from FDUPDATE builder
21
*/
22
*/
22
 
23
 
23
#include <errno.h>
24
#include <errno.h>
24
#include <stdio.h>   /* fopen, fclose... */
25
#include <stdio.h>   /* fopen, fclose... */
-
 
26
#include <stdint.h>
25
#include <stdlib.h>  /* system() */
27
#include <stdlib.h>  /* system() */
26
#include <string.h>  /* strcasecmp() */
28
#include <string.h>  /* strcasecmp() */
27
#include <time.h>    /* time(), ctime() */
29
#include <time.h>    /* time(), ctime() */
28
#include <unistd.h>  /* read() */
30
#include <unistd.h>  /* read() */
29
#include <dirent.h>
31
#include <dirent.h>
30
#include <sys/types.h>
32
#include <sys/types.h>
31
 
33
 
32
#define pVer "2017-04-23"
34
#define pVer "2021-01-13"
33
 
35
 
34
 
36
 
35
#include "crc32lib.c"
-
 
36
 
-
 
37
 
-
 
38
/* computes the CRC32 of file and returns it. returns 0 on error. */
37
/* computes the BSD sum of a file and returns it. returns 0 on error. */
39
static unsigned long file2crc(char *filename) {
38
static uint16_t file2bsum(char *filename) {
40
  unsigned long result;
39
  uint16_t result = 0;
41
  unsigned char buff[16 * 1024];
40
  unsigned char buff[1024 * 1024];
42
  int buffread;
41
  size_t i, buffread;
43
  FILE *fd;
42
  FILE *fd;
44
  fd = fopen(filename, "rb");
43
  fd = fopen(filename, "rb");
45
  if (fd == NULL) return(0);
44
  if (fd == NULL) return(0);
46
  result = crc32_init();
-
 
47
  while ((buffread = fread(buff, 1, sizeof(buff), fd)) > 0) {
45
  while ((buffread = fread(buff, 1, sizeof(buff), fd)) > 0) {
-
 
46
    for (i = 0; i < buffread; i++) {
-
 
47
      /* rotr */
48
    if (buffread > 0) crc32_feed(&result, buff, buffread);
48
      result = (result >> 1) | (result << 15);
-
 
49
      /* */
-
 
50
      result += buff[i];
-
 
51
    }
49
  }
52
  }
50
  crc32_finish(&result);
-
 
51
  fclose(fd);
53
  fclose(fd);
52
  if (buffread < 0) puts("read() error!");
-
 
53
  return(result);
54
  return(result);
54
}
55
}
55
 
56
 
56
 
57
 
57
static void trim(char *str) {
58
static void trim(char *str) {
Line 148... Line 149...
148
       to char", hence the following cast plus dereference */
149
       to char", hence the following cast plus dereference */
149
   return(strcasecmp(* (char * const *) p1, * (char * const *) p2));
150
   return(strcasecmp(* (char * const *) p1, * (char * const *) p2));
150
}
151
}
151
 
152
 
152
 
153
 
153
static char *getlastdir(char *s) {
-
 
154
  char *r = s;
-
 
155
  for (; *s != 0; s++) {
-
 
156
    if ((*s == '/') && (s[1] != 0)) r = s+1;
-
 
157
  }
-
 
158
  return(r);
-
 
159
}
-
 
160
 
-
 
161
 
-
 
162
static void GenIndexes(char *repodir) {
154
static void GenIndexes(char *repodir) {
163
  char *LsmFileList[4096];
155
  char *LsmFileList[4096];
164
  char tmpbuf[64];
156
  char tmpbuf[64];
165
  char *LsmFile, LSMpackage[64], LSMtitle[128], LSMversion[128], LSMdescription[1024];
157
  char *LsmFile, LSMpackage[64], LSMtitle[128], LSMversion[128], LSMdescription[1024];
166
  int LsmCount = 0, x;
158
  int LsmCount = 0, x;
167
  FILE *idx, *listing;
159
  FILE *idx;
168
  time_t curtime;
-
 
169
  DIR *dir;
160
  DIR *dir;
170
  struct dirent *diritem;
161
  struct dirent *diritem;
171
 
162
 
172
  dir = opendir("appinfo");
163
  dir = opendir("appinfo");
173
  if (dir == NULL) {
164
  if (dir == NULL) {
Line 189... Line 180...
189
 
180
 
190
  /* sort the entries */
181
  /* sort the entries */
191
  qsort(&LsmFileList[0], LsmCount, sizeof(char *), cmpstring);
182
  qsort(&LsmFileList[0], LsmCount, sizeof(char *), cmpstring);
192
 
183
 
193
  /* Create the index file */
184
  /* Create the index file */
194
  sprintf(tmpbuf, "%s/index.lst", repodir);
185
  sprintf(tmpbuf, "%s/index.tsv", repodir);
195
  idx = fopen(tmpbuf, "wb");
186
  idx = fopen(tmpbuf, "wb");
196
  sprintf(tmpbuf, "%s/listing.txt", repodir);
-
 
197
  listing = fopen(tmpbuf, "wb");
-
 
198
 
-
 
199
  /* Write out the index header */
-
 
200
  curtime = time(NULL);
-
 
201
  fprintf(idx, "FD-REPOv1\t'%s' built at unix time %ld, lists %d packages\n", getlastdir(repodir), curtime, LsmCount);
-
 
202
  fprintf(listing, "\n");
-
 
203
  fprintf(listing, "*** Repository '%s' - build time: %s\n", getlastdir(repodir), ctime(&curtime));
-
 
204
 
187
 
205
  /* Read every LSM */
188
  /* Read every LSM */
206
  for (x = 0; x < LsmCount; x++) {
189
  for (x = 0; x < LsmCount; x++) {
207
    unsigned long crc32, crc32zib;
190
    uint16_t bsum;
208
    LsmFile = LsmFileList[x];
191
    LsmFile = LsmFileList[x];
209
    sprintf(LSMpackage, "%s", LsmFile);
192
    sprintf(LSMpackage, "%s", LsmFile);
210
    LSMpackage[strlen(LSMpackage) - 4] = 0;
193
    LSMpackage[strlen(LSMpackage) - 4] = 0;
211
 
194
 
212
    /* compute the CRC of the zip package, and its zib version, if present */
195
    /* compute the BSD sum of the zip package */
213
    sprintf(tmpbuf, "%s/%s.zip", repodir, LSMpackage);
196
    sprintf(tmpbuf, "%s/%s.zip", repodir, LSMpackage);
214
    crc32 = file2crc(tmpbuf);
197
    bsum = file2bsum(tmpbuf);
215
    sprintf(tmpbuf, "%s/%s.zib", repodir, LSMpackage);
-
 
216
    crc32zib = file2crc(tmpbuf);
-
 
217
 
198
 
218
    if (crc32zib != 0) {
-
 
219
      printf("Processing %s... CRC %08lX (zib: %08lX)\n", LsmFile, crc32, crc32zib);
-
 
220
    } else {
-
 
221
      printf("Processing %s... CRC %08lX\n", LsmFile, crc32);
199
    printf("Processing %s... BSUM %04X\n", LsmFile, bsum);
222
    }
-
 
223
 
200
 
224
    sprintf(tmpbuf, "appinfo/%s", LsmFile);
201
    sprintf(tmpbuf, "appinfo/%s", LsmFile);
225
    readlsm(tmpbuf, LSMversion, LSMtitle, LSMdescription);
202
    readlsm(tmpbuf, LSMversion, LSMtitle, LSMdescription);
226
 
203
 
227
    if (strlen(LSMpackage) > 8) printf("Warning: %s.zip is not in 8.3 format!\n", LSMpackage);
204
    if (strlen(LSMpackage) > 8) printf("Warning: %s.zip is not in 8.3 format!\n", LSMpackage);
228
    if (LSMtitle[0] == 0) printf("Warning: no LSM title for %s.zip\n", LSMpackage);
205
    if (LSMtitle[0] == 0) printf("Warning: no LSM title for %s.zip\n", LSMpackage);
229
    if (LSMversion[0] == 0) printf("Warning: no LSM version for %s.zip!\n", LSMpackage);
206
    if (LSMversion[0] == 0) printf("Warning: no LSM version for %s.zip!\n", LSMpackage);
230
    if (LSMdescription[0] == 0) printf("Warning: no LSM description for %s.zip!\n", LSMpackage);
207
    if (LSMdescription[0] == 0) printf("Warning: no LSM description for %s.zip!\n", LSMpackage);
231
    if (crc32zib != 0) {
-
 
232
      fprintf(idx, "%s\t%s\t%s\t%08lX\t%08lX\n", LSMpackage, LSMversion, LSMdescription, crc32, crc32zib);
-
 
233
    } else {
-
 
234
      fprintf(idx, "%s\t%s\t%s\t%08lX\t\n", LSMpackage, LSMversion, LSMdescription, crc32);
208
    fprintf(idx, "%s\t%s\t%s\t%u\n", LSMpackage, LSMversion, LSMdescription, bsum);
235
    }
-
 
236
    fprintf(listing, "%s %s - %s\n", LSMpackage, LSMversion, LSMdescription);
-
 
237
  }
209
  }
238
  fprintf(listing, "\n");
-
 
239
  fclose(idx);
210
  fclose(idx);
240
  fclose(listing);
-
 
241
  /* create the compressed version of the index file using gzip */
-
 
242
  sprintf(tmpbuf, "gzip -9 < %s/index.lst > %s/index.gz", repodir, repodir);
-
 
243
  system(tmpbuf);
-
 
244
  /* remove the uncompressed version */
-
 
245
  sprintf(tmpbuf, "%s/index.lst", repodir);
-
 
246
  unlink(tmpbuf);
-
 
247
  printf("%d packages found.\n", LsmCount);
211
  printf("%d packages found.\n", LsmCount);
248
}
212
}
249
 
213
 
250
 
214
 
251
 
215