Bugfixes for mbfile import

This commit is contained in:
Michiel Broek 2003-01-19 14:43:23 +00:00
parent 0ec292293e
commit 24a6fa64a9
2 changed files with 87 additions and 65 deletions

View File

@ -17,6 +17,10 @@ v0.37.01 14-Jan-2003.
mbtask: mbtask:
Added debug logging to find some errors. Added debug logging to find some errors.
mbfile:
In the import function several bugfixes for reading files.bbs.
Fixed upper/lowercase filenames bug with import.
v0.37.00 26-Dec-2002 - 14-Jan-2003 v0.37.00 26-Dec-2002 - 14-Jan-2003

View File

@ -53,10 +53,12 @@ void ImportFiles(int Area)
{ {
char *pwd, *temp, *temp2, *tmpdir, *String, *token, *dest, *unarc, *lname; char *pwd, *temp, *temp2, *tmpdir, *String, *token, *dest, *unarc, *lname;
FILE *fbbs; FILE *fbbs;
int Append = FALSE, Files = 0, rc, i, j = 0, k = 0, x, Doit; DIR *dp;
int Append = FALSE, Files = 0, rc, i, line = 0, pos, x, Doit;
int Imported = 0, Errors = 0, Present = FALSE; int Imported = 0, Errors = 0, Present = FALSE;
struct FILERecord fdb; struct FILERecord fdb;
struct stat statfile; struct stat statfile;
struct dirent *de;
Syslog('-', "Import(%d)", Area); Syslog('-', "Import(%d)", Area);
@ -109,7 +111,7 @@ void ImportFiles(int Area)
Doit = TRUE; Doit = TRUE;
if ((unarc = unpacker(temp)) == NULL) { if ((unarc = unpacker(temp)) == NULL) {
Syslog('+', "Unknown archive format %s", temp); 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"), fdb.Name);
mkdirs(temp2, 0755); mkdirs(temp2, 0755);
if ((rc = file_cp(temp, temp2))) { if ((rc = file_cp(temp, temp2))) {
WriteError("Can't copy file to %s, %s", temp2, strerror(rc)); WriteError("Can't copy file to %s, %s", temp2, strerror(rc));
@ -170,6 +172,8 @@ void ImportFiles(int Area)
} }
Append = FALSE; Append = FALSE;
Present = FALSE; Present = FALSE;
line = 0;
pos = 0;
} }
/* /*
@ -183,27 +187,31 @@ void ImportFiles(int Area)
Present = TRUE; Present = TRUE;
token = strtok(String, " \t"); token = strtok(String, " \t");
strncpy(fdb.LName, token, 80);
/* /*
* Test filename against name on disk, first normal case, * Test filename against name on disk, first normal case,
* then lowercase and finally uppercase. * then lowercase and finally uppercase.
*/ */
sprintf(temp,"%s/%s", pwd, fdb.LName); if ((dp = opendir(pwd)) == NULL) {
if (stat(temp,&statfile) != 0) { WriteError("$Can't open directory %s", pwd);
strncpy(fdb.LName, tl(token), 80); die(MBERR_INIT_ERROR);
sprintf(temp,"%s/%s", pwd, fdb.LName); }
if (stat(temp,&statfile) != 0) { while ((de = readdir(dp))) {
strcpy(fdb.LName, tu(token)); if (strcasecmp(de->d_name, token) == 0) {
if (stat(temp,&statfile) != 0) { /*
WriteError("Can't find file on disk, skipping: %s\n",temp); * Found the right file.
Append = FALSE; */
Present = FALSE; strncpy(fdb.LName, token, 80);
} break;
} }
} }
closedir(dp);
if (Present) { if (strlen(fdb.LName) == 0) {
WriteError("Can't find file on disk, skipping: %s\n", token);
Append = FALSE;
Present = FALSE;
} else {
/* /*
* Create DOS 8.3 filename * Create DOS 8.3 filename
*/ */
@ -211,6 +219,13 @@ void ImportFiles(int Area)
name_mangle(temp2); name_mangle(temp2);
strcpy(fdb.Name, temp2); strcpy(fdb.Name, temp2);
if (strcmp(fdb.LName, fdb.Name) && (rename(fdb.LName, fdb.Name) == 0)) {
Syslog('+', "Renamed %s to %s", fdb.LName, fdb.Name);
}
sprintf(temp, "%s/%s", pwd, fdb.Name);
stat(temp, &statfile);
if (do_annon) if (do_annon)
fdb.Announced = TRUE; fdb.Announced = TRUE;
Syslog('f', "File: %s (%s)", fdb.Name, fdb.LName); Syslog('f', "File: %s (%s)", fdb.Name, fdb.LName);
@ -225,44 +240,45 @@ void ImportFiles(int Area)
token = strtok(NULL, "\0"); token = strtok(NULL, "\0");
i = strlen(token); i = strlen(token);
j = k = 0; line = pos = 0;
for (x = 0; x < i; x++) { for (x = 0; x < i; x++) {
if ((token[x] == '\n') || (token[x] == '\r')) if ((token[x] == '\n') || (token[x] == '\r'))
token[x] = '\0'; token[x] = '\0';
} }
i = strlen(token);
Doit = FALSE; Doit = FALSE;
for (x = 0; x < i; x++) { for (x = 0; x < i; x++) {
if (!Doit) { if (!Doit) {
if (isalnum(token[x])) if (!iscntrl(token[x]) && !isblank(token[x]))
Doit = TRUE; Doit = TRUE;
} }
if (Doit) { if (Doit) {
if (k > 42) { if (pos > 42) {
if (token[x] == ' ') { if (token[x] == ' ') {
fdb.Desc[j][k] = '\0'; fdb.Desc[line][pos] = '\0';
j++; line++;
k = 0; pos = 0;
} else { } else {
if (k == 49) { if (pos == 49) {
fdb.Desc[j][k] = '\0'; fdb.Desc[line][pos] = '\0';
k = 0; pos = 0;
j++; line++;
} }
fdb.Desc[j][k] = token[x]; fdb.Desc[line][pos] = token[x];
k++; pos++;
} }
} else { } else {
fdb.Desc[j][k] = token[x]; fdb.Desc[line][pos] = token[x];
k++; pos++;
} }
if (j == 25) if (line == 25)
break; break;
} }
} }
sprintf(dest, "%s/%s", area.Path, fdb.LName); sprintf(dest, "%s/%s", area.Path, fdb.Name);
sprintf(lname, "%s/%s", area.Path, fdb.Name); sprintf(lname, "%s/%s", area.Path, fdb.LName);
Append = TRUE; Append = TRUE;
fdb.Size = statfile.st_size; fdb.Size = statfile.st_size;
fdb.FileDate = statfile.st_mtime; fdb.FileDate = statfile.st_mtime;
@ -274,43 +290,45 @@ void ImportFiles(int Area)
/* /*
* Add multiple description lines * Add multiple description lines
*/ */
token = strtok(String, "\0"); if (line < 25) {
i = strlen(token); token = strtok(String, "\0");
j++; i = strlen(token);
k = 0; line++;
Doit = FALSE; pos = 0;
for (x = 0; x < i; x++) { Doit = FALSE;
if ((token[x] == '\n') || (token[x] == '\r')) for (x = 0; x < i; x++) {
token[x] = '\0'; if ((token[x] == '\n') || (token[x] == '\r'))
} token[x] = '\0';
for (x = 0; x < i; x++) { }
if (Doit) { for (x = 0; x < i; x++) {
if (k > 42) { if (Doit) {
if (token[x] == ' ') { if (pos > 42) {
fdb.Desc[j][k] = '\0'; if (token[x] == ' ') {
j++; fdb.Desc[line][pos] = '\0';
k = 0; line++;
} else { pos = 0;
if (k == 49) { } else {
fdb.Desc[j][k] = '\0'; if (pos == 49) {
k = 0; fdb.Desc[line][pos] = '\0';
j++; pos = 0;
line++;
}
fdb.Desc[line][pos] = token[x];
pos++;
} }
fdb.Desc[j][k] = token[x]; } else {
k++; fdb.Desc[line][pos] = token[x];
pos++;
} }
if (line == 25)
break;
} else { } else {
fdb.Desc[j][k] = token[x]; /*
k++; * Skip until + or | is found
*/
if ((token[x] == '+') || (token[x] == '|'))
Doit = TRUE;
} }
if (j == 25)
break;
} else {
/*
* Skip until + or | is found
*/
if ((token[x] == '+') || (token[x] == '|'))
Doit = TRUE;
} }
} }
} /* End if new file entry found */ } /* End if new file entry found */