Upgraded files database strcuture
This commit is contained in:
174
mbfido/addbbs.c
174
mbfido/addbbs.c
@@ -48,13 +48,13 @@ extern int tic_imp;
|
||||
*/
|
||||
int Add_BBS()
|
||||
{
|
||||
struct FILERecord frec;
|
||||
int rc, i, Insert, Done = FALSE, Found = FALSE;
|
||||
char fdbname[PATH_MAX], fdbtemp[PATH_MAX];
|
||||
char temp1[PATH_MAX], temp2[PATH_MAX], *fname, *lname, *p;
|
||||
FILE *fdb, *fdt;
|
||||
int Keep = 0, DidDelete = FALSE;
|
||||
fd_list *fdl = NULL;
|
||||
struct FILE_recordhdr frechdr;
|
||||
struct FILE_record frec;
|
||||
int rc, i, Insert, Done = FALSE, Found = FALSE, Keep = 0, DidDelete = FALSE;
|
||||
char fdbname[PATH_MAX], fdbtemp[PATH_MAX];
|
||||
char temp1[PATH_MAX], temp2[PATH_MAX], *fname, *lname, *p;
|
||||
FILE *fp, *fdt;
|
||||
fd_list *fdl = NULL;
|
||||
|
||||
/*
|
||||
* First check for an existing record with the same filename,
|
||||
@@ -62,20 +62,21 @@ int Add_BBS()
|
||||
* prevent for example allfiles.zip to get a new record everytime
|
||||
* and thus the download counters will be reset after a new update.
|
||||
*/
|
||||
sprintf(fdbname, "%s/fdb/fdb%ld.data", getenv("MBSE_ROOT"), tic.FileArea);
|
||||
if ((fdb = fopen(fdbname, "r+")) != NULL) {
|
||||
while (fread(&frec, sizeof(frec), 1, fdb) == 1) {
|
||||
sprintf(fdbname, "%s/fdb/file%ld.data", getenv("MBSE_ROOT"), tic.FileArea);
|
||||
if ((fp = fopen(fdbname, "r+")) != NULL) {
|
||||
fread(&frechdr, sizeof(frechdr), 1, fp);
|
||||
while (fread(&frec, frechdr.recsize, 1, fp) == 1) {
|
||||
if (strcmp(frec.Name, TIC.NewFile) == 0) {
|
||||
sprintf(temp1, "%s/%s", TIC.Inbound, TIC.NewFile);
|
||||
sprintf(temp2, "%s/%s", TIC.BBSpath, TIC.NewFile);
|
||||
mkdirs(temp2, 0755);
|
||||
if ((rc = file_cp(temp1, temp2))) {
|
||||
WriteError("Copy to %s failed: %s", temp2, strerror(rc));
|
||||
fclose(fdb);
|
||||
fclose(fp);
|
||||
return FALSE;
|
||||
}
|
||||
chmod(temp2, 0644);
|
||||
frec.TicAreaCRC = StringCRC32(TIC.TicIn.Area);
|
||||
strncpy(frec.TicArea, TIC.TicIn.Area, sizeof(frec.TicArea) -1);
|
||||
frec.Size = TIC.FileSize;
|
||||
frec.Crc32 = TIC.Crc_Int;
|
||||
frec.Announced = TRUE;
|
||||
@@ -88,16 +89,16 @@ int Add_BBS()
|
||||
}
|
||||
if (strlen(TIC.TicIn.Magic))
|
||||
sprintf(frec.Desc[i], "Magic Request: %s", TIC.TicIn.Magic);
|
||||
fseek(fdb, 0 - sizeof(frec), SEEK_CUR);
|
||||
fwrite(&frec, sizeof(frec), 1, fdb);
|
||||
fclose(fdb);
|
||||
fseek(fp, 0 - sizeof(frec), SEEK_CUR);
|
||||
fwrite(&frec, sizeof(frec), 1, fp);
|
||||
fclose(fp);
|
||||
tic_imp++;
|
||||
if ((i = file_rm(temp1)))
|
||||
WriteError("file_rm(%s): %s", temp1, strerror(i));
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
fclose(fdb);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +117,7 @@ int Add_BBS()
|
||||
for (i = 0; i < strlen(frec.LName); i++)
|
||||
frec.LName[i] = tolower(frec.LName[i]);
|
||||
}
|
||||
frec.TicAreaCRC = StringCRC32(TIC.TicIn.Area);
|
||||
strncpy(frec.TicArea, TIC.TicIn.Area, 20);
|
||||
frec.Size = TIC.FileSize;
|
||||
frec.Crc32 = TIC.Crc_Int;
|
||||
frec.Announced = TRUE;
|
||||
@@ -128,8 +129,10 @@ int Add_BBS()
|
||||
if (i == 24)
|
||||
break;
|
||||
}
|
||||
if (strlen(TIC.TicIn.Magic))
|
||||
if (strlen(TIC.TicIn.Magic)) {
|
||||
strncpy(frec.Magic, TIC.TicIn.Magic, sizeof(frec.Magic) -1);
|
||||
sprintf(frec.Desc[i], "Magic Request: %s", TIC.TicIn.Magic);
|
||||
}
|
||||
|
||||
sprintf(temp1, "%s/%s", TIC.Inbound, TIC.NewFile);
|
||||
sprintf(temp2, "%s/%s", TIC.BBSpath, frec.Name);
|
||||
@@ -167,15 +170,19 @@ int Add_BBS()
|
||||
}
|
||||
free(lname);
|
||||
|
||||
sprintf(fdbtemp, "%s/fdb/fdb%ld.temp", getenv("MBSE_ROOT"), tic.FileArea);
|
||||
|
||||
if ((fdb = fopen(fdbname, "r+")) == NULL) {
|
||||
sprintf(fdbtemp, "%s/fdb/file%ld.temp", getenv("MBSE_ROOT"), tic.FileArea);
|
||||
if ((fp = fopen(fdbname, "r+")) == NULL) {
|
||||
Syslog('+', "Fdb %s doesn't exist, creating", fdbname);
|
||||
if ((fdb = fopen(fdbname, "a+")) == NULL) {
|
||||
if ((fp = fopen(fdbname, "a+")) == NULL) {
|
||||
WriteError("$Can't create %s", fdbname);
|
||||
return FALSE;
|
||||
}
|
||||
frechdr.hdrsize = sizeof(frechdr);
|
||||
frechdr.recsize = sizeof(frec);
|
||||
fwrite(&frechdr, sizeof(frechdr), 1, fp);
|
||||
chmod(fdbname, 0660);
|
||||
} else {
|
||||
fread(&frechdr, sizeof(frechdr), 1, fp);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -183,10 +190,10 @@ int Add_BBS()
|
||||
* one and leave immediatly, keepnum and replace have no
|
||||
* use at this point.
|
||||
*/
|
||||
fseek(fdb, 0, SEEK_END);
|
||||
if (ftell(fdb) == 0) {
|
||||
fwrite(&frec, sizeof(frec), 1, fdb);
|
||||
fclose(fdb);
|
||||
fseek(fp, 0, SEEK_END);
|
||||
if (ftell(fp) == frechdr.hdrsize) {
|
||||
fwrite(&frec, sizeof(frec), 1, fp);
|
||||
fclose(fp);
|
||||
file_rm(temp1);
|
||||
tic_imp++;
|
||||
return TRUE;
|
||||
@@ -197,17 +204,17 @@ int Add_BBS()
|
||||
* which position to insert the new file, replace or
|
||||
* remove the old entry.
|
||||
*/
|
||||
fseek(fdb, 0, SEEK_SET);
|
||||
fseek(fp, frechdr.hdrsize, SEEK_SET);
|
||||
|
||||
Insert = 0;
|
||||
do {
|
||||
if (fread(&file, sizeof(file), 1, fdb) != 1)
|
||||
if (fread(&fdb, frechdr.recsize, 1, fp) != 1)
|
||||
Done = TRUE;
|
||||
if (!Done) {
|
||||
if (strcmp(frec.LName, file.LName) == 0) {
|
||||
if (strcmp(frec.LName, fdb.LName) == 0) {
|
||||
Found = TRUE;
|
||||
Insert++;
|
||||
} else if (strcmp(frec.LName, file.LName) < 0)
|
||||
} else if (strcmp(frec.LName, fdb.LName) < 0)
|
||||
Found = TRUE;
|
||||
else
|
||||
Insert++;
|
||||
@@ -217,53 +224,54 @@ int Add_BBS()
|
||||
if (Found) {
|
||||
if ((fdt = fopen(fdbtemp, "a+")) == NULL) {
|
||||
WriteError("$Can't create %s", fdbtemp);
|
||||
fclose(fdb);
|
||||
fclose(fp);
|
||||
return FALSE;
|
||||
}
|
||||
fwrite(&frechdr, frechdr.hdrsize, 1, fdt);
|
||||
|
||||
fseek(fdb, 0, SEEK_SET);
|
||||
fseek(fp, frechdr.hdrsize, SEEK_SET);
|
||||
/*
|
||||
* Copy entries till the insert point.
|
||||
*/
|
||||
for (i = 0; i < Insert; i++) {
|
||||
fread(&file, sizeof(file), 1, fdb);
|
||||
fread(&fdb, frechdr.recsize, 1, fp);
|
||||
/*
|
||||
* Check if we are importing a file with the same
|
||||
* name, if so, don't copy the original database
|
||||
* record. The file is also overwritten.
|
||||
*/
|
||||
if (strcmp(file.LName, frec.LName) != 0)
|
||||
fwrite(&file, sizeof(file), 1, fdt);
|
||||
if (strcmp(fdb.LName, frec.LName) != 0)
|
||||
fwrite(&fdb, frechdr.recsize, 1, fdt);
|
||||
}
|
||||
|
||||
if (area.AddAlpha) {
|
||||
/*
|
||||
* Insert the new entry
|
||||
*/
|
||||
fwrite(&frec, sizeof(frec), 1, fdt);
|
||||
fwrite(&frec, frechdr.recsize, 1, fdt);
|
||||
}
|
||||
|
||||
/*
|
||||
* Append the rest of the entries.
|
||||
*/
|
||||
while (fread(&file, sizeof(file), 1, fdb) == 1) {
|
||||
while (fread(&fdb, frechdr.recsize, 1, fp) == 1) {
|
||||
/*
|
||||
* Check if we find a file with the same name,
|
||||
* then we skip the record what was origionaly
|
||||
* in the database record.
|
||||
*/
|
||||
if (strcmp(file.LName, frec.LName) != 0)
|
||||
fwrite(&file, sizeof(file), 1, fdt);
|
||||
if (strcmp(fdb.LName, frec.LName) != 0)
|
||||
fwrite(&fdb, frechdr.recsize, 1, fdt);
|
||||
}
|
||||
|
||||
if (!area.AddAlpha) {
|
||||
/*
|
||||
* Append the new entry
|
||||
*/
|
||||
fwrite(&frec, sizeof(frec), 1, fdt);
|
||||
fwrite(&frec, frechdr.recsize, 1, fdt);
|
||||
}
|
||||
fclose(fdt);
|
||||
fclose(fdb);
|
||||
fclose(fp);
|
||||
|
||||
/*
|
||||
* Now make the changes for real.
|
||||
@@ -280,9 +288,9 @@ int Add_BBS()
|
||||
/*
|
||||
* Append the new entry
|
||||
*/
|
||||
fseek(fdb, 0, SEEK_END);
|
||||
fwrite(&frec, sizeof(frec), 1, fdb);
|
||||
fclose(fdb);
|
||||
fseek(fp, 0, SEEK_END);
|
||||
fwrite(&frec, frechdr.recsize, 1, fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -297,28 +305,30 @@ int Add_BBS()
|
||||
if ((strlen(TIC.TicIn.Replace)) && (tic.Replace)) {
|
||||
Syslog('f', "Must Replace: %s", TIC.TicIn.Replace);
|
||||
|
||||
if ((fdb = fopen(fdbname, "r+")) != NULL) {
|
||||
if ((fp = fopen(fdbname, "r+")) != NULL) {
|
||||
|
||||
while (fread(&file, sizeof(file), 1, fdb) == 1) {
|
||||
if (strlen(file.LName) == strlen(frec.LName)) {
|
||||
fread(&fdbhdr, sizeof(fdbhdr), 1, fp);
|
||||
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, fp) == 1) {
|
||||
if (strlen(fdb.LName) == strlen(frec.LName)) {
|
||||
// FIXME: Search must be based on a reg_exp search
|
||||
if (strcasecmp(file.LName, frec.LName) != 0) {
|
||||
if (strcasecmp(fdb.LName, frec.LName) != 0) {
|
||||
Found = TRUE;
|
||||
for (i = 0; i < strlen(frec.LName); i++) {
|
||||
if ((TIC.TicIn.Replace[i] != '?') && (toupper(TIC.TicIn.Replace[i]) != toupper(file.LName[i])))
|
||||
if ((TIC.TicIn.Replace[i] != '?') && (toupper(TIC.TicIn.Replace[i]) != toupper(fdb.LName[i])))
|
||||
Found = FALSE;
|
||||
}
|
||||
if (Found) {
|
||||
Syslog('+', "Replace: Deleting: %s", file.LName);
|
||||
file.Deleted = TRUE;
|
||||
fseek(fdb, - sizeof(file), SEEK_CUR);
|
||||
fwrite(&file, sizeof(file), 1, fdb);
|
||||
Syslog('+', "Replace: Deleting: %s", fdb.LName);
|
||||
fdb.Deleted = TRUE;
|
||||
fseek(fp , - fdbhdr.recsize, SEEK_CUR);
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, fp);
|
||||
DidDelete = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fdb);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,27 +336,29 @@ int Add_BBS()
|
||||
* Handle the Keep number of files option
|
||||
*/
|
||||
if (TIC.KeepNum) {
|
||||
if ((fdb = fopen(fdbname, "r")) != NULL) {
|
||||
if ((fp = fopen(fdbname, "r")) != NULL) {
|
||||
|
||||
while (fread(&file, sizeof(file), 1, fdb) == 1) {
|
||||
fread(&fdbhdr, sizeof(fdbhdr), 1, fp);
|
||||
|
||||
if ((strlen(file.LName) == strlen(frec.LName)) && (!file.Deleted)) {
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, fp) == 1) {
|
||||
|
||||
if ((strlen(fdb.LName) == strlen(frec.LName)) && (!fdb.Deleted)) {
|
||||
Found = TRUE;
|
||||
|
||||
for (i = 0; i < strlen(file.LName); i++) {
|
||||
for (i = 0; i < strlen(fdb.LName); i++) {
|
||||
if ((frec.LName[i] < '0') || (frec.LName[i] > '9')) {
|
||||
if (frec.LName[i] != file.LName[i]) {
|
||||
if (frec.LName[i] != fdb.LName[i]) {
|
||||
Found = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Found) {
|
||||
Keep++;
|
||||
fill_fdlist(&fdl, file.LName, file.UploadDate);
|
||||
fill_fdlist(&fdl, fdb.LName, fdb.UploadDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fdb);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -355,22 +367,24 @@ int Add_BBS()
|
||||
if (Keep > TIC.KeepNum) {
|
||||
sort_fdlist(&fdl);
|
||||
|
||||
if ((fdb = fopen(fdbname, "r+")) != NULL) {
|
||||
if ((fp = fopen(fdbname, "r+")) != NULL) {
|
||||
fread(&fdbhdr, sizeof(fdbhdr), 1, fp);
|
||||
|
||||
for (i = 0; i < (Keep - TIC.KeepNum); i++) {
|
||||
fname = pull_fdlist(&fdl);
|
||||
fseek(fdb, 0, SEEK_SET);
|
||||
fseek(fp, fdbhdr.hdrsize, SEEK_SET);
|
||||
|
||||
while (fread(&file, sizeof(file), 1, fdb) == 1) {
|
||||
if (strcmp(file.LName, fname) == 0) {
|
||||
Syslog('+', "Keep %d files, deleting: %s", TIC.KeepNum, file.LName);
|
||||
file.Deleted = TRUE;
|
||||
fseek(fdb, - sizeof(file), SEEK_CUR);
|
||||
fwrite(&file, sizeof(file), 1, fdb);
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, fp) == 1) {
|
||||
if (strcmp(fdb.LName, fname) == 0) {
|
||||
Syslog('+', "Keep %d files, deleting: %s", TIC.KeepNum, fdb.LName);
|
||||
fdb.Deleted = TRUE;
|
||||
fseek(fp , - fdbhdr.recsize, SEEK_CUR);
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, fp);
|
||||
DidDelete = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fdb);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
tidy_fdlist(&fdl);
|
||||
@@ -381,20 +395,24 @@ int Add_BBS()
|
||||
* database.
|
||||
*/
|
||||
if (DidDelete) {
|
||||
if ((fdb = fopen(fdbname, "r")) != NULL) {
|
||||
if ((fp = fopen(fdbname, "r")) != NULL) {
|
||||
fread(&fdbhdr, sizeof(fdbhdr), 1, fp);
|
||||
if ((fdt = fopen(fdbtemp, "a+")) != NULL) {
|
||||
while (fread(&file, sizeof(file), 1, fdb) == 1)
|
||||
if (!file.Deleted)
|
||||
fwrite(&file, sizeof(file), 1, fdt);
|
||||
fwrite(&fdbhdr, fdbhdr.hdrsize, 1, fdt);
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, fp) == 1)
|
||||
if (!fdb.Deleted)
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, fdt);
|
||||
else {
|
||||
sprintf(temp2, "%s/%s", area.Path, file.LName);
|
||||
sprintf(temp2, "%s/%s", area.Path, fdb.LName);
|
||||
if (unlink(temp2) != 0)
|
||||
WriteError("$Can't unlink file %s", temp2);
|
||||
sprintf(temp2, "%s/%s", area.Path, file.Name);
|
||||
sprintf(temp2, "%s/%s", area.Path, fdb.Name);
|
||||
if (unlink(temp2) != 0)
|
||||
WriteError("$Can't unlink file %s", temp2);
|
||||
sprintf(temp2, "%s/.%s", area.Path, fdb.Name);
|
||||
unlink(temp2); /* Thumbnail, no logging if there is an error */
|
||||
}
|
||||
fclose(fdb);
|
||||
fclose(fp);
|
||||
fclose(fdt);
|
||||
if (unlink(fdbname) == 0) {
|
||||
rename(fdbtemp, fdbname);
|
||||
@@ -403,7 +421,7 @@ int Add_BBS()
|
||||
unlink(fdbtemp);
|
||||
}
|
||||
} else {
|
||||
fclose(fdb);
|
||||
fclose(fp);
|
||||
}
|
||||
DidDelete = FALSE;
|
||||
}
|
||||
|
@@ -94,43 +94,49 @@ void Uploads()
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), i);
|
||||
sprintf(fAreas, "%s/fdb/file%d.data", getenv("MBSE_ROOT"), i);
|
||||
if ((pFile = fopen(fAreas, "r+")) != NULL) {
|
||||
|
||||
while (fread(&file, sizeof(file), 1, pFile) == 1) {
|
||||
fread(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||
Nopper();
|
||||
if (!file.Announced) {
|
||||
Syslog('m', " %d %s", i, file.Name);
|
||||
if (!fdb.Announced) {
|
||||
Syslog('m', " %d %s", i, fdb.Name);
|
||||
memset(&T_File, 0, sizeof(T_File));
|
||||
sprintf(T_File.Echo, "AREA %d", i);
|
||||
sprintf(T_File.Group, "%s", area.NewGroup);
|
||||
sprintf(T_File.Comment, "%s", area.Name);
|
||||
sprintf(T_File.Name, "%s", file.Name);
|
||||
sprintf(T_File.LName, "%s", file.LName);
|
||||
T_File.Size = file.Size;
|
||||
T_File.SizeKb = file.Size / 1024;
|
||||
T_File.Fdate = file.FileDate;
|
||||
sprintf(T_File.Crc, "%08lx", file.Crc32);
|
||||
sprintf(T_File.Desc, "%s %s %s %s", file.Desc[0], file.Desc[1], file.Desc[2], file.Desc[3]);
|
||||
if (strlen(fdb.TicArea))
|
||||
strncpy(T_File.Echo, fdb.TicArea, sizeof(T_File.Echo) -1);
|
||||
else
|
||||
sprintf(T_File.Echo, "AREA %d", i);
|
||||
strncpy(T_File.Group, area.NewGroup, sizeof(T_File.Group) -1);
|
||||
strncpy(T_File.Comment, area.Name, sizeof(T_File.Comment) -1);
|
||||
strncpy(T_File.Name, fdb.Name, sizeof(T_File.Name) -1);
|
||||
strncpy(T_File.LName, fdb.LName, sizeof(T_File.LName) -1);
|
||||
if (strlen(fdb.Magic))
|
||||
strncpy(T_File.Magic, fdb.Magic, sizeof(T_File.Magic) -1);
|
||||
T_File.Size = fdb.Size;
|
||||
T_File.SizeKb = fdb.Size / 1024;
|
||||
T_File.Fdate = fdb.FileDate;
|
||||
sprintf(T_File.Crc, "%08lx", fdb.Crc32);
|
||||
sprintf(T_File.Desc, "%s %s %s %s", fdb.Desc[0], fdb.Desc[1], fdb.Desc[2], fdb.Desc[3]);
|
||||
k = 0;
|
||||
for (j = 0; j < 25; j++) {
|
||||
if (strlen(file.Desc[j])) {
|
||||
sprintf(T_File.LDesc[k], "%s", file.Desc[j]);
|
||||
if (strlen(fdb.Desc[j])) {
|
||||
sprintf(T_File.LDesc[k], "%s", fdb.Desc[j]);
|
||||
T_File.LDesc[k][49] = '\0';
|
||||
k++;
|
||||
}
|
||||
}
|
||||
T_File.TotLdesc = k;
|
||||
T_File.Cost = file.Cost;
|
||||
T_File.Announce = TRUE;
|
||||
if (Add_ToBeRep())
|
||||
Count++;
|
||||
/*
|
||||
* Mark file is announced.
|
||||
*/
|
||||
file.Announced = TRUE;
|
||||
fseek(pFile, - sizeof(file), SEEK_CUR);
|
||||
fwrite(&file, sizeof(file), 1, pFile);
|
||||
fdb.Announced = TRUE;
|
||||
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -291,12 +291,13 @@ void ScanFiles(ff_list *tmp)
|
||||
Back(15);
|
||||
}
|
||||
if (area.Available && area.FileFind) {
|
||||
sprintf(temp, "%s/fdb/fdb%lu.data", getenv("MBSE_ROOT"), areanr);
|
||||
sprintf(temp, "%s/fdb/file%lu.data", getenv("MBSE_ROOT"), areanr);
|
||||
if ((pFile = fopen(temp, "r")) != NULL) {
|
||||
|
||||
while (fread(&file, sizeof(file), 1, pFile) == 1) {
|
||||
fread(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||
for (i = 0; i < 25; i++)
|
||||
sprintf(BigDesc, "%s%s", BigDesc, *(file.Desc + i));
|
||||
sprintf(BigDesc, "%s%s", BigDesc, *(fdb.Desc + i));
|
||||
sprintf(temp, "%s", tmp->subject);
|
||||
|
||||
Found = FALSE;
|
||||
@@ -332,20 +333,20 @@ void ScanFiles(ff_list *tmp)
|
||||
tl(kwd);
|
||||
|
||||
if (strlen(kwd) > 3) {
|
||||
if (strstr(file.Name, kwd) != NULL) {
|
||||
if (strstr(fdb.Name, kwd) != NULL) {
|
||||
Found = TRUE;
|
||||
Syslog('m', "Found %s in %s in filename", kwd, file.Name);
|
||||
Syslog('m', "Found %s in %s in filename", kwd, fdb.Name);
|
||||
}
|
||||
if (keywrd && (strstr(tl(BigDesc), kwd) != NULL)) {
|
||||
Found = TRUE;
|
||||
Syslog('m', "Found %s in %s in description", kwd, file.Name);
|
||||
Syslog('m', "Found %s in %s in description", kwd, fdb.Name);
|
||||
}
|
||||
}
|
||||
} /* while (strlen(temp) && (!Found)) */
|
||||
if (Found) {
|
||||
found++;
|
||||
Syslog('m', "Found %s area %d", file.Name, areanr);
|
||||
fill_rflist(&rfl, file.Name, areanr);
|
||||
Syslog('m', "Found %s area %d", fdb.Name, areanr);
|
||||
fill_rflist(&rfl, fdb.Name, areanr);
|
||||
}
|
||||
strcpy(BigDesc, "");
|
||||
}
|
||||
@@ -404,27 +405,28 @@ void ScanFiles(ff_list *tmp)
|
||||
areanr = rft->area;
|
||||
}
|
||||
|
||||
sprintf(temp, "%s/fdb/fdb%lu.data", getenv("MBSE_ROOT"), rft->area);
|
||||
sprintf(temp, "%s/fdb/file%lu.data", getenv("MBSE_ROOT"), rft->area);
|
||||
if ((pFile = fopen(temp, "r")) != NULL) {
|
||||
while (fread(&file, sizeof(file), 1, pFile) == 1)
|
||||
if (!strcmp(rft->filename, file.Name))
|
||||
fread(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1)
|
||||
if (!strcmp(rft->filename, fdb.Name))
|
||||
break;
|
||||
fclose(pFile);
|
||||
MacroVars("slbkdt", "ssddss", file.Name, file.LName, file.Size, file.Size / 1024, " ",
|
||||
To_Low(file.Desc[0],scanmgr.HiAscii));
|
||||
MacroVars("slbkdt", "ssddss", fdb.Name, fdb.LName, fdb.Size, fdb.Size / 1024, " ",
|
||||
To_Low(fdb.Desc[0],scanmgr.HiAscii));
|
||||
fseek(fi, filepos1, SEEK_SET);
|
||||
Msg_Macro(fi);
|
||||
filepos2 = ftell(fi);
|
||||
SubSize += file.Size;
|
||||
SubSize += fdb.Size;
|
||||
|
||||
/*
|
||||
* We add no more then 5 description lines
|
||||
* to prevent unnecesary long messages.
|
||||
*/
|
||||
for (i = 1; i < MAX_DESC_LINES; i++) {
|
||||
MacroVars("t", "s", To_Low(file.Desc[i],scanmgr.HiAscii));
|
||||
MacroVars("t", "s", To_Low(fdb.Desc[i],scanmgr.HiAscii));
|
||||
fseek(fi, filepos2, SEEK_SET);
|
||||
if (strlen(file.Desc[i])) {
|
||||
if (strlen(fdb.Desc[i])) {
|
||||
Msg_Macro(fi);
|
||||
} else {
|
||||
line = calloc(255, sizeof(char));
|
||||
|
@@ -305,11 +305,6 @@ void F_Status(faddr *t, char *replyid)
|
||||
MacroVars("B", "d", nodes.Tic);
|
||||
MacroVars("C", "d", nodes.AdvTic);
|
||||
MacroVars("D", "d", nodes.Notify);
|
||||
MacroVars("E", "d", nodes.Billing);
|
||||
MacroVars("f", "d", nodes.BillDirect);
|
||||
MacroVars("G", "d", nodes.Debet);
|
||||
MacroVars("I", "d", nodes.Credit);
|
||||
MacroVars("J", "d", nodes.WarnLevel);
|
||||
MacroVars("a", "d", nodes.FilesSent.lweek);
|
||||
MacroVars("b", "d", nodes.FilesSent.month[i]);
|
||||
MacroVars("c", "d", nodes.FilesSent.total);
|
||||
|
@@ -43,7 +43,7 @@
|
||||
|
||||
void ForwardFile(fidoaddr Node, fa_list *sbl)
|
||||
{
|
||||
char *subject = NULL, *fwdfile = NULL, *queuedir, *listfile, *ticfile = NULL, fname[PATH_MAX], *ticname, flavor;
|
||||
char *subject = NULL, *fwdfile = NULL, *queuedir, *listfile, *ticfile = NULL, *ticname, flavor;
|
||||
FILE *fp, *fi, *fl, *net;
|
||||
faddr *dest, *routeto, *Fa, *Temp, *ba;
|
||||
int i, z, n;
|
||||
@@ -56,28 +56,6 @@ void ForwardFile(fidoaddr Node, fa_list *sbl)
|
||||
}
|
||||
Syslog('+', "Forward file to %s %s netmail", aka2str(Node), nodes.Message?"with":"without");
|
||||
|
||||
/*
|
||||
* If Costsharing active for this node
|
||||
*/
|
||||
if (nodes.Billing) {
|
||||
/*
|
||||
* Check if this node has enough credits for this file.
|
||||
*/
|
||||
T_File.Cost = TIC.FileCost + (TIC.FileCost * nodes.AddPerc / 1000);
|
||||
if ((nodes.Credit < (nodes.StopLevel + T_File.Cost)) && (!TIC.Charge)) {
|
||||
Syslog('!', "No forward to %s, not enough credit left", aka2str(Node));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if we are passing the warning level
|
||||
*/
|
||||
if ((nodes.Credit > nodes.WarnLevel) && ((nodes.Credit - T_File.Cost) <= nodes.WarnLevel)) {
|
||||
Syslog('+', "Low credit warning to %s", aka2str(Node));
|
||||
/* CREATE NETMAIL */
|
||||
}
|
||||
}
|
||||
|
||||
fwdfile = calloc(PATH_MAX, sizeof(char));
|
||||
queuedir = calloc(PATH_MAX, sizeof(char));
|
||||
listfile = calloc(PATH_MAX, sizeof(char));
|
||||
@@ -206,12 +184,6 @@ void ForwardFile(fidoaddr Node, fa_list *sbl)
|
||||
if (nodes.AdvTic) {
|
||||
fprintf(fp, "Areadesc %s\r\n", tic.Comment);
|
||||
fprintf(fp, "Fdn %s\r\n", fgroup.Comment);
|
||||
/*
|
||||
* According to Harald Harms this field must
|
||||
* be multiplied with 100.
|
||||
*/
|
||||
if (TIC.FileCost && nodes.Billing)
|
||||
fprintf(fp, "Cost %ld.00\r\n", T_File.Cost);
|
||||
if (TIC.TicIn.TotLDesc)
|
||||
for (i = 0; i < TIC.TicIn.TotLDesc; i++)
|
||||
fprintf(fp, "LDesc %s\r\n", TIC.TicIn.LDesc[i]);
|
||||
@@ -289,30 +261,6 @@ void ForwardFile(fidoaddr Node, fa_list *sbl)
|
||||
WriteError("$Can't create %s", ticfile);
|
||||
}
|
||||
}
|
||||
|
||||
if (TIC.Charge && nodes.Billing) {
|
||||
nodes.Credit -= TIC.FileCost;
|
||||
Syslog('-', "Cost: %d Left: %d", TIC.FileCost, nodes.Credit);
|
||||
|
||||
/*
|
||||
* Add an entry to the billing file, each node has his own
|
||||
* billing file.
|
||||
*/
|
||||
sprintf(fname, "%s/tmp/%d.%d.%d.%d.bill", getenv("MBSE_ROOT"),
|
||||
nodes.Aka[0].zone, nodes.Aka[0].net, nodes.Aka[0].node, nodes.Aka[0].point);
|
||||
if ((fp = fopen(fname, "a+")) != NULL) {
|
||||
memset(&bill, 0, sizeof(bill));
|
||||
bill.Node = nodes.Aka[0];
|
||||
strcpy(bill.FileName, TIC.NewFile);
|
||||
strcpy(bill.FileEcho, TIC.TicIn.Area);
|
||||
bill.Size = TIC.FileSize;
|
||||
bill.Cost = TIC.FileCost;
|
||||
fwrite(&bill, sizeof(bill), 1, fp);
|
||||
fclose(fp);
|
||||
} else {
|
||||
WriteError("$Can't create %s", fname);
|
||||
}
|
||||
}
|
||||
fsync(fileno(fl));
|
||||
fclose(fl);
|
||||
|
||||
|
@@ -322,9 +322,6 @@ void MakeStat(void)
|
||||
MacroVars("d", "s", q);
|
||||
MacroVars("e", "s", p);
|
||||
MacroVars("f", "s", adate(nodes.LastDate));
|
||||
MacroVars("g", "d", nodes.Billing);
|
||||
MacroVars("h", "d", nodes.Credit);
|
||||
MacroVars("i", "d", nodes.Debet);
|
||||
MacroVars("j", "d", nodes.F_KbSent.total);
|
||||
MacroVars("k", "d", nodes.F_KbRcvd.total);
|
||||
MacroVars("l", "d", nodes.MailSent.total);
|
||||
|
@@ -51,7 +51,7 @@ void AdoptFile(int Area, char *File, char *Description)
|
||||
int IsArchive = FALSE, MustRearc = FALSE, UnPacked = FALSE;
|
||||
int IsVirus = FALSE, File_Id = FALSE;
|
||||
int i, j, k, lines = 0, File_id_cnt = 0, rc;
|
||||
struct FILERecord fdb;
|
||||
struct FILE_record f_db;
|
||||
|
||||
Syslog('f', "Adopt(%d, %s, %s)", Area, MBSE_SS(File), MBSE_SS(Description));
|
||||
|
||||
@@ -140,11 +140,11 @@ void AdoptFile(int Area, char *File, char *Description)
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
memset(&fdb, 0, sizeof(fdb));
|
||||
strcpy(fdb.Uploader, CFG.sysop_name);
|
||||
fdb.UploadDate = time(NULL);
|
||||
memset(&f_db, 0, sizeof(f_db));
|
||||
strcpy(f_db.Uploader, CFG.sysop_name);
|
||||
f_db.UploadDate = time(NULL);
|
||||
if (do_annon)
|
||||
fdb.Announced = TRUE;
|
||||
f_db.Announced = TRUE;
|
||||
|
||||
if (UnPacked) {
|
||||
/*
|
||||
@@ -187,7 +187,7 @@ void AdoptFile(int Area, char *File, char *Description)
|
||||
j = 0;
|
||||
for (i = 0; i < strlen(Desc); i++) {
|
||||
if ((Desc[i] >= ' ') || (Desc[i] < 0)) {
|
||||
fdb.Desc[File_id_cnt][j] = Desc[i];
|
||||
f_db.Desc[File_id_cnt][j] = Desc[i];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
@@ -200,12 +200,12 @@ void AdoptFile(int Area, char *File, char *Description)
|
||||
/*
|
||||
* Strip empty lines at end of FILE_ID.DIZ
|
||||
*/
|
||||
while ((strlen(fdb.Desc[File_id_cnt-1]) == 0) && (File_id_cnt))
|
||||
while ((strlen(f_db.Desc[File_id_cnt-1]) == 0) && (File_id_cnt))
|
||||
File_id_cnt--;
|
||||
|
||||
Syslog('f', "Got %d FILE_ID.DIZ lines", File_id_cnt);
|
||||
for (i = 0; i < File_id_cnt; i++)
|
||||
Syslog('f', "\"%s\"", fdb.Desc[i]);
|
||||
Syslog('f', "\"%s\"", f_db.Desc[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -225,7 +225,7 @@ void AdoptFile(int Area, char *File, char *Description)
|
||||
/*
|
||||
* Less then 48 chars, copy and ready.
|
||||
*/
|
||||
strcpy(fdb.Desc[0], Description);
|
||||
strcpy(f_db.Desc[0], Description);
|
||||
File_id_cnt++;
|
||||
} else {
|
||||
/*
|
||||
@@ -238,14 +238,14 @@ void AdoptFile(int Area, char *File, char *Description)
|
||||
j = 48;
|
||||
while (TDesc[j] != ' ')
|
||||
j--;
|
||||
strncat(fdb.Desc[File_id_cnt], TDesc, j);
|
||||
strncat(f_db.Desc[File_id_cnt], TDesc, j);
|
||||
File_id_cnt++;
|
||||
k = strlen(TDesc);
|
||||
j++; /* Correct space */
|
||||
for (i = 0; i <= k; i++, j++)
|
||||
TDesc[i] = TDesc[j];
|
||||
}
|
||||
strcpy(fdb.Desc[File_id_cnt], TDesc);
|
||||
strcpy(f_db.Desc[File_id_cnt], TDesc);
|
||||
File_id_cnt++;
|
||||
}
|
||||
}
|
||||
@@ -261,11 +261,11 @@ void AdoptFile(int Area, char *File, char *Description)
|
||||
*/
|
||||
strcpy(temp2, File);
|
||||
name_mangle(temp2);
|
||||
strcpy(fdb.Name, temp2);
|
||||
strcpy(fdb.LName, File);
|
||||
fdb.Size = file_size(File);
|
||||
fdb.Crc32 = file_crc(File, TRUE);
|
||||
fdb.FileDate = file_time(File);
|
||||
strcpy(f_db.Name, temp2);
|
||||
strcpy(f_db.LName, File);
|
||||
f_db.Size = file_size(File);
|
||||
f_db.Crc32 = file_crc(File, TRUE);
|
||||
f_db.FileDate = file_time(File);
|
||||
sprintf(temp2, "%s/%s", area.Path, File);
|
||||
|
||||
if (!do_quiet) {
|
||||
@@ -273,15 +273,15 @@ void AdoptFile(int Area, char *File, char *Description)
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
if (strcmp(fdb.Name, fdb.LName)) {
|
||||
if (strcmp(f_db.Name, f_db.LName)) {
|
||||
lname = calloc(PATH_MAX, sizeof(char));
|
||||
sprintf(lname, "%s/%s", area.Path, fdb.Name);
|
||||
if (AddFile(fdb, Area, temp2, File, lname) == FALSE) {
|
||||
sprintf(lname, "%s/%s", area.Path, f_db.Name);
|
||||
if (AddFile(f_db, Area, temp2, File, lname) == FALSE) {
|
||||
die(MBERR_GENERAL);
|
||||
}
|
||||
free(lname);
|
||||
} else {
|
||||
if (AddFile(fdb, Area, temp2, File, NULL) == FALSE) {
|
||||
if (AddFile(f_db, Area, temp2, File, NULL) == FALSE) {
|
||||
die(MBERR_GENERAL);
|
||||
}
|
||||
}
|
||||
|
@@ -172,7 +172,7 @@ void Check(void)
|
||||
WriteError("Can't stat %s", area.Path);
|
||||
}
|
||||
|
||||
sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), i);
|
||||
sprintf(fAreas, "%s/fdb/file%d.data", getenv("MBSE_ROOT"), i);
|
||||
|
||||
/*
|
||||
* Open the file database, if it doesn't exist,
|
||||
@@ -184,6 +184,11 @@ void Check(void)
|
||||
WriteError("$Can't create %s", fAreas);
|
||||
die(MBERR_GENERAL);
|
||||
}
|
||||
fdbhdr.hdrsize = sizeof(fdbhdr);
|
||||
fdbhdr.recsize = sizeof(fdb);
|
||||
fwrite(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
} else {
|
||||
fread(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -191,23 +196,22 @@ void Check(void)
|
||||
* against the contents of the directory.
|
||||
*/
|
||||
inArea = 0;
|
||||
while (fread(&file, sizeof(file), 1, pFile) == 1) {
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||
|
||||
iTotal++;
|
||||
inArea++;
|
||||
sprintf(newdir, "%s/%s", area.Path, file.LName);
|
||||
sprintf(mname, "%s/%s", area.Path, file.Name);
|
||||
sprintf(newdir, "%s/%s", area.Path, fdb.LName);
|
||||
sprintf(mname, "%s/%s", area.Path, fdb.Name);
|
||||
|
||||
if (file_exist(newdir, R_OK) && file_exist(mname, R_OK)) {
|
||||
Syslog('+', "File %s area %d not on disk.", newdir, i);
|
||||
if (!file.NoKill) {
|
||||
file.Deleted = TRUE;
|
||||
if (!fdb.NoKill) {
|
||||
fdb.Deleted = TRUE;
|
||||
do_pack = TRUE;
|
||||
}
|
||||
iErrors++;
|
||||
file.Missing = TRUE;
|
||||
fseek(pFile, - sizeof(file), SEEK_CUR);
|
||||
fwrite(&file, sizeof(file), 1, pFile);
|
||||
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
||||
} else {
|
||||
/*
|
||||
* File exists, now check the file.
|
||||
@@ -215,16 +219,16 @@ void Check(void)
|
||||
Marker();
|
||||
Update = FALSE;
|
||||
|
||||
strcpy(temp, file.LName);
|
||||
strcpy(temp, fdb.LName);
|
||||
name_mangle(temp);
|
||||
sprintf(mname, "%s/%s", area.Path, temp);
|
||||
if (strcmp(file.Name, temp)) {
|
||||
Syslog('!', "Converted %s to %s", file.Name, temp);
|
||||
if (strcmp(fdb.Name, temp)) {
|
||||
Syslog('!', "Converted %s to %s", fdb.Name, temp);
|
||||
tname = calloc(PATH_MAX, sizeof(char));
|
||||
sprintf(tname, "%s/%s", area.Path, file.Name);
|
||||
sprintf(tname, "%s/%s", area.Path, fdb.Name);
|
||||
rename(tname, mname);
|
||||
free(tname);
|
||||
strncpy(file.Name, temp, 12);
|
||||
strncpy(fdb.Name, temp, 12);
|
||||
iErrors++;
|
||||
Update = TRUE;
|
||||
}
|
||||
@@ -232,17 +236,17 @@ void Check(void)
|
||||
/*
|
||||
* If 8.3 and LFN are the same, try to rename the LFN to lowercase.
|
||||
*/
|
||||
if (strcmp(file.Name, file.LName) == 0) {
|
||||
if (strcmp(fdb.Name, fdb.LName) == 0) {
|
||||
/*
|
||||
* 8.3 and LFN are the same.
|
||||
*/
|
||||
tname = calloc(PATH_MAX, sizeof(char));
|
||||
sprintf(tname, "%s/%s", area.Path, file.LName);
|
||||
for (j = 0; j < strlen(file.LName); j++)
|
||||
file.LName[j] = tolower(file.LName[j]);
|
||||
sprintf(newdir, "%s/%s", area.Path, file.LName);
|
||||
sprintf(tname, "%s/%s", area.Path, fdb.LName);
|
||||
for (j = 0; j < strlen(fdb.LName); j++)
|
||||
fdb.LName[j] = tolower(fdb.LName[j]);
|
||||
sprintf(newdir, "%s/%s", area.Path, fdb.LName);
|
||||
if (strcmp(tname, newdir)) {
|
||||
Syslog('+', "Rename LFN from %s to %s", file.Name, file.LName);
|
||||
Syslog('+', "Rename LFN from %s to %s", fdb.Name, fdb.LName);
|
||||
rename(tname, newdir);
|
||||
Update = TRUE;
|
||||
}
|
||||
@@ -323,7 +327,7 @@ void Check(void)
|
||||
* It could be that there is a thumbnail made of the LFN.
|
||||
*/
|
||||
tname = calloc(PATH_MAX, sizeof(char));
|
||||
sprintf(tname, "%s/.%s", area.Path, file.LName);
|
||||
sprintf(tname, "%s/.%s", area.Path, fdb.LName);
|
||||
if (file_exist(tname, R_OK) == 0) {
|
||||
Syslog('+', "Removing thumbnail %s", tname);
|
||||
iErrors++;
|
||||
@@ -332,28 +336,28 @@ void Check(void)
|
||||
free(tname);
|
||||
|
||||
|
||||
if (file_time(newdir) != file.FileDate) {
|
||||
Syslog('!', "Date mismatch area %d file %s", i, file.LName);
|
||||
file.FileDate = file_time(newdir);
|
||||
if (file_time(newdir) != fdb.FileDate) {
|
||||
Syslog('!', "Date mismatch area %d file %s", i, fdb.LName);
|
||||
fdb.FileDate = file_time(newdir);
|
||||
iErrors++;
|
||||
Update = TRUE;
|
||||
}
|
||||
if (file_size(newdir) != file.Size) {
|
||||
Syslog('!', "Size mismatch area %d file %s", i, file.LName);
|
||||
file.Size = file_size(newdir);
|
||||
if (file_size(newdir) != fdb.Size) {
|
||||
Syslog('!', "Size mismatch area %d file %s", i, fdb.LName);
|
||||
fdb.Size = file_size(newdir);
|
||||
iErrors++;
|
||||
Update = TRUE;
|
||||
}
|
||||
if (file_crc(newdir, CFG.slow_util && do_quiet) != file.Crc32) {
|
||||
Syslog('!', "CRC error area %d, file %s", i, file.LName);
|
||||
file.Crc32 = file_crc(newdir, CFG.slow_util && do_quiet);
|
||||
if (file_crc(newdir, CFG.slow_util && do_quiet) != fdb.Crc32) {
|
||||
Syslog('!', "CRC error area %d, file %s", i, fdb.LName);
|
||||
fdb.Crc32 = file_crc(newdir, CFG.slow_util && do_quiet);
|
||||
iErrors++;
|
||||
Update = TRUE;
|
||||
}
|
||||
Marker();
|
||||
if (Update) {
|
||||
fseek(pFile, - sizeof(file), SEEK_CUR);
|
||||
fwrite(&file, sizeof(file), 1, pFile);
|
||||
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -370,9 +374,9 @@ void Check(void)
|
||||
if (de->d_name[0] != '.') {
|
||||
Marker();
|
||||
Found = FALSE;
|
||||
rewind(pFile);
|
||||
while (fread(&file, sizeof(file), 1, pFile) == 1) {
|
||||
if ((strcmp(file.LName, de->d_name) == 0) || (strcmp(file.Name, de->d_name) == 0)) {
|
||||
fseek(pFile, fdbhdr.hdrsize, SEEK_SET);
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||
if ((strcmp(fdb.LName, de->d_name) == 0) || (strcmp(fdb.Name, de->d_name) == 0)) {
|
||||
if (!Found) {
|
||||
Found = TRUE;
|
||||
} else {
|
||||
@@ -380,12 +384,12 @@ void Check(void)
|
||||
* Record has been found before, so this must be
|
||||
* a double record.
|
||||
*/
|
||||
Syslog('!', "Double file record area %d file %s", i, file.LName);
|
||||
Syslog('!', "Double file record area %d file %s", i, fdb.LName);
|
||||
iErrors++;
|
||||
file.Double = TRUE;
|
||||
fdb.Double = TRUE;
|
||||
do_pack = TRUE;
|
||||
fseek(pFile, - sizeof(file), SEEK_CUR);
|
||||
fwrite(&file, sizeof(file), 1, pFile);
|
||||
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -421,7 +425,7 @@ void Check(void)
|
||||
} else {
|
||||
|
||||
if (strlen(area.Name) == 0) {
|
||||
sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), i);
|
||||
sprintf(fAreas, "%s/fdb/file%d.data", getenv("MBSE_ROOT"), i);
|
||||
if (unlink(fAreas) == 0) {
|
||||
Syslog('+', "Removed obsolete %s", fAreas);
|
||||
}
|
||||
|
@@ -42,12 +42,11 @@ extern int do_quiet; /* Suppress screen output */
|
||||
|
||||
|
||||
/*
|
||||
* Move a file
|
||||
* Delete a file
|
||||
*/
|
||||
void Delete(int UnDel, int Area, char *File)
|
||||
{
|
||||
char *temp;
|
||||
struct FILERecord fdb;
|
||||
FILE *fp;
|
||||
int rc = FALSE;
|
||||
|
||||
|
@@ -50,7 +50,7 @@ void ImportFiles(int Area)
|
||||
DIR *dp;
|
||||
int Append = FALSE, Files = 0, rc, i, line = 0, pos, x, Doit;
|
||||
int Imported = 0, Errors = 0, Present = FALSE;
|
||||
struct FILERecord fdb;
|
||||
struct FILE_record f_db;
|
||||
struct stat statfile;
|
||||
struct dirent *de;
|
||||
|
||||
@@ -105,7 +105,7 @@ void ImportFiles(int Area)
|
||||
Doit = TRUE;
|
||||
if ((unarc = unpacker(temp)) == NULL) {
|
||||
Syslog('+', "Unknown archive format %s", temp);
|
||||
sprintf(temp2, "%s/tmp/arc/%s", getenv("MBSE_ROOT"), fdb.Name);
|
||||
sprintf(temp2, "%s/tmp/arc/%s", getenv("MBSE_ROOT"), f_db.Name);
|
||||
mkdirs(temp2, 0755);
|
||||
if ((rc = file_cp(temp, temp2))) {
|
||||
WriteError("Can't copy file to %s, %s", temp2, strerror(rc));
|
||||
@@ -148,14 +148,14 @@ void ImportFiles(int Area)
|
||||
printf("Adding \b\b\b\b\b\b\b\b\b\b");
|
||||
fflush(stdout);
|
||||
}
|
||||
if (strcmp(fdb.Name, fdb.LName)) {
|
||||
if (AddFile(fdb, Area, dest, temp, lname)) {
|
||||
if (strcmp(f_db.Name, f_db.LName)) {
|
||||
if (AddFile(f_db, Area, dest, temp, lname)) {
|
||||
Imported++;
|
||||
} else {
|
||||
Errors++;
|
||||
}
|
||||
} else {
|
||||
if (AddFile(fdb, Area, dest, temp, NULL)) {
|
||||
if (AddFile(f_db, Area, dest, temp, NULL)) {
|
||||
Imported++;
|
||||
} else {
|
||||
Errors++;
|
||||
@@ -177,7 +177,7 @@ void ImportFiles(int Area)
|
||||
die(MBERR_DISK_FULL);
|
||||
|
||||
Files++;
|
||||
memset(&fdb, 0, sizeof(fdb));
|
||||
memset(&f_db, 0, sizeof(f_db));
|
||||
Present = TRUE;
|
||||
|
||||
token = strtok(String, " \t");
|
||||
@@ -195,13 +195,13 @@ void ImportFiles(int Area)
|
||||
/*
|
||||
* Found the right file.
|
||||
*/
|
||||
strncpy(fdb.LName, token, 80);
|
||||
strncpy(f_db.LName, token, 80);
|
||||
break;
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
|
||||
if (strlen(fdb.LName) == 0) {
|
||||
if (strlen(f_db.LName) == 0) {
|
||||
WriteError("Can't find file on disk, skipping: %s\n", token);
|
||||
Append = FALSE;
|
||||
Present = FALSE;
|
||||
@@ -209,28 +209,28 @@ void ImportFiles(int Area)
|
||||
/*
|
||||
* Create DOS 8.3 filename
|
||||
*/
|
||||
strcpy(temp2, fdb.LName);
|
||||
strcpy(temp2, f_db.LName);
|
||||
name_mangle(temp2);
|
||||
strcpy(fdb.Name, temp2);
|
||||
strcpy(f_db.Name, temp2);
|
||||
|
||||
if (strcmp(fdb.LName, fdb.Name) && (rename(fdb.LName, fdb.Name) == 0)) {
|
||||
Syslog('+', "Renamed %s to %s", fdb.LName, fdb.Name);
|
||||
if (strcmp(f_db.LName, f_db.Name) && (rename(f_db.LName, f_db.Name) == 0)) {
|
||||
Syslog('+', "Renamed %s to %s", f_db.LName, f_db.Name);
|
||||
}
|
||||
|
||||
sprintf(temp, "%s/%s", pwd, fdb.Name);
|
||||
sprintf(temp, "%s/%s", pwd, f_db.Name);
|
||||
stat(temp, &statfile);
|
||||
|
||||
if (do_annon)
|
||||
fdb.Announced = TRUE;
|
||||
Syslog('f', "File: %s (%s)", fdb.Name, fdb.LName);
|
||||
f_db.Announced = TRUE;
|
||||
Syslog('f', "File: %s (%s)", f_db.Name, f_db.LName);
|
||||
|
||||
if (!do_quiet) {
|
||||
printf("\rImport file: %s ", fdb.Name);
|
||||
printf("\rImport file: %s ", f_db.Name);
|
||||
printf("Checking \b\b\b\b\b\b\b\b\b\b");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
IsDoing("Import %s", fdb.Name);
|
||||
IsDoing("Import %s", f_db.Name);
|
||||
|
||||
token = strtok(NULL, "\0");
|
||||
i = strlen(token);
|
||||
@@ -250,20 +250,20 @@ void ImportFiles(int Area)
|
||||
if (Doit) {
|
||||
if (pos > 42) {
|
||||
if (token[x] == ' ') {
|
||||
fdb.Desc[line][pos] = '\0';
|
||||
f_db.Desc[line][pos] = '\0';
|
||||
line++;
|
||||
pos = 0;
|
||||
} else {
|
||||
if (pos == 49) {
|
||||
fdb.Desc[line][pos] = '\0';
|
||||
f_db.Desc[line][pos] = '\0';
|
||||
pos = 0;
|
||||
line++;
|
||||
}
|
||||
fdb.Desc[line][pos] = token[x];
|
||||
f_db.Desc[line][pos] = token[x];
|
||||
pos++;
|
||||
}
|
||||
} else {
|
||||
fdb.Desc[line][pos] = token[x];
|
||||
f_db.Desc[line][pos] = token[x];
|
||||
pos++;
|
||||
}
|
||||
if (line == 25)
|
||||
@@ -271,14 +271,14 @@ void ImportFiles(int Area)
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(dest, "%s/%s", area.Path, fdb.Name);
|
||||
sprintf(lname, "%s/%s", area.Path, fdb.LName);
|
||||
sprintf(dest, "%s/%s", area.Path, f_db.Name);
|
||||
sprintf(lname, "%s/%s", area.Path, f_db.LName);
|
||||
Append = TRUE;
|
||||
fdb.Size = statfile.st_size;
|
||||
fdb.FileDate = statfile.st_mtime;
|
||||
fdb.Crc32 = file_crc(temp, FALSE);
|
||||
strcpy(fdb.Uploader, CFG.sysop_name);
|
||||
fdb.UploadDate = time(NULL);
|
||||
f_db.Size = statfile.st_size;
|
||||
f_db.FileDate = statfile.st_mtime;
|
||||
f_db.Crc32 = file_crc(temp, FALSE);
|
||||
strcpy(f_db.Uploader, CFG.sysop_name);
|
||||
f_db.UploadDate = time(NULL);
|
||||
}
|
||||
} else if (Present) {
|
||||
/*
|
||||
@@ -298,20 +298,20 @@ void ImportFiles(int Area)
|
||||
if (Doit) {
|
||||
if (pos > 42) {
|
||||
if (token[x] == ' ') {
|
||||
fdb.Desc[line][pos] = '\0';
|
||||
f_db.Desc[line][pos] = '\0';
|
||||
line++;
|
||||
pos = 0;
|
||||
} else {
|
||||
if (pos == 49) {
|
||||
fdb.Desc[line][pos] = '\0';
|
||||
f_db.Desc[line][pos] = '\0';
|
||||
pos = 0;
|
||||
line++;
|
||||
}
|
||||
fdb.Desc[line][pos] = token[x];
|
||||
f_db.Desc[line][pos] = token[x];
|
||||
pos++;
|
||||
}
|
||||
} else {
|
||||
fdb.Desc[line][pos] = token[x];
|
||||
f_db.Desc[line][pos] = token[x];
|
||||
pos++;
|
||||
}
|
||||
if (line == 25)
|
||||
@@ -336,7 +336,7 @@ void ImportFiles(int Area)
|
||||
Doit = TRUE;
|
||||
if ((unarc = unpacker(temp)) == NULL) {
|
||||
Syslog('+', "Unknown archive format %s", temp);
|
||||
sprintf(temp2, "%s/tmp/arc/%s", getenv("MBSE_ROOT"), fdb.LName);
|
||||
sprintf(temp2, "%s/tmp/arc/%s", getenv("MBSE_ROOT"), f_db.LName);
|
||||
mkdirs(temp2, 0755);
|
||||
if ((rc = file_cp(temp, temp2))) {
|
||||
WriteError("Can't copy file to %s, %s", temp2, strerror(rc));
|
||||
@@ -377,13 +377,13 @@ void ImportFiles(int Area)
|
||||
printf("Adding \b\b\b\b\b\b\b\b\b\b");
|
||||
fflush(stdout);
|
||||
}
|
||||
if (strcmp(fdb.Name, fdb.LName)) {
|
||||
if (AddFile(fdb, Area, dest, temp, lname))
|
||||
if (strcmp(f_db.Name, f_db.LName)) {
|
||||
if (AddFile(f_db, Area, dest, temp, lname))
|
||||
Imported++;
|
||||
else
|
||||
Errors++;
|
||||
} else {
|
||||
if (AddFile(fdb, Area, dest, temp, NULL))
|
||||
if (AddFile(f_db, Area, dest, temp, NULL))
|
||||
Imported++;
|
||||
else
|
||||
Errors++;
|
||||
|
@@ -379,7 +379,7 @@ void ReqIndex(void)
|
||||
newdir = NULL;
|
||||
}
|
||||
|
||||
sprintf(fAreas, "%s/fdb/fdb%ld.data", getenv("MBSE_ROOT"), i);
|
||||
sprintf(fAreas, "%s/fdb/file%ld.data", getenv("MBSE_ROOT"), i);
|
||||
|
||||
/*
|
||||
* Open the file database, if it doesn't exist,
|
||||
@@ -391,6 +391,11 @@ void ReqIndex(void)
|
||||
WriteError("$Can't create %s", fAreas);
|
||||
die(MBERR_GENERAL);
|
||||
}
|
||||
fdbhdr.hdrsize = sizeof(fdbhdr);
|
||||
fdbhdr.recsize = sizeof(fdb);
|
||||
fwrite(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
} else {
|
||||
fread(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -401,13 +406,13 @@ void ReqIndex(void)
|
||||
* Now start creating the unsorted index.
|
||||
*/
|
||||
record = 0;
|
||||
while (fread(&file, sizeof(file), 1, pFile) == 1) {
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||
iTotal++;
|
||||
if ((iTotal % 10) == 0)
|
||||
Marker();
|
||||
memset(&idx, 0, sizeof(idx));
|
||||
sprintf(idx.Name, "%s", tu(file.Name));
|
||||
sprintf(idx.LName, "%s", tu(file.LName));
|
||||
sprintf(idx.Name, "%s", tu(fdb.Name));
|
||||
sprintf(idx.LName, "%s", tu(fdb.LName));
|
||||
idx.AreaNum = i;
|
||||
idx.Record = record;
|
||||
fill_index(idx, &fdx);
|
||||
@@ -426,15 +431,15 @@ void ReqIndex(void)
|
||||
if ((fp = fopen(temp, "w")) == NULL) {
|
||||
WriteError("$Can't create %s", temp);
|
||||
} else {
|
||||
fseek(pFile, 0, SEEK_SET);
|
||||
fseek(pFile, fdbhdr.hdrsize, SEEK_SET);
|
||||
fbAreas++;
|
||||
while (fread(&file, sizeof(file), 1, pFile) == 1) {
|
||||
if ((!file.Deleted) && (!file.Missing)) {
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||
if (!fdb.Deleted) {
|
||||
fbFiles++;
|
||||
fprintf(fp, "%-12s [%ld] %s\r\n", file.Name, file.TimesDL + file.TimesFTP + file.TimesReq, file.Desc[0]);
|
||||
fprintf(fp, "%-12s [%ld] %s\r\n", fdb.Name, fdb.TimesDL, fdb.Desc[0]);
|
||||
for (j = 1; j < 25; j++)
|
||||
if (strlen(file.Desc[j]))
|
||||
fprintf(fp, " +%s\r\n", file.Desc[j]);
|
||||
if (strlen(fdb.Desc[j]))
|
||||
fprintf(fp, " +%s\r\n", fdb.Desc[j]);
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
@@ -450,10 +455,10 @@ void ReqIndex(void)
|
||||
if ((fp = fopen(temp, "w")) == NULL) {
|
||||
WriteError("$Can't create %s", temp);
|
||||
} else {
|
||||
fseek(pFile, 0, SEEK_SET);
|
||||
fseek(pFile, fdbhdr.hdrsize, SEEK_SET);
|
||||
|
||||
while (fread(&file, sizeof(file), 1, pFile) == 1) {
|
||||
if ((!file.Deleted) && (!file.Missing)) {
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||
if (!fdb.Deleted) {
|
||||
/*
|
||||
* The next is to reduce system load
|
||||
*/
|
||||
@@ -462,16 +467,16 @@ void ReqIndex(void)
|
||||
msleep(1);
|
||||
|
||||
for (z = 0; z <= 25; z++) {
|
||||
if (strlen(file.Desc[z])) {
|
||||
if (strlen(fdb.Desc[z])) {
|
||||
if (z == 0)
|
||||
fprintf(fp, "%-12s %7luK %s ", file.Name, (long)(file.Size / 1024),
|
||||
StrDateDMY(file.UploadDate));
|
||||
fprintf(fp, "%-12s %7luK %s ", fdb.Name, (long)(fdb.Size / 1024),
|
||||
StrDateDMY(fdb.UploadDate));
|
||||
else
|
||||
fprintf(fp, " ");
|
||||
if ((file.Desc[z][0] == '@') && (file.Desc[z][1] == 'X'))
|
||||
fprintf(fp, "%s\n", file.Desc[z]+4);
|
||||
if ((fdb.Desc[z][0] == '@') && (fdb.Desc[z][1] == 'X'))
|
||||
fprintf(fp, "%s\n", fdb.Desc[z]+4);
|
||||
else
|
||||
fprintf(fp, "%s\n", file.Desc[z]);
|
||||
fprintf(fp, "%s\n", fdb.Desc[z]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -600,7 +605,7 @@ void HtmlIndex(char *Lang)
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
sprintf(fAreas, "%s/fdb/fdb%ld.data", getenv("MBSE_ROOT"), i);
|
||||
sprintf(fAreas, "%s/fdb/file%ld.data", getenv("MBSE_ROOT"), i);
|
||||
|
||||
/*
|
||||
* Open the file database, if it doesn't exist,
|
||||
@@ -609,21 +614,22 @@ void HtmlIndex(char *Lang)
|
||||
if ((pFile = fopen(fAreas, "r+")) == NULL) {
|
||||
WriteError("$Can't open %s", fAreas);
|
||||
die(MBERR_GENERAL);
|
||||
}
|
||||
}
|
||||
fread(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
|
||||
/*
|
||||
* Create index.html pages in each available download area.
|
||||
*/
|
||||
if (!area.CDrom && fm && (strncmp(CFG.ftp_base, area.Path, strlen(CFG.ftp_base)) == 0)) {
|
||||
|
||||
fseek(pFile, 0, SEEK_SET);
|
||||
fseek(pFile, fdbhdr.hdrsize, SEEK_SET);
|
||||
AreasHtml++;
|
||||
inArea = 0;
|
||||
while (fread(&file, sizeof(file), 1, pFile) == 1) {
|
||||
if ((!file.Deleted) && (!file.Missing))
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||
if (!fdb.Deleted)
|
||||
inArea++;
|
||||
}
|
||||
fseek(pFile, 0, SEEK_SET);
|
||||
fseek(pFile, fdbhdr.hdrsize, SEEK_SET);
|
||||
|
||||
aSize = 0L;
|
||||
aTotal = 0;
|
||||
@@ -635,8 +641,8 @@ void HtmlIndex(char *Lang)
|
||||
fileptr1 = gfilepos;
|
||||
}
|
||||
|
||||
while (fread(&file, sizeof(file), 1, pFile) == 1) {
|
||||
if ((!file.Deleted) && (!file.Missing)) {
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||
if (!fdb.Deleted) {
|
||||
/*
|
||||
* The next is to reduce system load
|
||||
*/
|
||||
@@ -654,40 +660,40 @@ void HtmlIndex(char *Lang)
|
||||
* check if a thumbnail file exists. If not try to
|
||||
* create a thumbnail file to add to the html listing.
|
||||
*/
|
||||
if (strstr(file.LName, ".gif") || strstr(file.LName, ".jpg") ||
|
||||
strstr(file.LName, ".GIF") || strstr(file.LName, ".JPG")) {
|
||||
sprintf(linebuf, "%s/%s", area.Path, file.Name);
|
||||
sprintf(outbuf, "%s/.%s", area.Path, file.Name);
|
||||
if (strstr(fdb.LName, ".gif") || strstr(fdb.LName, ".jpg") ||
|
||||
strstr(fdb.LName, ".GIF") || strstr(fdb.LName, ".JPG")) {
|
||||
sprintf(linebuf, "%s/%s", area.Path, fdb.Name);
|
||||
sprintf(outbuf, "%s/.%s", area.Path, fdb.Name);
|
||||
if (file_exist(outbuf, R_OK)) {
|
||||
if ((j = execute_str(CFG.www_convert, linebuf, outbuf,
|
||||
(char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"))) {
|
||||
Syslog('+', "Failed to create thumbnail for %s, rc=% d", file.Name, j);
|
||||
Syslog('+', "Failed to create thumbnail for %s, rc=% d", fdb.Name, j);
|
||||
} else {
|
||||
chmod(outbuf, 0644);
|
||||
}
|
||||
}
|
||||
sprintf(outbuf, "%s/%s%s/%s", CFG.www_url, CFG.www_link2ftp,
|
||||
area.Path+strlen(CFG.ftp_base), file.Name);
|
||||
area.Path+strlen(CFG.ftp_base), fdb.Name);
|
||||
sprintf(linebuf, "%s/%s%s/.%s", CFG.www_url, CFG.www_link2ftp,
|
||||
area.Path+strlen(CFG.ftp_base), file.Name);
|
||||
MacroVars("fghi", "dsss", 1, outbuf, file.LName, linebuf);
|
||||
area.Path+strlen(CFG.ftp_base), fdb.Name);
|
||||
MacroVars("fghi", "dsss", 1, outbuf, fdb.LName, linebuf);
|
||||
} else {
|
||||
sprintf(outbuf, "%s/%s%s/%s", CFG.www_url, CFG.www_link2ftp,
|
||||
area.Path+strlen(CFG.ftp_base), file.Name);
|
||||
MacroVars("fghi", "dsss", 0, outbuf, file.LName, "");
|
||||
area.Path+strlen(CFG.ftp_base), fdb.Name);
|
||||
MacroVars("fghi", "dsss", 0, outbuf, fdb.LName, "");
|
||||
}
|
||||
|
||||
sprintf(outbuf, "%lu Kb.", (long)(file.Size / 1024));
|
||||
MacroVars("jkl", "ssd", StrDateDMY(file.FileDate), outbuf, file.TimesDL+file.TimesFTP+file.TimesReq);
|
||||
sprintf(outbuf, "%lu Kb.", (long)(fdb.Size / 1024));
|
||||
MacroVars("jkl", "ssd", StrDateDMY(fdb.FileDate), outbuf, fdb.TimesDL);
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
k = 0;
|
||||
for (j = 0; j < 25; j++)
|
||||
if (strlen(file.Desc[j])) {
|
||||
if (strlen(fdb.Desc[j])) {
|
||||
if (j) {
|
||||
sprintf(desc+k, "\n");
|
||||
k += 1;
|
||||
}
|
||||
sprintf(linebuf, "%s", To_Html(file.Desc[j]));
|
||||
sprintf(linebuf, "%s", To_Html(fdb.Desc[j]));
|
||||
html_massage(linebuf, outbuf);
|
||||
sprintf(desc+k, "%s", outbuf);
|
||||
k += strlen(outbuf);
|
||||
@@ -695,10 +701,10 @@ void HtmlIndex(char *Lang)
|
||||
MacroVars("m", "s", desc);
|
||||
fseek(fb, fileptr1, SEEK_SET);
|
||||
MacroRead(fb, fa);
|
||||
aSize += file.Size;
|
||||
aSize += fdb.Size;
|
||||
MacroVars("efghijklm", "ddsssssds", 0, 0, "", "", "", "", "", 0, "");
|
||||
if (file.FileDate > last)
|
||||
last = file.FileDate;
|
||||
if (fdb.FileDate > last)
|
||||
last = fdb.FileDate;
|
||||
if ((aTotal % CFG.www_files_page) == 0) {
|
||||
closepage(fa, area.Path, inArea, aTotal, fb);
|
||||
fseek(fb, 0, SEEK_SET);
|
||||
|
@@ -52,7 +52,7 @@ extern int do_pack; /* Perform pack */
|
||||
void Kill(void)
|
||||
{
|
||||
FILE *pAreas, *pFile, *pDest, *pTemp;
|
||||
int i, iAreas, iAreasNew = 0, iTotal = 0, iKilled = 0, iMoved = 0, rc, Killit, FilesLeft;
|
||||
int i, iAreas, iAreasNew = 0, iTotal = 0, iKilled = 0, iMoved = 0, rc, Killit;
|
||||
char *sAreas, *fAreas, *newdir = NULL, *sTemp, from[PATH_MAX], to[PATH_MAX];
|
||||
time_t Now;
|
||||
struct fileareas darea;
|
||||
@@ -106,7 +106,7 @@ void Kill(void)
|
||||
newdir = NULL;
|
||||
}
|
||||
|
||||
sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), i);
|
||||
sprintf(fAreas, "%s/fdb/file%d.data", getenv("MBSE_ROOT"), i);
|
||||
|
||||
/*
|
||||
* Open the file database, if it doesn't exist,
|
||||
@@ -118,29 +118,34 @@ void Kill(void)
|
||||
WriteError("$Can't create %s", fAreas);
|
||||
die(MBERR_GENERAL);
|
||||
}
|
||||
}
|
||||
fdbhdr.hdrsize = sizeof(fdbhdr);
|
||||
fdbhdr.recsize = sizeof(fdb);
|
||||
fwrite(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
} else {
|
||||
fread(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
}
|
||||
|
||||
/*
|
||||
* Now start checking the files in the filedatabase
|
||||
* against the contents of the directory.
|
||||
*/
|
||||
while (fread(&file, sizeof(file), 1, pFile) == 1) {
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||
iTotal++;
|
||||
Marker();
|
||||
|
||||
Killit = FALSE;
|
||||
if (!file.UploadDate)
|
||||
Syslog('!', "Warning: file %s in area %d has no upload date", file.Name, i);
|
||||
if (!fdb.UploadDate)
|
||||
Syslog('!', "Warning: file %s in area %d has no upload date", fdb.Name, i);
|
||||
|
||||
if (area.DLdays) {
|
||||
/*
|
||||
* Test last download date or never downloaded and the
|
||||
* file is more then n days available for download.
|
||||
*/
|
||||
if ((file.LastDL) && (((Now - file.LastDL) / 84400) > area.DLdays)) {
|
||||
if ((fdb.LastDL) && (((Now - fdb.LastDL) / 84400) > area.DLdays)) {
|
||||
Killit = TRUE;
|
||||
}
|
||||
if ((!file.LastDL) && file.UploadDate && (((Now - file.UploadDate) / 84400) > area.DLdays)) {
|
||||
if ((!fdb.LastDL) && fdb.UploadDate && (((Now - fdb.UploadDate) / 84400) > area.DLdays)) {
|
||||
Killit = TRUE;
|
||||
}
|
||||
}
|
||||
@@ -149,7 +154,7 @@ void Kill(void)
|
||||
/*
|
||||
* Check filedate
|
||||
*/
|
||||
if (file.UploadDate && (((Now - file.UploadDate) / 84400) > area.FDdays)) {
|
||||
if (fdb.UploadDate && (((Now - fdb.UploadDate) / 84400) > area.FDdays)) {
|
||||
Killit = TRUE;
|
||||
}
|
||||
}
|
||||
@@ -159,55 +164,62 @@ void Kill(void)
|
||||
if (area.MoveArea) {
|
||||
fseek(pAreas, ((area.MoveArea -1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET);
|
||||
fread(&darea, areahdr.recsize, 1, pAreas);
|
||||
sprintf(from, "%s/%s", area.Path, file.Name);
|
||||
sprintf(to, "%s/%s", darea.Path, file.Name);
|
||||
sprintf(from, "%s/%s", area.Path, fdb.Name);
|
||||
sprintf(to, "%s/%s", darea.Path, fdb.Name);
|
||||
if ((rc = file_mv(from, to)) == 0) {
|
||||
Syslog('+', "Move %s, area %d => %d", file.Name, i, area.MoveArea);
|
||||
sprintf(to, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), area.MoveArea);
|
||||
Syslog('+', "Move %s, area %d => %d", fdb.Name, i, area.MoveArea);
|
||||
sprintf(to, "%s/fdb/file%d.data", getenv("MBSE_ROOT"), area.MoveArea);
|
||||
if ((pDest = fopen(to, "a+")) != NULL) {
|
||||
file.UploadDate = time(NULL);
|
||||
file.LastDL = time(NULL);
|
||||
fwrite(&file, sizeof(file), 1, pDest);
|
||||
fseek(pDest, 0, SEEK_END);
|
||||
if (ftell(pDest) == 0) {
|
||||
/* New file, write header */
|
||||
fwrite(&fdbhdr, fdbhdr.hdrsize, 1, pDest);
|
||||
}
|
||||
fdb.UploadDate = time(NULL);
|
||||
fdb.LastDL = time(NULL);
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, pDest);
|
||||
fclose(pDest);
|
||||
}
|
||||
|
||||
/*
|
||||
* Now again if there is a dotted version (thumbnail) of this file.
|
||||
*/
|
||||
sprintf(from, "%s/.%s", area.Path, file.Name);
|
||||
sprintf(to, "%s/.%s", darea.Path, file.Name);
|
||||
sprintf(from, "%s/.%s", area.Path, fdb.Name);
|
||||
sprintf(to, "%s/.%s", darea.Path, fdb.Name);
|
||||
if (file_exist(from, R_OK) == 0)
|
||||
file_mv(from, to);
|
||||
|
||||
/*
|
||||
* Unlink the old symbolic link
|
||||
*/
|
||||
sprintf(from, "%s/%s", area.Path, file.LName);
|
||||
sprintf(from, "%s/%s", area.Path, fdb.LName);
|
||||
unlink(from);
|
||||
|
||||
/*
|
||||
* Create the new symbolic link
|
||||
*/
|
||||
sprintf(from, "%s/%s", darea.Path, file.Name);
|
||||
sprintf(to, "%s/%s", darea.Path, file.LName);
|
||||
sprintf(from, "%s/%s", darea.Path, fdb.Name);
|
||||
sprintf(to, "%s/%s", darea.Path, fdb.LName);
|
||||
symlink(from, to);
|
||||
|
||||
file.Deleted = TRUE;
|
||||
fseek(pFile, - sizeof(file), SEEK_CUR);
|
||||
fwrite(&file, sizeof(file), 1, pFile);
|
||||
fdb.Deleted = TRUE;
|
||||
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
||||
iMoved++;
|
||||
} else {
|
||||
WriteError("Move %s to area %d failed, %s", file.Name, area.MoveArea, strerror(rc));
|
||||
WriteError("Move %s to area %d failed, %s", fdb.Name, area.MoveArea, strerror(rc));
|
||||
}
|
||||
} else {
|
||||
Syslog('+', "Delete %s, area %d", file.LName, i);
|
||||
file.Deleted = TRUE;
|
||||
fseek(pFile, - sizeof(file), SEEK_CUR);
|
||||
fwrite(&file, sizeof(file), 1, pFile);
|
||||
Syslog('+', "Delete %s, area %d", fdb.LName, i);
|
||||
fdb.Deleted = TRUE;
|
||||
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
||||
iKilled++;
|
||||
sprintf(from, "%s/%s", area.Path, file.LName);
|
||||
sprintf(from, "%s/%s", area.Path, fdb.LName);
|
||||
unlink(from);
|
||||
sprintf(from, "%s/%s", area.Path, file.Name);
|
||||
sprintf(from, "%s/%s", area.Path, fdb.Name);
|
||||
unlink(from);
|
||||
sprintf(from, "%s/.%s", area.Path, fdb.Name);
|
||||
unlink(from);
|
||||
}
|
||||
}
|
||||
@@ -221,11 +233,10 @@ void Kill(void)
|
||||
sprintf(sTemp, "%s/fdb/fdbtmp.data", getenv("MBSE_ROOT"));
|
||||
|
||||
if ((pTemp = fopen(sTemp, "a+")) != NULL) {
|
||||
FilesLeft = FALSE;
|
||||
while (fread(&file, sizeof(file), 1, pFile) == 1) {
|
||||
if ((!file.Deleted) && strcmp(file.LName, "") != 0) {
|
||||
fwrite(&file, sizeof(file), 1, pTemp);
|
||||
FilesLeft = TRUE;
|
||||
fwrite(&fdbhdr, fdbhdr.hdrsize, 1, pTemp);
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||
if ((!fdb.Deleted) && strcmp(fdb.LName, "") != 0) {
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, pTemp);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -98,63 +98,46 @@ void ListFileAreas(int Area)
|
||||
/*
|
||||
* Open the file database, create new one if it doesn't exist.
|
||||
*/
|
||||
sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), Area);
|
||||
sprintf(fAreas, "%s/fdb/file%d.data", getenv("MBSE_ROOT"), Area);
|
||||
if ((pFile = fopen(fAreas, "r+")) == NULL) {
|
||||
Syslog('!', "Creating new %s", fAreas);
|
||||
if ((pFile = fopen(fAreas, "a+")) == NULL) {
|
||||
WriteError("$Can't create %s", fAreas);
|
||||
die(MBERR_GENERAL);
|
||||
}
|
||||
fdbhdr.hdrsize = sizeof(fdbhdr);
|
||||
fdbhdr.recsize = sizeof(fdb);
|
||||
fwrite(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
} else {
|
||||
fread(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
}
|
||||
|
||||
fcount = 0;
|
||||
fsize = 0L;
|
||||
colour(CYAN, BLACK);
|
||||
printf("File listing of area %d, %s\n\n", Area, area.Name);
|
||||
printf("Short name Kb. File date Down Flags TIC Area Long name\n");
|
||||
printf("------------ ----- ---------- ---- ----- -------------------- ");
|
||||
printf("Short name Kb. File date Down Flg TIC Area Long name\n");
|
||||
printf("------------ ----- ---------- ---- --- -------------------- ");
|
||||
for (i = 63; i < COLS; i++)
|
||||
printf("-");
|
||||
printf("\n");
|
||||
|
||||
colour(LIGHTGRAY, BLACK);
|
||||
|
||||
while (fread(&file, sizeof(file), 1, pFile) == 1) {
|
||||
sprintf(flags, "-----");
|
||||
if (file.Free)
|
||||
flags[0] = 'F';
|
||||
if (file.Deleted)
|
||||
flags[1] = 'D';
|
||||
if (file.Missing)
|
||||
flags[2] = 'M';
|
||||
if (file.NoKill)
|
||||
flags[3] = 'N';
|
||||
if (file.Announced)
|
||||
flags[4] = 'A';
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||
sprintf(flags, "---");
|
||||
if (fdb.Deleted)
|
||||
flags[0] = 'D';
|
||||
if (fdb.NoKill)
|
||||
flags[1] = 'N';
|
||||
if (fdb.Announced)
|
||||
flags[2] = 'A';
|
||||
|
||||
if (file.TicAreaCRC) {
|
||||
/*
|
||||
* Fill the default answer
|
||||
*/
|
||||
sprintf(ticarea, "Not found");
|
||||
fseek(pTic, tichdr.hdrsize, SEEK_SET);
|
||||
while (fread(&tic, tichdr.recsize, 1, pTic)) {
|
||||
if (StringCRC32(tic.Name) == file.TicAreaCRC) {
|
||||
sprintf(ticarea, "%s", tic.Name);
|
||||
break;
|
||||
}
|
||||
fseek(pTic, tichdr.syssize, SEEK_CUR);
|
||||
}
|
||||
} else {
|
||||
sprintf(ticarea, "N/A");
|
||||
}
|
||||
|
||||
file.LName[COLS - 63] = '\0';
|
||||
printf("%-12s %5ld %s %4ld %s %-20s %s\n",
|
||||
file.Name, (long)(file.Size / 1024), StrDateDMY(file.FileDate),
|
||||
(long)(file.TimesDL + file.TimesFTP + file.TimesReq), flags, ticarea, file.LName);
|
||||
fdb.LName[COLS - 63] = '\0';
|
||||
printf("%-12s %5ld %s %4ld %s %-20s %s\n", fdb.Name, (long)(fdb.Size / 1024), StrDateDMY(fdb.FileDate),
|
||||
(long)(fdb.TimesDL), flags, fdb.TicArea, fdb.LName);
|
||||
fcount++;
|
||||
fsize = fsize + file.Size;
|
||||
fsize = fsize + fdb.Size;
|
||||
}
|
||||
fsize = fsize / 1024;
|
||||
|
||||
@@ -196,20 +179,25 @@ void ListFileAreas(int Area)
|
||||
/*
|
||||
* Open the file database, create new one if it doesn't exist.
|
||||
*/
|
||||
sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), i);
|
||||
sprintf(fAreas, "%s/fdb/file%d.data", getenv("MBSE_ROOT"), i);
|
||||
if ((pFile = fopen(fAreas, "r+")) == NULL) {
|
||||
Syslog('!', "Creating new %s", fAreas);
|
||||
if ((pFile = fopen(fAreas, "a+")) == NULL) {
|
||||
WriteError("$Can't create %s", fAreas);
|
||||
die(MBERR_GENERAL);
|
||||
}
|
||||
fdbhdr.hdrsize = sizeof(fdbhdr);
|
||||
fdbhdr.recsize = sizeof(fdb);
|
||||
fwrite(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
} else {
|
||||
fread(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
}
|
||||
|
||||
fcount = 0;
|
||||
fsize = 0L;
|
||||
while (fread(&file, sizeof(file), 1, pFile) == 1) {
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||
fcount++;
|
||||
fsize = fsize + file.Size;
|
||||
fsize = fsize + fdb.Size;
|
||||
}
|
||||
fsize = fsize / 1048576;
|
||||
tcount += fcount;
|
||||
|
@@ -46,10 +46,11 @@ extern int do_quiet; /* Suppress screen output */
|
||||
*/
|
||||
void Move(int From, int To, char *File)
|
||||
{
|
||||
char *frompath, *topath, *temp1, *temp2, *fromlink, *tolink, *fromthumb, *tothumb;
|
||||
struct FILERecord fdb;
|
||||
FILE *fp1, *fp2;
|
||||
int rc = FALSE, Found = FALSE;
|
||||
char *frompath, *topath, *temp1, *temp2, *fromlink, *tolink, *fromthumb, *tothumb;
|
||||
struct FILE_recordhdr f_dbhdr;
|
||||
struct FILE_record f_db;
|
||||
FILE *fp1, *fp2;
|
||||
int rc = FALSE, Found = FALSE;
|
||||
|
||||
IsDoing("Move file");
|
||||
colour(LIGHTRED, BLACK);
|
||||
@@ -87,11 +88,13 @@ void Move(int From, int To, char *File)
|
||||
* Find the file in the "from" area, check LFN and 8.3 names.
|
||||
*/
|
||||
temp1 = calloc(PATH_MAX, sizeof(char));
|
||||
sprintf(temp1, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), From);
|
||||
sprintf(temp1, "%s/fdb/file%d.data", getenv("MBSE_ROOT"), From);
|
||||
if ((fp1 = fopen(temp1, "r")) == NULL)
|
||||
die(MBERR_GENERAL);
|
||||
while (fread(&fdb, sizeof(fdb), 1, fp1) == 1) {
|
||||
if ((strcmp(fdb.LName, File) == 0) || strcmp(fdb.Name, File) == 0) {
|
||||
fread(&f_dbhdr, sizeof(fdbhdr), 1, fp1);
|
||||
|
||||
while (fread(&f_db, f_dbhdr.recsize, 1, fp1) == 1) {
|
||||
if ((strcmp(f_db.LName, File) == 0) || strcmp(f_db.Name, File) == 0) {
|
||||
Found = TRUE;
|
||||
break;
|
||||
}
|
||||
@@ -107,13 +110,13 @@ void Move(int From, int To, char *File)
|
||||
|
||||
frompath = xstrcpy(area.Path);
|
||||
frompath = xstrcat(frompath, (char *)"/");
|
||||
frompath = xstrcat(frompath, fdb.Name);
|
||||
frompath = xstrcat(frompath, f_db.Name);
|
||||
fromlink = xstrcpy(area.Path);
|
||||
fromlink = xstrcat(fromlink, (char *)"/");
|
||||
fromlink = xstrcat(fromlink, fdb.LName);
|
||||
fromlink = xstrcat(fromlink, f_db.LName);
|
||||
fromthumb = xstrcpy(area.Path);
|
||||
fromthumb = xstrcat(fromthumb, (char *)"/.");
|
||||
fromthumb = xstrcat(fromthumb, fdb.Name);
|
||||
fromthumb = xstrcat(fromthumb, f_db.Name);
|
||||
|
||||
/*
|
||||
* Check Destination area
|
||||
@@ -139,13 +142,13 @@ void Move(int From, int To, char *File)
|
||||
|
||||
topath = xstrcpy(area.Path);
|
||||
topath = xstrcat(topath, (char *)"/");
|
||||
topath = xstrcat(topath, fdb.Name);
|
||||
topath = xstrcat(topath, f_db.Name);
|
||||
tolink = xstrcpy(area.Path);
|
||||
tolink = xstrcat(tolink, (char *)"/");
|
||||
tolink = xstrcat(tolink, fdb.LName);
|
||||
tolink = xstrcat(tolink, f_db.LName);
|
||||
tothumb = xstrcpy(area.Path);
|
||||
tothumb = xstrcat(tothumb, (char *)"/.");
|
||||
tothumb = xstrcat(tothumb, fdb.Name);
|
||||
tothumb = xstrcat(tothumb, f_db.Name);
|
||||
|
||||
if (file_exist(topath, F_OK) == 0) {
|
||||
WriteError("File %s already exists in area %d", File, To);
|
||||
@@ -155,23 +158,25 @@ void Move(int From, int To, char *File)
|
||||
}
|
||||
|
||||
temp2 = calloc(PATH_MAX, sizeof(char));
|
||||
sprintf(temp2, "%s/fdb/fdb%d.temp", getenv("MBSE_ROOT"), From);
|
||||
sprintf(temp2, "%s/fdb/file%d.temp", getenv("MBSE_ROOT"), From);
|
||||
|
||||
if ((fp1 = fopen(temp1, "r")) == NULL)
|
||||
die(MBERR_GENERAL);
|
||||
fread(&f_dbhdr, sizeof(fdbhdr), 1, fp1);
|
||||
if ((fp2 = fopen(temp2, "a+")) == NULL)
|
||||
die(MBERR_GENERAL);
|
||||
fwrite(&f_dbhdr, f_dbhdr.hdrsize, 1, fp2);
|
||||
|
||||
/*
|
||||
* Search the file if the From area, if found, the
|
||||
* temp database holds all records except the moved
|
||||
* file.
|
||||
*/
|
||||
while (fread(&fdb, sizeof(fdb), 1, fp1) == 1) {
|
||||
if (strcmp(fdb.LName, File) && strcmp(fdb.Name, File))
|
||||
fwrite(&fdb, sizeof(fdb), 1, fp2);
|
||||
while (fread(&f_db, f_dbhdr.recsize, 1, fp1) == 1) {
|
||||
if (strcmp(f_db.LName, File) && strcmp(f_db.Name, File))
|
||||
fwrite(&f_db, f_dbhdr.recsize, 1, fp2);
|
||||
else {
|
||||
rc = AddFile(fdb, To, topath, frompath, tolink);
|
||||
rc = AddFile(f_db, To, topath, frompath, tolink);
|
||||
if (rc) {
|
||||
unlink(fromlink);
|
||||
unlink(frompath);
|
||||
|
@@ -88,8 +88,8 @@ void PackFileBase(void)
|
||||
}
|
||||
Marker();
|
||||
|
||||
sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), i);
|
||||
sprintf(fTmp, "%s/fdb/fdb%d.temp", getenv("MBSE_ROOT"), i);
|
||||
sprintf(fAreas, "%s/fdb/file%d.data", getenv("MBSE_ROOT"), i);
|
||||
sprintf(fTmp, "%s/fdb/file%d.temp", getenv("MBSE_ROOT"), i);
|
||||
|
||||
if ((pFile = fopen(fAreas, "r")) == NULL) {
|
||||
Syslog('!', "Creating new %s", fAreas);
|
||||
@@ -97,37 +97,43 @@ void PackFileBase(void)
|
||||
WriteError("$Can't create %s", fAreas);
|
||||
die(MBERR_GENERAL);
|
||||
}
|
||||
fdbhdr.hdrsize = sizeof(fdbhdr);
|
||||
fdbhdr.recsize = sizeof(fdb);
|
||||
fwrite(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
} else {
|
||||
fread(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
}
|
||||
|
||||
if ((fp = fopen(fTmp, "a+")) == NULL) {
|
||||
WriteError("$Can't create %s", fTmp);
|
||||
die(MBERR_GENERAL);
|
||||
}
|
||||
fwrite(&fdbhdr, fdbhdr.hdrsize, 1, fp);
|
||||
|
||||
while (fread(&file, sizeof(file), 1, pFile) == 1) {
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||
|
||||
iTotal++;
|
||||
|
||||
if ((!file.Deleted) && (!file.Double) && (strcmp(file.Name, "") != 0)) {
|
||||
fwrite(&file, sizeof(file), 1, fp);
|
||||
if ((!fdb.Deleted) && (!fdb.Double) && (strcmp(fdb.Name, "") != 0)) {
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, fp);
|
||||
} else {
|
||||
iRemoved++;
|
||||
if (file.Double) {
|
||||
Syslog('+', "Removed double record file \"%s\" from area %d", file.LName, i);
|
||||
if (fdb.Double) {
|
||||
Syslog('+', "Removed double record file \"%s\" from area %d", fdb.LName, i);
|
||||
} else {
|
||||
Syslog('+', "Removed file \"%s\" from area %d", file.LName, i);
|
||||
sprintf(fn, "%s/%s", area.Path, file.LName);
|
||||
Syslog('+', "Removed file \"%s\" from area %d", fdb.LName, i);
|
||||
sprintf(fn, "%s/%s", area.Path, fdb.LName);
|
||||
rc = unlink(fn);
|
||||
if (rc && (errno != ENOENT))
|
||||
Syslog('+', "Unlink %s failed, result %d", fn, rc);
|
||||
sprintf(fn, "%s/%s", area.Path, file.Name);
|
||||
sprintf(fn, "%s/%s", area.Path, fdb.Name);
|
||||
rc = unlink(fn);
|
||||
if (rc && (errno != ENOENT))
|
||||
Syslog('+', "Unlink %s failed, result %d", fn, rc);
|
||||
/*
|
||||
* If a dotted version (thumbnail) exists, remove it silently
|
||||
*/
|
||||
sprintf(fn, "%s/.%s", area.Path, file.LName);
|
||||
sprintf(fn, "%s/.%s", area.Path, fdb.Name);
|
||||
unlink(fn);
|
||||
}
|
||||
do_index = TRUE;
|
||||
|
@@ -43,13 +43,13 @@ extern int do_index; /* Reindex filebases */
|
||||
|
||||
typedef struct _fdbs {
|
||||
struct _fdbs *next;
|
||||
struct FILERecord filrec;
|
||||
struct FILE_record filrec;
|
||||
} fdbs;
|
||||
|
||||
|
||||
|
||||
void fill_fdbs(struct FILERecord, fdbs **);
|
||||
void fill_fdbs(struct FILERecord filrec, fdbs **fap)
|
||||
void fill_fdbs(struct FILE_record, fdbs **);
|
||||
void fill_fdbs(struct FILE_record filrec, fdbs **fap)
|
||||
{
|
||||
fdbs *tmp;
|
||||
|
||||
@@ -166,8 +166,8 @@ void SortFileBase(int Area)
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), Area);
|
||||
sprintf(fTmp, "%s/fdb/fdb%d.temp", getenv("MBSE_ROOT"), Area);
|
||||
sprintf(fAreas, "%s/fdb/file%d.data", getenv("MBSE_ROOT"), Area);
|
||||
sprintf(fTmp, "%s/fdb/file%d.temp", getenv("MBSE_ROOT"), Area);
|
||||
|
||||
if ((pFile = fopen(fAreas, "r")) == NULL) {
|
||||
Syslog('!', "Creating new %s", fAreas);
|
||||
@@ -175,20 +175,26 @@ void SortFileBase(int Area)
|
||||
WriteError("$Can't create %s", fAreas);
|
||||
die(MBERR_GENERAL);
|
||||
}
|
||||
fdbhdr.hdrsize = sizeof(fdbhdr);
|
||||
fdbhdr.recsize = sizeof(fdb);
|
||||
fwrite(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
} else {
|
||||
fread(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||
}
|
||||
|
||||
if ((fp = fopen(fTmp, "a+")) == NULL) {
|
||||
WriteError("$Can't create %s", fTmp);
|
||||
die(MBERR_GENERAL);
|
||||
}
|
||||
fwrite(&fdbhdr, fdbhdr.hdrsize, 1, fp);
|
||||
|
||||
/*
|
||||
* Fill the sort array
|
||||
*/
|
||||
while (fread(&file, sizeof(file), 1, pFile) == 1) {
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||
iTotal++;
|
||||
fill_fdbs(file, &fdx);
|
||||
Syslog('f', "Adding %s", file.LName);
|
||||
fill_fdbs(fdb, &fdx);
|
||||
Syslog('f', "Adding %s", fdb.LName);
|
||||
}
|
||||
|
||||
sort_fdbs(&fdx);
|
||||
@@ -198,7 +204,7 @@ void SortFileBase(int Area)
|
||||
*/
|
||||
for (tmp = fdx; tmp; tmp = tmp->next) {
|
||||
Syslog('f', "Sorted %s", tmp->filrec.LName);
|
||||
fwrite(&tmp->filrec, sizeof(file), 1, fp);
|
||||
fwrite(&tmp->filrec, fdbhdr.recsize, 1, fp);
|
||||
}
|
||||
tidy_fdbs(&fdx);
|
||||
|
||||
|
@@ -299,11 +299,10 @@ int UnpackFile(char *File)
|
||||
|
||||
|
||||
/*
|
||||
* Add file to the BBS. The file is in the current
|
||||
* directory. The fdb record already has all needed
|
||||
* information.
|
||||
* Add file to the BBS. The file is in the current directory.
|
||||
* The f_db record already has all needed information.
|
||||
*/
|
||||
int AddFile(struct FILERecord fdb, int Area, char *DestPath, char *FromPath, char *LinkPath)
|
||||
int AddFile(struct FILE_record f_db, int Area, char *DestPath, char *FromPath, char *LinkPath)
|
||||
{
|
||||
char *temp1, *temp2;
|
||||
FILE *fp1, *fp2;
|
||||
@@ -316,9 +315,9 @@ int AddFile(struct FILERecord fdb, int Area, char *DestPath, char *FromPath, cha
|
||||
mkdirs(DestPath, 0775);
|
||||
|
||||
if (file_exist(DestPath, F_OK) == 0) {
|
||||
WriteError("File %s already exists in area %d", fdb.Name, Area);
|
||||
WriteError("File %s already exists in area %d", f_db.Name, Area);
|
||||
if (!do_quiet)
|
||||
printf("\nFile %s already exists in area %d\n", fdb.Name, Area);
|
||||
printf("\nFile %s already exists in area %d\n", f_db.Name, Area);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -341,33 +340,34 @@ int AddFile(struct FILERecord fdb, int Area, char *DestPath, char *FromPath, cha
|
||||
|
||||
temp1 = calloc(PATH_MAX, sizeof(char));
|
||||
temp2 = calloc(PATH_MAX, sizeof(char));
|
||||
sprintf(temp1, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), Area);
|
||||
sprintf(temp2, "%s/fdb/fdb%d.temp", getenv("MBSE_ROOT"), Area);
|
||||
sprintf(temp1, "%s/fdb/file%d.data", getenv("MBSE_ROOT"), Area);
|
||||
sprintf(temp2, "%s/fdb/file%d.temp", getenv("MBSE_ROOT"), Area);
|
||||
|
||||
fp1 = fopen(temp1, "r+");
|
||||
fread(&fdbhdr, sizeof(fdbhdr.hdrsize), 1, fp1);
|
||||
fseek(fp1, 0, SEEK_END);
|
||||
if (ftell(fp1) == 0) {
|
||||
if (ftell(fp1) == fdbhdr.hdrsize) {
|
||||
/*
|
||||
* No records yet
|
||||
*/
|
||||
fwrite(&fdb, sizeof(fdb), 1, fp1);
|
||||
fwrite(&f_db, fdbhdr.recsize, 1, fp1);
|
||||
fclose(fp1);
|
||||
} else {
|
||||
/*
|
||||
* Files are already there. Find the right spot.
|
||||
*/
|
||||
fseek(fp1, 0, SEEK_SET);
|
||||
fseek(fp1, fdbhdr.hdrsize, SEEK_SET);
|
||||
|
||||
Insert = 0;
|
||||
do {
|
||||
if (fread(&file, sizeof(file), 1, fp1) != 1)
|
||||
if (fread(&fdb, fdbhdr.recsize, 1, fp1) != 1)
|
||||
Done = TRUE;
|
||||
if (!Done) {
|
||||
if (strcmp(fdb.LName, file.LName) == 0) {
|
||||
if (strcmp(f_db.LName, fdb.LName) == 0) {
|
||||
Found = TRUE;
|
||||
Insert++;
|
||||
} else {
|
||||
if (strcmp(fdb.LName, file.LName) < 0)
|
||||
if (strcmp(f_db.LName, fdb.LName) < 0)
|
||||
Found = TRUE;
|
||||
else
|
||||
Insert++;
|
||||
@@ -380,33 +380,34 @@ int AddFile(struct FILERecord fdb, int Area, char *DestPath, char *FromPath, cha
|
||||
WriteError("Can't create %s", temp2);
|
||||
return FALSE;
|
||||
}
|
||||
fwrite(&fdbhdr, fdbhdr.hdrsize, 1, fp2);
|
||||
fseek(fp1, fdbhdr.hdrsize, SEEK_SET);
|
||||
|
||||
fseek(fp1, 0, SEEK_SET);
|
||||
/*
|
||||
* Copy until the insert point
|
||||
*/
|
||||
for (i = 0; i < Insert; i++) {
|
||||
fread(&file, sizeof(file), 1, fp1);
|
||||
fread(&fdb, fdbhdr.recsize, 1, fp1);
|
||||
/*
|
||||
* If we are importing a file with the same name,
|
||||
* skip the original record and put the new one in place.
|
||||
*/
|
||||
if (strcmp(file.LName, fdb.LName) != 0)
|
||||
fwrite(&file, sizeof(file), 1, fp2);
|
||||
if (strcmp(fdb.LName, f_db.LName) != 0)
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, fp2);
|
||||
}
|
||||
|
||||
if (area.AddAlpha)
|
||||
fwrite(&fdb, sizeof(fdb), 1, fp2);
|
||||
fwrite(&f_db, fdbhdr.recsize, 1, fp2);
|
||||
|
||||
/*
|
||||
* Append the rest of the records
|
||||
*/
|
||||
while (fread(&file, sizeof(file), 1, fp1) == 1) {
|
||||
if (strcmp(file.LName, fdb.LName) != 0)
|
||||
fwrite(&file, sizeof(file), 1, fp2);
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, fp1) == 1) {
|
||||
if (strcmp(fdb.LName, f_db.LName) != 0)
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, fp2);
|
||||
}
|
||||
if (!area.AddAlpha)
|
||||
fwrite(&fdb, sizeof(fdb), 1, fp2);
|
||||
fwrite(&f_db, fdbhdr.recsize, 1, fp2);
|
||||
fclose(fp1);
|
||||
fclose(fp2);
|
||||
|
||||
@@ -423,7 +424,7 @@ int AddFile(struct FILERecord fdb, int Area, char *DestPath, char *FromPath, cha
|
||||
* Append file record
|
||||
*/
|
||||
fseek(fp1, 0, SEEK_END);
|
||||
fwrite(&fdb, sizeof(fdb), 1, fp1);
|
||||
fwrite(&f_db, fdbhdr.recsize, 1, fp1);
|
||||
fclose(fp1);
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ void Help(void); /* Show help screen */
|
||||
void Marker(void); /* Eyecatcher */
|
||||
void DeleteVirusWork(void); /* Delete unarc directory */
|
||||
int UnpackFile(char *File); /* Unpack archive */
|
||||
int AddFile(struct FILERecord, int, char *, char *, char *);
|
||||
int AddFile(struct FILE_record, int, char *, char *, char *);
|
||||
int CheckFDB(int, char *); /* Check FDB of area */
|
||||
int LoadAreaRec(int); /* Load Area record */
|
||||
|
||||
|
@@ -74,7 +74,6 @@ int ProcessTic(fa_list *sbl)
|
||||
unsigned long crc, crc2, Kb;
|
||||
sysconnect Link;
|
||||
FILE *fp;
|
||||
long FwdCost = 0, FwdSize = 0;
|
||||
struct utimbuf ut;
|
||||
int BBS_Imp = FALSE, DidBanner = FALSE;
|
||||
faddr *p_from;
|
||||
@@ -314,63 +313,14 @@ int ProcessTic(fa_list *sbl)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the cost of this file
|
||||
*/
|
||||
T_File.Size = TIC.FileSize;
|
||||
T_File.SizeKb = TIC.FileSize / 1024;
|
||||
if ((fgroup.UnitCost) || (TIC.TicIn.Cost))
|
||||
TIC.Charge = TRUE;
|
||||
else
|
||||
TIC.Charge = FALSE;
|
||||
|
||||
if (TIC.Charge) {
|
||||
/*
|
||||
* Calculate our filetransfer cost.
|
||||
*/
|
||||
FwdCost = fgroup.UnitCost;
|
||||
FwdSize = fgroup.UnitSize;
|
||||
|
||||
/*
|
||||
* If FwdSize <> 0 then calculate per size, else charge for each file.
|
||||
*/
|
||||
if (FwdSize)
|
||||
TIC.FileCost = ((TIC.FileSize / 1024) / FwdSize) * FwdCost;
|
||||
else
|
||||
TIC.FileCost = FwdCost;
|
||||
|
||||
if (TIC.TicIn.Cost)
|
||||
TIC.FileCost += TIC.TicIn.Cost;
|
||||
|
||||
if (fgroup.AddProm)
|
||||
TIC.FileCost += (TIC.FileCost * fgroup.AddProm / 1000);
|
||||
|
||||
if (fgroup.DivideCost) {
|
||||
/*
|
||||
* If not a passthru area, we are a link too.
|
||||
*/
|
||||
if (DownLinks)
|
||||
TIC.FileCost = TIC.FileCost / (DownLinks + 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* At least charge one unit.
|
||||
*/
|
||||
if (!TIC.FileCost)
|
||||
TIC.FileCost = 1;
|
||||
|
||||
Syslog('+', "The file cost will be %ld", TIC.FileCost);
|
||||
}
|
||||
|
||||
/*
|
||||
* Update the uplink's counters.
|
||||
*/
|
||||
Kb = TIC.FileSize / 1024;
|
||||
if (SearchNode(TIC.Aka)) {
|
||||
if (TIC.TicIn.Cost && nodes.Billing) {
|
||||
nodes.Debet -= TIC.TicIn.Cost;
|
||||
Syslog('f', "Uplink cost %ld, debet %ld", TIC.TicIn.Cost, nodes.Debet);
|
||||
}
|
||||
StatAdd(&nodes.FilesRcvd, 1L);
|
||||
StatAdd(&nodes.F_KbRcvd, Kb);
|
||||
UpdateNode();
|
||||
@@ -727,7 +677,6 @@ int ProcessTic(fa_list *sbl)
|
||||
strncpy(T_File.Name, TIC.NewFile, 12);
|
||||
strncpy(T_File.LName, TIC.NewFullName, 80);
|
||||
T_File.Fdate = TIC.FileDate;
|
||||
T_File.Cost = TIC.TicIn.Cost;
|
||||
Add_ToBeRep();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user