Added better support for short and long filenames

This commit is contained in:
Michiel Broek
2002-11-23 16:48:54 +00:00
parent 85bd9bcd1e
commit ffe9331fb0
21 changed files with 528 additions and 417 deletions

View File

@@ -57,7 +57,7 @@ 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;
char temp1[PATH_MAX], temp2[PATH_MAX], *fname, *lname;
FILE *fdb, *fdt;
int Keep = 0, DidDelete = FALSE;
fd_list *fdl = NULL;
@@ -142,6 +142,12 @@ int Add_BBS()
return FALSE;
}
chmod(temp2, 0644);
lname = calloc(PATH_MAX, sizeof(char));
sprintf(lname, "%s/%s", TIC.BBSpath, frec.Name);
if (link(temp2, lname)) {
WriteError("$Create link %s to %s failed", lname, temp2);
}
free(lname);
sprintf(fdbtemp, "%s/fdb/fdb%ld.temp", getenv("MBSE_ROOT"), tic.FileArea);
@@ -365,6 +371,9 @@ int Add_BBS()
sprintf(temp2, "%s/%s", area.Path, file.LName);
if (unlink(temp2) != 0)
WriteError("$Can't unlink file %s", temp2);
sprintf(temp2, "%s/%s", area.Path, file.Name);
if (unlink(temp2) != 0)
WriteError("$Can't unlink file %s", temp2);
}
fclose(fdb);
fclose(fdt);

View File

@@ -52,7 +52,7 @@ extern int do_novir; /* Suppress virus check */
void AdoptFile(int Area, char *File, char *Description)
{
FILE *fp;
char *temp, *temp2, *tmpdir, *unarc, *pwd;
char *temp, *temp2, *tmpdir, *unarc, *pwd, *lname;
char Desc[256], TDesc[256];
int IsArchive = FALSE, MustRearc = FALSE, UnPacked = FALSE;
int IsVirus = FALSE, File_Id = FALSE;
@@ -279,8 +279,17 @@ void AdoptFile(int Area, char *File, char *Description)
fflush(stdout);
}
if (AddFile(fdb, Area, temp2, File) == FALSE) {
die(MBERR_GENERAL);
if (strcmp(fdb.Name, fdb.LName)) {
lname = calloc(PATH_MAX, sizeof(char));
sprintf(lname, "%s/%s", area.Path, fdb.Name);
if (AddFile(fdb, Area, temp2, File, lname) == FALSE) {
die(MBERR_GENERAL);
}
free(lname);
} else {
if (AddFile(fdb, Area, temp2, File, NULL) == FALSE) {
die(MBERR_GENERAL);
}
}
Syslog('+', "File %s added to area %d", File, Area);

View File

@@ -67,7 +67,7 @@ void Check(void)
{
FILE *pAreas, *pFile;
int i, iAreas, iAreasNew = 0, Fix, inArea, iTotal = 0, iErrors = 0;
char *sAreas, *fAreas, *newdir, *temp;
char *sAreas, *fAreas, *newdir, *temp, *lname;
DIR *dp;
struct dirent *de;
int Found, Update;
@@ -80,6 +80,7 @@ void Check(void)
fAreas = calloc(PATH_MAX, sizeof(char));
newdir = calloc(PATH_MAX, sizeof(char));
temp = calloc(PATH_MAX, sizeof(char));
lname = calloc(PATH_MAX, sizeof(char));
if (!do_quiet) {
colour(3, 0);
@@ -221,12 +222,25 @@ void Check(void)
strcpy(temp, file.LName);
name_mangle(temp);
sprintf(lname, "%s/%s", area.Path, temp);
if (strcmp(file.Name, temp)) {
Syslog('!', "Converted %s to %s", file.Name, temp);
strncpy(file.Name, temp, 12);
iErrors++;
Update = TRUE;
}
/*
* Check hard link to the short/mangled filename.
*/
if (strcmp(file.Name, file.LName)) {
if (file_exist(lname, F_OK)) {
if (link(newdir, lname)) {
WriteError("$Can't create link %s to %s", lname, newdir);
} else {
Syslog('!', "Created hard link area %d LFN %s to 8.3 %s", i, file.LName, file.Name);
}
}
}
if (file_time(newdir) != file.FileDate) {
Syslog('!', "Date mismatch area %d file %s", i, file.LName);
file.FileDate = file_time(newdir);
@@ -267,7 +281,7 @@ void Check(void)
Found = FALSE;
rewind(pFile);
while (fread(&file, sizeof(file), 1, pFile) == 1) {
if (strcmp(file.LName, de->d_name) == 0) {
if ((strcmp(file.LName, de->d_name) == 0) || (strcmp(file.Name, de->d_name) == 0)) {
if (!Found) {
Found = TRUE;
} else {
@@ -331,6 +345,7 @@ void Check(void)
fflush(stdout);
}
free(lname);
free(temp);
free(newdir);
free(sAreas);

View File

@@ -94,7 +94,7 @@ void Delete(int UnDel, int Area, char *File)
colour(CYAN, BLACK);
while (fread(&fdb, sizeof(fdb), 1, fp) == 1) {
if (! strcmp(fdb.LName, File)) {
if ((! strcmp(fdb.LName, File) || (! strcmp(fdb.Name, File)))) {
if (UnDel && fdb.Deleted) {
fdb.Deleted = FALSE;
Syslog('+', "Marked file %s in area %d for undeletion", File, Area);

View File

@@ -51,7 +51,7 @@ extern int do_novir; /* Suppress virus scanning */
void ImportFiles(int Area)
{
char *pwd, *temp, *temp2, *tmpdir, *String, *token, *dest, *unarc;
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;
int Imported = 0, Errors = 0, Present = FALSE;
@@ -73,6 +73,7 @@ void ImportFiles(int Area)
tmpdir = calloc(PATH_MAX, sizeof(char));
String = calloc(4096, sizeof(char));
dest = calloc(PATH_MAX, sizeof(char));
lname = calloc(PATH_MAX, sizeof(char));
getcwd(pwd, PATH_MAX);
if (CheckFDB(Area, area.Path))
@@ -151,10 +152,19 @@ void ImportFiles(int Area)
printf("Adding \b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
}
if (AddFile(fdb, Area, dest, temp)) {
Imported++;
} else
Errors++;
if (strcmp(fdb.Name, fdb.LName)) {
if (AddFile(fdb, Area, dest, temp, lname)) {
Imported++;
} else {
Errors++;
}
} else {
if (AddFile(fdb, Area, dest, temp, NULL)) {
Imported++;
} else {
Errors++;
}
}
} else {
Errors++;
}
@@ -252,6 +262,7 @@ void ImportFiles(int Area)
}
sprintf(dest, "%s/%s", area.Path, fdb.LName);
sprintf(lname, "%s/%s", area.Path, fdb.Name);
Append = TRUE;
fdb.Size = statfile.st_size;
fdb.FileDate = statfile.st_mtime;
@@ -354,15 +365,23 @@ void ImportFiles(int Area)
printf("Adding \b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
}
if (AddFile(fdb, Area, dest, temp))
Imported++;
else
Errors++;
if (strcmp(fdb.Name, fdb.LName)) {
if (AddFile(fdb, Area, dest, temp, lname))
Imported++;
else
Errors++;
} else {
if (AddFile(fdb, Area, dest, temp, NULL))
Imported++;
else
Errors++;
}
} else {
Errors++;
}
}
free(lname);
free(dest);
free(String);
free(pwd);

View File

@@ -52,10 +52,10 @@ extern int do_quiet; /* Suppress screen output */
*/
void Move(int From, int To, char *File)
{
char *frompath, *topath, *temp1, *temp2;
char *frompath, *topath, *temp1, *temp2, *fromlink, *tolink;
struct FILERecord fdb;
FILE *fp1, *fp2;
int rc = FALSE;
int rc = FALSE, Found = FALSE;
IsDoing("Move file");
colour(LIGHTRED, BLACK);
@@ -88,9 +88,35 @@ void Move(int From, int To, char *File)
}
if (CheckFDB(From, area.Path))
die(MBERR_GENERAL);
/*
* 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);
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) {
Found = TRUE;
break;
}
}
fclose(fp1);
if (!Found) {
WriteError("File %s not found in area %d", File, From);
if (!do_quiet)
printf("File %s not found in area %d\n", File, From);
free(temp1);
die(MBERR_GENERAL);
}
frompath = xstrcpy(area.Path);
frompath = xstrcat(frompath, (char *)"/");
frompath = xstrcat(frompath, File);
frompath = xstrcat(frompath, fdb.LName);
fromlink = xstrcpy(area.Path);
fromlink = xstrcat(fromlink, (char *)"/");
fromlink = xstrcat(fromlink, fdb.Name);
/*
* Check Destination area
@@ -113,13 +139,15 @@ void Move(int From, int To, char *File)
}
if (CheckFDB(To, area.Path))
die(MBERR_GENERAL);
topath = xstrcpy(area.Path);
topath = xstrcat(topath, (char *)"/");
topath = xstrcat(topath, File);
topath = xstrcat(topath, fdb.LName);
tolink = xstrcpy(area.Path);
tolink = xstrcat(tolink, (char *)"/");
tolink = xstrcat(tolink, fdb.Name);
temp1 = calloc(PATH_MAX, sizeof(char));
temp2 = calloc(PATH_MAX, sizeof(char));
sprintf(temp1, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), From);
sprintf(temp2, "%s/fdb/fdb%d.temp", getenv("MBSE_ROOT"), From);
if ((fp1 = fopen(temp1, "r")) == NULL)
@@ -133,11 +161,19 @@ void Move(int From, int To, char *File)
* file.
*/
while (fread(&fdb, sizeof(fdb), 1, fp1) == 1) {
if (strcmp(fdb.LName, File))
if (strcmp(fdb.LName, File) && strcmp(fdb.Name, File))
fwrite(&fdb, sizeof(fdb), 1, fp2);
else {
rc = AddFile(fdb, To, topath, frompath);
if (strcmp(fdb.Name, fdb.LName))
rc = AddFile(fdb, To, topath, frompath, tolink);
else
rc = AddFile(fdb, To, topath, frompath, NULL);
if (rc) {
/*
* Remove old 8.3 name
*/
if (strcmp(fdb.Name, fdb.LName))
unlink(fromlink);
/*
* Try to move thumbnail if it exists
*/
@@ -189,7 +225,9 @@ void Move(int From, int To, char *File)
free(temp1);
free(temp2);
free(frompath);
free(fromlink);
free(topath);
free(tolink);
}

View File

@@ -53,113 +53,116 @@ extern int do_index; /* Reindex filebases */
*/
void PackFileBase(void)
{
FILE *fp, *pAreas, *pFile;
int i, iAreas, iAreasNew = 0, rc;
int iTotal = 0, iRemoved = 0;
char *sAreas, *fAreas, *fTmp, fn[PATH_MAX];
FILE *fp, *pAreas, *pFile;
int i, iAreas, iAreasNew = 0, rc, iTotal = 0, iRemoved = 0;
char *sAreas, *fAreas, *fTmp, fn[PATH_MAX];
sAreas = calloc(PATH_MAX, sizeof(char));
fAreas = calloc(PATH_MAX, sizeof(char));
fTmp = calloc(PATH_MAX, sizeof(char));
sAreas = calloc(PATH_MAX, sizeof(char));
fAreas = calloc(PATH_MAX, sizeof(char));
fTmp = calloc(PATH_MAX, sizeof(char));
IsDoing("Pack filebase");
if (!do_quiet) {
colour(3, 0);
printf("Packing file database...\n");
}
IsDoing("Pack filebase");
if (!do_quiet) {
colour(3, 0);
printf("Packing file database...\n");
}
sprintf(sAreas, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
sprintf(sAreas, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
if ((pAreas = fopen (sAreas, "r")) == NULL) {
WriteError("Can't open %s", sAreas);
die(MBERR_INIT_ERROR);
}
if ((pAreas = fopen (sAreas, "r")) == NULL) {
WriteError("Can't open %s", sAreas);
die(MBERR_INIT_ERROR);
}
fread(&areahdr, sizeof(areahdr), 1, pAreas);
fseek(pAreas, 0, SEEK_END);
iAreas = (ftell(pAreas) - areahdr.hdrsize) / areahdr.recsize;
fread(&areahdr, sizeof(areahdr), 1, pAreas);
fseek(pAreas, 0, SEEK_END);
iAreas = (ftell(pAreas) - areahdr.hdrsize) / areahdr.recsize;
for (i = 1; i <= iAreas; i++) {
for (i = 1; i <= iAreas; i++) {
fseek(pAreas, ((i-1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET);
fread(&area, areahdr.recsize, 1, pAreas);
fseek(pAreas, ((i-1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET);
fread(&area, areahdr.recsize, 1, pAreas);
if (area.Available && !area.CDrom) {
if (area.Available && !area.CDrom) {
if (!diskfree(CFG.freespace))
die(MBERR_DISK_FULL);
if (!diskfree(CFG.freespace))
die(MBERR_DISK_FULL);
if (!do_quiet) {
printf("\r%4d => %-44s", i, area.Name);
fflush(stdout);
}
Marker();
sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), i);
sprintf(fTmp, "%s/fdb/fdb%d.temp", 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);
}
}
if ((fp = fopen(fTmp, "a+")) == NULL) {
WriteError("$Can't create %s", fTmp);
die(MBERR_GENERAL);
}
while (fread(&file, sizeof(file), 1, pFile) == 1) {
iTotal++;
if ((!file.Deleted) && (!file.Double) && (strcmp(file.Name, "") != 0)) {
fwrite(&file, sizeof(file), 1, fp);
} else {
iRemoved++;
if (file.Double) {
Syslog('+', "Removed double record file \"%s\" from area %d", file.LName, i);
} else {
Syslog('+', "Removed file \"%s\" from area %d", file.LName, i);
sprintf(fn, "%s/%s", area.Path, file.LName);
rc = unlink(fn);
if (rc)
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);
unlink(fn);
}
do_index = TRUE;
}
}
fclose(fp);
fclose(pFile);
if ((rename(fTmp, fAreas)) == 0) {
unlink(fTmp);
chmod(fAreas, 00660);
}
iAreasNew++;
} /* if area.Available */
}
fclose(pAreas);
Syslog('+', "Pack Areas [%5d] Files [%5d] Removed [%5d]", iAreasNew, iTotal, iRemoved);
if (!do_quiet) {
printf("\r \r");
if (!do_quiet) {
printf("\r%4d => %-44s", i, area.Name);
fflush(stdout);
}
}
Marker();
free(fTmp);
free(sAreas);
free(fAreas);
sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), i);
sprintf(fTmp, "%s/fdb/fdb%d.temp", 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);
}
}
if ((fp = fopen(fTmp, "a+")) == NULL) {
WriteError("$Can't create %s", fTmp);
die(MBERR_GENERAL);
}
while (fread(&file, sizeof(file), 1, pFile) == 1) {
iTotal++;
if ((!file.Deleted) && (!file.Double) && (strcmp(file.Name, "") != 0)) {
fwrite(&file, sizeof(file), 1, fp);
} else {
iRemoved++;
if (file.Double) {
Syslog('+', "Removed double record file \"%s\" from area %d", file.LName, i);
} else {
Syslog('+', "Removed file \"%s\" from area %d", file.LName, i);
sprintf(fn, "%s/%s", area.Path, file.LName);
rc = unlink(fn);
if (rc)
Syslog('+', "Unlink %s failed, result %d", fn, rc);
sprintf(fn, "%s/%s", area.Path, file.Name);
rc = unlink(fn);
if (rc)
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);
unlink(fn);
}
do_index = TRUE;
}
}
fclose(fp);
fclose(pFile);
if ((rename(fTmp, fAreas)) == 0) {
unlink(fTmp);
chmod(fAreas, 00660);
}
iAreasNew++;
} /* if area.Available */
}
fclose(pAreas);
Syslog('+', "Pack Areas [%5d] Files [%5d] Removed [%5d]", iAreasNew, iTotal, iRemoved);
if (!do_quiet) {
printf("\r \r");
fflush(stdout);
}
free(fTmp);
free(sAreas);
free(fAreas);
}

View File

@@ -309,12 +309,16 @@ int UnpackFile(char *File)
* directory. The fdb record already has all needed
* information.
*/
int AddFile(struct FILERecord fdb, int Area, char *DestPath, char *FromPath)
int AddFile(struct FILERecord fdb, int Area, char *DestPath, char *FromPath, char *LinkPath)
{
char *temp1, *temp2;
FILE *fp1, *fp2;
int i, rc, Insert, Done = FALSE, Found = FALSE;
/*
* Copy file to the final destination and make a hard link with the
* 8.3 filename to the long filename.
*/
mkdirs(DestPath, 0775);
if ((rc = file_cp(FromPath, DestPath))) {
WriteError("Can't copy file in place");
@@ -323,6 +327,15 @@ int AddFile(struct FILERecord fdb, int Area, char *DestPath, char *FromPath)
return FALSE;
}
chmod(DestPath, 0644);
if (LinkPath) {
if ((rc = link(DestPath, LinkPath))) {
WriteError("Can't create link %s", LinkPath);
if (!do_quiet)
printf("Can't create link %s, %s\n", LinkPath, strerror(rc));
unlink(DestPath);
return FALSE;
}
}
temp1 = calloc(PATH_MAX, sizeof(char));
temp2 = calloc(PATH_MAX, sizeof(char));

View File

@@ -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 *);
int AddFile(struct FILERecord, int, char *, char *, char *);
int CheckFDB(int, char *); /* Check FDB of area */
int LoadAreaRec(int); /* Load Area record */

View File

@@ -695,16 +695,24 @@ int ProcessTic(fa_list *sbl)
* If the file is converted, we set the date of the original
* received file as the file creation date.
*/
sprintf(Temp, "%s/%s", TIC.Inbound, TIC.NewName);
if ((MustRearc || DidBanner) && CFG.ct_KeepDate) {
if ((tic.Touch) && (tic.FileArea)) {
ut.actime = mktime(localtime(&TIC.FileDate));
ut.modtime = mktime(localtime(&TIC.FileDate));
sprintf(Temp, "%s/%s", TIC.Inbound, TIC.NewName);
utime(Temp, &ut);
Syslog('-', "Restamp filedate %s to %s", Temp, rfcdate(ut.modtime));
}
}
/*
* Now make sure the file timestamp is updated. The file may be restamped,
* altered by banners etc.
*/
TIC.FileDate = file_time(Temp);
/*
* If not passthru, import in the BBS.
*/
if (tic.FileArea) {
Syslog('+', "Import: %s Area: %s", TIC.NewName, TIC.TicIn.Area);
@@ -795,21 +803,6 @@ int ProcessTic(fa_list *sbl)
tic_out++;
}
}
/*
* Now start forwarding files
*/
// First = TRUE;
// while (GetTicSystem(&Link, First)) {
// First = FALSE;
// if ((Link.aka.zone) && (Link.sendto) && (!Link.pause)) {
// if (!((TIC.Aka.zone == Link.aka.zone) && (TIC.Aka.net == Link.aka.net) &&
// (TIC.Aka.node == Link.aka.node) && (TIC.Aka.point == Link.aka.point))) {
// tic_out++;
// ForwardFile(Link.aka, sbl);
// }
// }
// }
}
Magic_ExecCommand();
@@ -818,8 +811,8 @@ int ProcessTic(fa_list *sbl)
Magic_AdoptFile();
sprintf(Temp, "%s/%s", TIC.Inbound, TIC.TicName);
unlink(Temp);
free(Temp);
tidy_qualify(&qal);
return 0;