Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 185 → Rev 184

/buildidx/buildidx.c
1,13 → 1,12
/*
SvarDOS repo index builder
Copyright (C) Mateusz Viste 2012-2021
FDNPKG idx builder
Copyright (C) Mateusz Viste 2012, 2013, 2014, 2015, 2016, 2017
 
buildidx computes an index tsv file for the SvarDOS repository.
it must be executed pointing to a directory that stores packages (zip)
files. buildidx will generate the index file and save it into the package
repository.
buildidx computes idx files for FDNPKG-compatible repositories.
it must be executed pointing to a directory that stores FreeDOS
packages (zip) files. buildidx will generate the index file and
save it into the package repository.
 
13 jan 2021: removed the identification line, changed CRC32 to bsum, not creating the listing.txt file and stopped compressing index
23 apr 2017: uncompressed index is no longer created, added CRC32 of zib (bin only) files, if present
28 aug 2016: listing.txt is always written inside the repo dir (instead of inside current dir)
27 aug 2016: accepting full paths to repos (starting with /...)
23,7 → 22,6
 
#include <errno.h>
#include <stdio.h> /* fopen, fclose... */
#include <stdint.h>
#include <stdlib.h> /* system() */
#include <string.h> /* strcasecmp() */
#include <time.h> /* time(), ctime() */
31,26 → 29,27
#include <dirent.h>
#include <sys/types.h>
 
#define pVer "2021-01-13"
#define pVer "2017-04-23"
 
 
/* computes the BSD sum of a file and returns it. returns 0 on error. */
static uint16_t file2bsum(char *filename) {
uint16_t result = 0;
unsigned char buff[1024 * 1024];
size_t i, buffread;
#include "crc32lib.c"
 
 
/* computes the CRC32 of file and returns it. returns 0 on error. */
static unsigned long file2crc(char *filename) {
unsigned long result;
unsigned char buff[16 * 1024];
int buffread;
FILE *fd;
fd = fopen(filename, "rb");
if (fd == NULL) return(0);
result = crc32_init();
while ((buffread = fread(buff, 1, sizeof(buff), fd)) > 0) {
for (i = 0; i < buffread; i++) {
/* rotr */
result = (result >> 1) | (result << 15);
/* */
result += buff[i];
}
if (buffread > 0) crc32_feed(&result, buff, buffread);
}
crc32_finish(&result);
fclose(fd);
if (buffread < 0) puts("read() error!");
return(result);
}
 
151,12 → 150,22
}
 
 
static char *getlastdir(char *s) {
char *r = s;
for (; *s != 0; s++) {
if ((*s == '/') && (s[1] != 0)) r = s+1;
}
return(r);
}
 
 
static void GenIndexes(char *repodir) {
char *LsmFileList[4096];
char tmpbuf[64];
char *LsmFile, LSMpackage[64], LSMtitle[128], LSMversion[128], LSMdescription[1024];
int LsmCount = 0, x;
FILE *idx;
FILE *idx, *listing;
time_t curtime;
DIR *dir;
struct dirent *diritem;
 
182,21 → 191,35
qsort(&LsmFileList[0], LsmCount, sizeof(char *), cmpstring);
 
/* Create the index file */
sprintf(tmpbuf, "%s/index.tsv", repodir);
sprintf(tmpbuf, "%s/index.lst", repodir);
idx = fopen(tmpbuf, "wb");
sprintf(tmpbuf, "%s/listing.txt", repodir);
listing = fopen(tmpbuf, "wb");
 
/* Write out the index header */
curtime = time(NULL);
fprintf(idx, "FD-REPOv1\t'%s' built at unix time %ld, lists %d packages\n", getlastdir(repodir), curtime, LsmCount);
fprintf(listing, "\n");
fprintf(listing, "*** Repository '%s' - build time: %s\n", getlastdir(repodir), ctime(&curtime));
 
/* Read every LSM */
for (x = 0; x < LsmCount; x++) {
uint16_t bsum;
unsigned long crc32, crc32zib;
LsmFile = LsmFileList[x];
sprintf(LSMpackage, "%s", LsmFile);
LSMpackage[strlen(LSMpackage) - 4] = 0;
 
/* compute the BSD sum of the zip package */
/* compute the CRC of the zip package, and its zib version, if present */
sprintf(tmpbuf, "%s/%s.zip", repodir, LSMpackage);
bsum = file2bsum(tmpbuf);
crc32 = file2crc(tmpbuf);
sprintf(tmpbuf, "%s/%s.zib", repodir, LSMpackage);
crc32zib = file2crc(tmpbuf);
 
printf("Processing %s... BSUM %04X\n", LsmFile, bsum);
if (crc32zib != 0) {
printf("Processing %s... CRC %08lX (zib: %08lX)\n", LsmFile, crc32, crc32zib);
} else {
printf("Processing %s... CRC %08lX\n", LsmFile, crc32);
}
 
sprintf(tmpbuf, "appinfo/%s", LsmFile);
readlsm(tmpbuf, LSMversion, LSMtitle, LSMdescription);
205,9 → 228,22
if (LSMtitle[0] == 0) printf("Warning: no LSM title for %s.zip\n", LSMpackage);
if (LSMversion[0] == 0) printf("Warning: no LSM version for %s.zip!\n", LSMpackage);
if (LSMdescription[0] == 0) printf("Warning: no LSM description for %s.zip!\n", LSMpackage);
fprintf(idx, "%s\t%s\t%s\t%u\n", LSMpackage, LSMversion, LSMdescription, bsum);
if (crc32zib != 0) {
fprintf(idx, "%s\t%s\t%s\t%08lX\t%08lX\n", LSMpackage, LSMversion, LSMdescription, crc32, crc32zib);
} else {
fprintf(idx, "%s\t%s\t%s\t%08lX\t\n", LSMpackage, LSMversion, LSMdescription, crc32);
}
fprintf(listing, "%s %s - %s\n", LSMpackage, LSMversion, LSMdescription);
}
fprintf(listing, "\n");
fclose(idx);
fclose(listing);
/* create the compressed version of the index file using gzip */
sprintf(tmpbuf, "gzip -9 < %s/index.lst > %s/index.gz", repodir, repodir);
system(tmpbuf);
/* remove the uncompressed version */
sprintf(tmpbuf, "%s/index.lst", repodir);
unlink(tmpbuf);
printf("%d packages found.\n", LsmCount);
}