Fixes for malformatted file description lines with tic processing

This commit is contained in:
Michiel Broek
2002-05-01 14:40:45 +00:00
parent eb93569b53
commit 7e56a3b95a
9 changed files with 119 additions and 87 deletions

View File

@@ -63,7 +63,7 @@ extern int do_pack; /* Pack filebase */
void Check(void)
{
FILE *pAreas, *pFile;
int i, iAreas, iAreasNew = 0, Fix;
int i, iAreas, iAreasNew = 0, Fix, inArea;
int iTotal = 0, iErrors = 0;
char *sAreas, *fAreas, *newdir, *temp;
DIR *dp;
@@ -193,9 +193,11 @@ void Check(void)
* Now start checking the files in the filedatabase
* against the contents of the directory.
*/
inArea = 0;
while (fread(&file, sizeof(file), 1, pFile) == 1) {
iTotal++;
inArea++;
sprintf(newdir, "%s/%s", area.Path, file.LName);
if (file_exist(newdir, R_OK)) {
@@ -248,6 +250,8 @@ void Check(void)
}
}
}
if (inArea == 0)
Syslog('+', "Warning: area %d (%s) is empty", i, area.Name);
/*
* Check files in the directory against the database.

View File

@@ -225,9 +225,6 @@ void Kill(void)
unlink(sTemp);
chmod(fAreas, 006600);
}
if (!FilesLeft) {
Syslog('+', "Warning: area %d (%s) is empty", i, area.Name);
}
} else
fclose(pFile);

View File

@@ -132,8 +132,26 @@ void Move(int From, int To, char *File)
while (fread(&fdb, sizeof(fdb), 1, fp1) == 1) {
if (strcmp(fdb.LName, File))
fwrite(&fdb, sizeof(fdb), 1, fp2);
else
else {
rc = AddFile(fdb, To, topath, frompath);
if (rc) {
/*
* Try to move thumbnail if it exists
*/
unlink(frompath);
free(frompath);
free(topath);
frompath = xstrcpy(area.Path);
frompath = xstrcat(frompath, (char *)"/.");
frompath = xstrcat(frompath, File);
topath = xstrcpy(area.Path);
topath = xstrcat(topath, (char *)"/.");
topath = xstrcat(topath, File);
if (file_exist(frompath, R_OK) == 0) {
file_mv(frompath, topath);
}
}
}
}
fclose(fp1);
fclose(fp2);
@@ -149,7 +167,6 @@ void Move(int From, int To, char *File)
WriteError("$Can't unlink %s", temp1);
unlink(temp2);
}
unlink(frompath);
colour(CYAN, BLACK);
} else {
/*

View File

@@ -579,9 +579,7 @@ int ProcessTic(fa_list *sbl)
if (!Get_File_Id()) {
if (TIC.TicIn.TotLDesc > 2) {
for (i = 0; i < TIC.TicIn.TotLDesc; i++) {
strcpy(temp1, TIC.TicIn.LDesc[i]);
temp1[48] = '\0';
strcpy(TIC.File_Id[i], temp1);
strncpy(TIC.File_Id[i], TIC.TicIn.LDesc[i], 48);
}
TIC.File_Id_Ct = TIC.TicIn.TotLDesc;
} else {
@@ -599,14 +597,18 @@ int ProcessTic(fa_list *sbl)
j = 48;
while (TDesc[j] != ' ')
j--;
strncat(TIC.File_Id[TIC.File_Id_Ct], TDesc, j);
strncpy(TIC.File_Id[TIC.File_Id_Ct], TDesc, j);
Syslog('f', "%2d/%2d: \"%s\"", TIC.File_Id_Ct, j, TIC.File_Id[TIC.File_Id_Ct]);
TIC.File_Id_Ct++;
k = strlen(TDesc);
j++; /* Correct space */
for (i = 0; i <= k; i++, j++)
TDesc[i] = TDesc[j];
if (TIC.File_Id_Ct == 23)
break;
}
strcpy(TIC.File_Id[TIC.File_Id_Ct], TDesc);
strncpy(TIC.File_Id[TIC.File_Id_Ct], TDesc, 48);
Syslog('f', "%2d/%2d: \"%s\"", TIC.File_Id_Ct, strlen(TIC.File_Id[TIC.File_Id_Ct]), TIC.File_Id[TIC.File_Id_Ct]);
TIC.File_Id_Ct++;
}
}

View File

@@ -165,7 +165,7 @@ int LoadTic(char *inb, char *tfn)
{
FILE *tfp;
char *Temp, *Temp2, *Buf, *Log = NULL;
int i, j, rc;
int i, j, rc, bufsize;
fa_list *sbl = NULL;
int DescCnt = FALSE;
@@ -184,10 +184,15 @@ int LoadTic(char *inb, char *tfn)
return 1;
}
Temp = calloc(PATH_MAX, sizeof(char));
Buf = calloc(PATH_MAX, sizeof(char));
if (PATH_MAX > 1024)
bufsize = PATH_MAX;
else
bufsize = 1024;
Temp = calloc(bufsize+1, sizeof(char));
Buf = calloc(bufsize+1, sizeof(char));
Syslog('f', "Tic buffersize %d", bufsize);
while ((fgets(Buf, PATH_MAX -1, tfp)) != NULL) {
while ((fgets(Buf, bufsize, tfp)) != NULL) {
/*
* Remove all garbage from the .TIC file.
*/
@@ -200,10 +205,10 @@ int LoadTic(char *inb, char *tfn)
}
Temp[j] = '\0';
if (strlen(Temp) > 255) {
Syslog('+', "Truncating TIC line of %d characters", strlen(Temp));
Temp[255] = '\0';
}
// if (strlen(Temp) > 255) {
// Syslog('+', "Truncating TIC line of %d characters", strlen(Temp));
// Temp[255] = '\0';
// }
Syslog('f', "TIC: %s", Temp);
if (strncasecmp(Temp, "hatch", 5) == 0) {
@@ -251,7 +256,7 @@ int LoadTic(char *inb, char *tfn)
} else if (strncasecmp(Temp, "desc ", 5) == 0) {
if (!DescCnt) {
strncpy(TIC.TicIn.Desc, Temp+5, 255);
strncpy(TIC.TicIn.Desc, Temp+5, 1023);
strncpy(T_File.Desc, TIC.TicIn.Desc, 255);
DescCnt = TRUE;
} else {

View File

@@ -17,7 +17,7 @@ typedef struct _tic_in {
char Created[81]; /* Created text */
char Path[25][81]; /* Travelled path */
int TotPath; /* Nr of pathlines */
char Desc[256]; /* Short description */
char Desc[1024]; /* Short description */
char Magic[21]; /* Magic alias */
char Crc[9]; /* CRC of file */
char Pw[21]; /* Password */

View File

@@ -172,74 +172,80 @@ void ReCalcCrc(char *fn)
int Get_File_Id()
{
char *temp;
char Desc[256];
FILE *fp;
int i, j, lines = 0;
char *temp;
char Desc[1024];
FILE *fp;
int i, j, lines = 0;
temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/tmp/FILE_ID.DIZ", getenv("MBSE_ROOT"));
temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/tmp/FILE_ID.DIZ", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r")) == NULL) {
sprintf(temp, "%s/tmp/file_id.diz", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r")) == NULL) {
sprintf(temp, "%s/tmp/file_id.diz", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r")) == NULL) {
free(temp);
return FALSE;
free(temp);
return FALSE;
}
}
/*
* Read no more then 25 lines.
*/
while (((fgets(Desc, 1023, fp)) != NULL) && (TIC.File_Id_Ct < 25)) {
lines++;
/*
* Check if the FILE_ID.DIZ is in a normal layout.
* The layout should be max. 10 lines of max. 48 characters.
* We check at 51 characters and if the lines are longer,
* we trash the FILE_ID.DIZ file.
*/
if (strlen(Desc) > 51) {
fclose(fp);
unlink(temp);
for (i = 0; i < 25; i++)
TIC.File_Id[i][0] = '\0';
TIC.File_Id_Ct = 0;
Syslog('f', "FILE_ID.DIZ line %d is %d chars", lines, strlen(Desc));
Syslog('!', "Trashing illegal formatted FILE_ID.DIZ");
free(temp);
return FALSE;
}
if (strlen(Desc) > 0) {
j = 0;
for (i = 0; i < strlen(Desc); i++) {
if (isprint(Desc[i])) {
TIC.File_Id[TIC.File_Id_Ct][j] = Desc[i];
j++;
if (j > 47)
break;
}
}
/*
* Remove trailing spaces
*/
while (j && isspace(TIC.File_Id[TIC.File_Id_Ct][j-1]))
j--;
TIC.File_Id[TIC.File_Id_Ct][j] = '\0';
Syslog('f', "%2d/%2d: \"%s\"", TIC.File_Id_Ct, j, TIC.File_Id[TIC.File_Id_Ct]);
TIC.File_Id_Ct++;
}
}
fclose(fp);
unlink(temp);
free(temp);
/*
* Read no more then 25 lines.
*/
while (((fgets(Desc, 255, fp)) != NULL) && (TIC.File_Id_Ct < 25)) {
lines++;
/*
* Check if the FILE_ID.DIZ is in a normal layout.
* The layout should be max. 10 lines of max. 48 characters.
* We check at 51 characters and if the lines are longer,
* we trash the FILE_ID.DIZ file.
*/
if (strlen(Desc) > 51) {
fclose(fp);
unlink(temp);
TIC.File_Id_Ct = 0;
Syslog('f', "FILE_ID.DIZ line %d is %d chars", lines, strlen(Desc));
Syslog('!', "Trashing illegal formatted FILE_ID.DIZ");
free(temp);
return FALSE;
}
/*
* Strip empty lines at end of FILE_ID.DIZ
*/
while ((strlen(TIC.File_Id[TIC.File_Id_Ct-1]) == 0) && (TIC.File_Id_Ct))
TIC.File_Id_Ct--;
if (strlen(Desc) > 0) {
j = 0;
for (i = 0; i < strlen(Desc); i++) {
if ((Desc[i] >= ' ') || (Desc[i] < 0)) {
TIC.File_Id[TIC.File_Id_Ct][j] = Desc[i];
j++;
}
}
if (j >= 48)
TIC.File_Id[TIC.File_Id_Ct][48] = '\0';
else
TIC.File_Id[TIC.File_Id_Ct][j] = '\0';
TIC.File_Id_Ct++;
}
}
fclose(fp);
unlink(temp);
free(temp);
/*
* Strip empty lines at end of FILE_ID.DIZ
*/
while ((strlen(TIC.File_Id[TIC.File_Id_Ct-1]) == 0) && (TIC.File_Id_Ct))
TIC.File_Id_Ct--;
Syslog('f', "Got %d FILE_ID.DIZ lines", TIC.File_Id_Ct);
if (TIC.File_Id_Ct)
return TRUE;
else
return FALSE;
Syslog('f', "Got %d FILE_ID.DIZ lines", TIC.File_Id_Ct);
if (TIC.File_Id_Ct)
return TRUE;
else
return FALSE;
}