Updates for mbfile check and rearc

This commit is contained in:
Michiel Broek
2004-03-09 21:42:29 +00:00
parent 126eb3a84f
commit 66fb5827e8
13 changed files with 240 additions and 66 deletions

View File

@@ -304,7 +304,7 @@ void Magic_Keepnum(void)
void Magic_UpDateAlias(void)
{
if (GetMagicRec(MG_UPDALIAS, TRUE)) {
UpDateAlias(TIC.TicIn.Area);
magic_update(TIC.TicIn.Area, TIC.NewFile);
MagicResult((char *)"Update Alias");
}
}

View File

@@ -59,16 +59,17 @@ extern int do_pack; /* Pack filebase */
*/
void Check(void)
{
FILE *pAreas, *pFile;
int i, j, iAreas, iAreasNew = 0, Fix, inArea, iTotal = 0, iErrors = 0;
char *sAreas, *fAreas, *newdir, *temp, *mname, *tname;
DIR *dp;
struct dirent *de;
int Found, Update;
char fn[PATH_MAX];
struct stat stb;
struct passwd *pw;
struct group *gr;
FILE *pAreas, *pFile;
int i, j, iAreas, iAreasNew = 0, Fix, inArea, iTotal = 0, iErrors = 0, rc;
char *sAreas, *fAreas, *newdir, *temp, *mname, *tname;
DIR *dp;
struct dirent *de;
int Found, Update;
char fn[PATH_MAX];
struct stat stb;
struct passwd *pw;
struct group *gr;
struct FILEIndex idx;
sAreas = calloc(PATH_MAX, sizeof(char));
fAreas = calloc(PATH_MAX, sizeof(char));
@@ -363,6 +364,17 @@ void Check(void)
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
}
}
if (strlen(fdb.Magic)) {
Syslog('f', "Checking magic %s file %s", fdb.Magic, fdb.Name);
rc = magic_check(fdb.Magic, fdb.Name);
if (rc == -1) {
Syslog('+', "Area %d magic alias %s file %s is invalid", i, fdb.Magic, fdb.Name);
memset(&fdb.Magic, 0, sizeof(fdb.Magic));
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
iErrors++;
}
}
}
if (inArea == 0)
Syslog('+', "Warning: area %d (%s) is empty", i, area.Name);
@@ -438,6 +450,55 @@ void Check(void)
}
fclose(pAreas);
if (!do_quiet) {
printf("\rChecking magic alias names ... \r");
fflush(stdout);
}
if (!strlen(CFG.req_magic)) {
WriteError("No magic filename path configured");
} else {
if ((dp = opendir(CFG.req_magic)) == NULL) {
WriteError("$Can't open directory %s", CFG.req_magic);
} else {
while ((de = readdir(dp))) {
if (de->d_name[0] != '.') {
sprintf(temp, "%s/%s", CFG.req_magic, de->d_name);
if (file_exist(temp, X_OK) == 0) {
Syslog('f', "%s is executable", temp);
} else if (file_exist(temp, R_OK) == 0) {
Syslog('f', "%s is magic alias", temp);
if ((pFile = fopen(temp, "r"))) {
fgets(mname, PATH_MAX -1, pFile);
fclose(pFile);
Striplf(mname);
sprintf(newdir, "%s/etc/request.index", getenv("MBSE_ROOT"));
Found = FALSE;
if ((pFile = fopen(newdir, "r"))) {
while (fread(&idx, sizeof(idx), 1, pFile)) {
if ((strcmp(idx.Name, mname) == 0) || (strcmp(idx.LName, mname) == 0)) {
Found = TRUE;
break;
}
}
fclose(pFile);
}
if (!Found) {
Syslog('+', "Error: magic alias %s (%s) is invalid, removed", de->d_name, mname);
iErrors++;
unlink(temp);
}
}
} else {
Syslog('f', "%s cannot be", temp);
}
}
}
closedir(dp);
}
}
if (!do_quiet) {
printf("\r \r");
fflush(stdout);

View File

@@ -262,6 +262,13 @@ int main(int argc, char **argv)
if (do_check)
Check();
if (do_rearc) {
ReArc(Area, FileName);
if (do_index)
Index();
die(MBERR_OK);
}
if (do_pack)
PackFileBase();
@@ -278,11 +285,6 @@ int main(int argc, char **argv)
die(MBERR_OK);
}
if (do_rearc) {
ReArc(Area, FileName);
die(MBERR_OK);
}
if (do_list) {
ListFileAreas(Area);
die(MBERR_OK);

View File

@@ -38,6 +38,7 @@
extern int do_quiet; /* Suppress screen output */
extern int do_index; /* Rebuild index */
@@ -46,7 +47,7 @@ extern int do_quiet; /* Suppress screen output */
*/
void ReArc(int Area, char *File)
{
char *p, *temp, *linkpath, mask[256];
char *p, *temp, *mname, *linkpath, mask[256];
FILE *fp;
int i, rc = -1, count = 0, errors = 0;
struct utimbuf ut;
@@ -168,15 +169,34 @@ void ReArc(int Area, char *File)
ut.actime = mktime(localtime(&fdb.FileDate));
ut.modtime = mktime(localtime(&fdb.FileDate));
utime(temp, &ut);
/*
* Check if mangled name is changed, and if so update to the
* new name and rename the file on disk.
*/
mname = calloc(PATH_MAX, sizeof(char));
strcpy(mname, fdb.LName);
name_mangle(mname);
if (strcmp(fdb.Name, mname)) {
Syslog('+', "Converted 8.3 name to %s", mname);
strcpy(fdb.Name, mname);
sprintf(mname, "%s/%s", area.Path, fdb.Name);
rename(temp, mname);
strcpy(temp, mname);
}
free(mname);
fseek(fp, - fdbhdr.recsize, SEEK_CUR);
fwrite(&fdb, fdbhdr.recsize, 1, fp);
/*
* Update symbolic link to long filename
*/
sprintf(linkpath, "%s/%s", area.Path, fdb.LName);
symlink(temp, linkpath);
free(linkpath);
if (strlen(fdb.Magic))
magic_update(fdb.Magic, fdb.Name);
do_index = TRUE;
} else {
errors++;
break; // stop when something goes wrong

View File

@@ -666,7 +666,7 @@ int ProcessTic(fa_list *sbl)
*/
if (tic.FileArea) {
if (strlen(TIC.TicIn.Magic))
UpDateAlias(TIC.TicIn.Magic);
magic_update(TIC.TicIn.Magic, TIC.NewFile);
else
Magic_UpDateAlias();

View File

@@ -257,33 +257,3 @@ int Get_File_Id()
}
void UpDateAlias(char *Alias)
{
char *path;
FILE *fp;
Syslog('f', "UpDateAlias(%s) with %s", Alias, TIC.NewFile);
if (!strlen(CFG.req_magic)) {
WriteError("No magic filename path configured");
return;
}
path = xstrcpy(CFG.req_magic);
path = xstrcat(path, (char *)"/");
path = xstrcat(path, Alias);
if ((fp = fopen(path, "w")) == NULL) {
WriteError("$Can't create %s", path);
free(path);
return;
}
fprintf(fp, "%s\n", TIC.NewFile);
fclose(fp);
free(path);
}

View File

@@ -1,6 +1,7 @@
#ifndef _UTIC_H
#define _UTIC_H
/* $Id$ */
char *MakeTicName(void);
int Day_Of_Year(void);
@@ -9,7 +10,6 @@ void DeleteVirusWork(void);
void Bad(char *, ...);
void ReCalcCrc(char *);
int Get_File_Id(void);
void UpDateAlias(char *);
#endif