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:
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

View File

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