Added mbfile adopt command
This commit is contained in:
parent
97f33ea687
commit
35c0eb6b50
@ -4245,6 +4245,8 @@ v0.33.19 26-Oct-2001
|
|||||||
now in a more logical order for a first system setup.
|
now in a more logical order for a first system setup.
|
||||||
Most datafiles are now saved mode 0640 exept the files that
|
Most datafiles are now saved mode 0640 exept the files that
|
||||||
need to be rewritten by users, they have mode 0660.
|
need to be rewritten by users, they have mode 0660.
|
||||||
|
In the file database editor the default choice was 0 in stead
|
||||||
|
of -.
|
||||||
|
|
||||||
mbsebbs:
|
mbsebbs:
|
||||||
Added menu 317, change FS editor shortcut keys to (Emacs/
|
Added menu 317, change FS editor shortcut keys to (Emacs/
|
||||||
@ -4312,4 +4314,5 @@ v0.33.19 26-Oct-2001
|
|||||||
|
|
||||||
mbfile:
|
mbfile:
|
||||||
During check the file databases are reset to filemode 0660.
|
During check the file databases are reset to filemode 0660.
|
||||||
|
Implemented "mbfile adopt" function.
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
</HEAD>
|
</HEAD>
|
||||||
<BODY>
|
<BODY>
|
||||||
<BLOCKQUOTE>
|
<BLOCKQUOTE>
|
||||||
<h5>Last update 22-Oct-2001</h5>
|
<h5>Last update 19-Nov-2001</h5>
|
||||||
<P>
|
<P>
|
||||||
|
|
||||||
<H1>mbfile - File database maintenance program.</H1>
|
<H1>mbfile - File database maintenance program.</H1>
|
||||||
@ -48,6 +48,16 @@ must exist in the subdirectory ~/etc.
|
|||||||
<P> <P>
|
<P> <P>
|
||||||
|
|
||||||
<H3>Commands.</H3>
|
<H3>Commands.</H3>
|
||||||
|
<P>
|
||||||
|
<code><strong>mbfile</strong> adopt <area> <file> [description]</code>
|
||||||
|
Adopt a file to the filebase. The description is optional, but if present it
|
||||||
|
should be enclosed in quotes. The optional description may be 255 characters.
|
||||||
|
Default mbfile will try to use the FILE_ID.DIZ if this is present. The file to
|
||||||
|
adopt needs to be in your current directory and will be copied to the new area.
|
||||||
|
If you have virus scanners defined, the file will be checked for virusses. If
|
||||||
|
you have a different default archiver set for the destination file area then the
|
||||||
|
file is archived with, the file will be rearchived.
|
||||||
|
|
||||||
<P>
|
<P>
|
||||||
<code><strong>mbfile</strong> check</code>
|
<code><strong>mbfile</strong> check</code>
|
||||||
Check the database integrity. All files in the filedatabase must exist on
|
Check the database integrity. All files in the filedatabase must exist on
|
||||||
|
@ -45,10 +45,14 @@ extern int do_quiet; /* Supress screen output */
|
|||||||
|
|
||||||
void AdoptFile(int Area, char *File, char *Description)
|
void AdoptFile(int Area, char *File, char *Description)
|
||||||
{
|
{
|
||||||
FILE *pAreas, *pFile, *fp;
|
FILE *pAreas, *pFile, *fp;
|
||||||
char *sAreas, *fAreas, *temp, *temp2, *unarc, *cmd, *pwd;
|
char *sAreas, *fAreas, *temp, *temp2, *unarc, *cmd, *pwd;
|
||||||
int IsArchive = FALSE, MustRearc = FALSE, UnPacked = FALSE;
|
char Desc[256], TDesc[256];
|
||||||
int IsVirus = FALSE, File_Id = FALSE;
|
int IsArchive = FALSE, MustRearc = FALSE, UnPacked = FALSE;
|
||||||
|
int IsVirus = FALSE, File_Id = FALSE;
|
||||||
|
int i, j, k, lines = 0, File_id_cnt = 0;
|
||||||
|
int Insert, Done = FALSE, Found = FALSE;
|
||||||
|
struct FILERecord fdb;
|
||||||
|
|
||||||
Syslog('-', "Adopt(%d, %s, %s)", Area, MBSE_SS(File), MBSE_SS(Description));
|
Syslog('-', "Adopt(%d, %s, %s)", Area, MBSE_SS(File), MBSE_SS(Description));
|
||||||
|
|
||||||
@ -214,6 +218,10 @@ void AdoptFile(int Area, char *File, char *Description)
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset(&fdb, 0, sizeof(fdb));
|
||||||
|
strcpy(fdb.Uploader, CFG.sysop_name);
|
||||||
|
fdb.UploadDate = time(NULL);
|
||||||
|
|
||||||
temp2 = calloc(PATH_MAX, sizeof(char));
|
temp2 = calloc(PATH_MAX, sizeof(char));
|
||||||
sprintf(temp, "%s/tmp/arc/FILE_ID.DIZ", getenv("MBSE_ROOT"));
|
sprintf(temp, "%s/tmp/arc/FILE_ID.DIZ", getenv("MBSE_ROOT"));
|
||||||
sprintf(temp2, "%s/tmp/FILE_ID.DIZ", getenv("MBSE_ROOT"));
|
sprintf(temp2, "%s/tmp/FILE_ID.DIZ", getenv("MBSE_ROOT"));
|
||||||
@ -224,13 +232,201 @@ void AdoptFile(int Area, char *File, char *Description)
|
|||||||
if (file_cp(temp, temp2) == 0)
|
if (file_cp(temp, temp2) == 0)
|
||||||
File_Id = TRUE;
|
File_Id = TRUE;
|
||||||
}
|
}
|
||||||
free(temp2);
|
if (File_Id) {
|
||||||
if (File_Id)
|
|
||||||
Syslog('-', "FILE_ID.DIZ found");
|
Syslog('-', "FILE_ID.DIZ found");
|
||||||
|
if ((fp = fopen(temp2, "r"))) {
|
||||||
|
/*
|
||||||
|
* Read no more then 25 lines
|
||||||
|
*/
|
||||||
|
while (((fgets(Desc, 255, fp)) != NULL) && (File_id_cnt < 25)) {
|
||||||
|
lines++;
|
||||||
|
/*
|
||||||
|
* Check if the FILE_ID.DIZ is in a normal layout.
|
||||||
|
* This should be max. 10 lines of max. 48 characters.
|
||||||
|
* We check at 51 characters and if the lines are longer,
|
||||||
|
* we discard the FILE_ID.DIZ file.
|
||||||
|
*/
|
||||||
|
if (strlen(Desc) > 51) {
|
||||||
|
File_id_cnt = 0;
|
||||||
|
File_Id = FALSE;
|
||||||
|
Syslog('!', "Discarding illegal formated FILE_ID.DIZ");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(Desc)) {
|
||||||
|
if (strlen(Desc) > 48)
|
||||||
|
Desc[48] = '\0';
|
||||||
|
j = 0;
|
||||||
|
for (i = 0; i < strlen(Desc); i++) {
|
||||||
|
if ((Desc[i] >= ' ') || (Desc[i] < 0)) {
|
||||||
|
fdb.Desc[File_id_cnt][j] = Desc[i];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
File_id_cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
unlink(temp2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Strip empty lines at end of FILE_ID.DIZ
|
||||||
|
*/
|
||||||
|
while ((strlen(fdb.Desc[File_id_cnt-1]) == 0) && (File_id_cnt))
|
||||||
|
File_id_cnt--;
|
||||||
|
|
||||||
|
Syslog('f', "Got %d FILE_ID.DIZ lines", File_id_cnt);
|
||||||
|
for (i = 0; i < File_id_cnt; i++)
|
||||||
|
Syslog('f', "\"%s\"", fdb.Desc[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!File_id_cnt) {
|
||||||
|
if (Description == NULL) {
|
||||||
|
WriteError("No FILE_ID.DIZ and no description on the commandline");
|
||||||
|
DeleteVirusWork();
|
||||||
|
fclose(pFile);
|
||||||
|
die(0);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Create description from the commandline.
|
||||||
|
*/
|
||||||
|
if (strlen(Description) < 48) {
|
||||||
|
strcpy(fdb.Desc[0], Description);
|
||||||
|
File_id_cnt++;
|
||||||
|
} else {
|
||||||
|
memset(&TDesc, 0, sizeof(TDesc));
|
||||||
|
strcpy(TDesc, Description);
|
||||||
|
while (strlen(TDesc) > 48) {
|
||||||
|
j = 48;
|
||||||
|
while (TDesc[j] != ' ')
|
||||||
|
j--;
|
||||||
|
strncat(fdb.Desc[File_id_cnt], TDesc, j);
|
||||||
|
File_id_cnt++;
|
||||||
|
k = strlen(TDesc);
|
||||||
|
j++; /* Correct space */
|
||||||
|
for (i = 0; i <= k; i++, j++)
|
||||||
|
TDesc[i] = TDesc[j];
|
||||||
|
}
|
||||||
|
strcpy(fdb.Desc[File_id_cnt], TDesc);
|
||||||
|
File_id_cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Import the file.
|
||||||
|
*/
|
||||||
|
chdir(pwd);
|
||||||
DeleteVirusWork();
|
DeleteVirusWork();
|
||||||
fclose(pFile);
|
strcpy(fdb.Name, File);
|
||||||
|
strcpy(fdb.LName, File);
|
||||||
|
fdb.Size = file_size(File);
|
||||||
|
fdb.Crc32 = file_crc(File, TRUE);
|
||||||
|
fdb.FileDate = file_time(File);
|
||||||
|
sprintf(temp2, "%s/%s", area.Path, File);
|
||||||
|
|
||||||
|
if (!do_quiet) {
|
||||||
|
printf("Adding \b\b\b\b\b\b\b\b\b\b");
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
mkdirs(temp2);
|
||||||
|
if (file_cp(fdb.LName, temp2)) {
|
||||||
|
WriteError("Can't move file in place");
|
||||||
|
fclose(pFile);
|
||||||
|
die(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(temp2, "%s/fdb/fdb%d.temp", getenv("MBSE_ROOT"), Area);
|
||||||
|
fseek(pFile, 0, SEEK_END);
|
||||||
|
if (ftell(pFile) == 0) {
|
||||||
|
/*
|
||||||
|
* No records yet
|
||||||
|
*/
|
||||||
|
fwrite(&fdb, sizeof(fdb), 1, pFile);
|
||||||
|
fclose(pFile);
|
||||||
|
free(temp2);
|
||||||
|
Syslog('+', "Added file in area %d", Area);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Files are already there. Find the right spot.
|
||||||
|
*/
|
||||||
|
fseek(pFile, 0, SEEK_SET);
|
||||||
|
|
||||||
|
Insert = 0;
|
||||||
|
do {
|
||||||
|
if (fread(&file, sizeof(file), 1, pFile) != 1)
|
||||||
|
Done = TRUE;
|
||||||
|
if (!Done) {
|
||||||
|
if (strcmp(fdb.Name, file.Name) == 0) {
|
||||||
|
Found = TRUE;
|
||||||
|
Insert++;
|
||||||
|
} else {
|
||||||
|
if (strcmp(fdb.Name, file.Name) < 0)
|
||||||
|
Found = TRUE;
|
||||||
|
else
|
||||||
|
Insert++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while ((!Found) && (!Done));
|
||||||
|
|
||||||
|
if (Found) {
|
||||||
|
if ((fp = fopen(temp2, "a+")) == NULL) {
|
||||||
|
WriteError("Can't create %s", temp2);
|
||||||
|
die(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek(pFile, 0, SEEK_SET);
|
||||||
|
/*
|
||||||
|
* Copy until the insert point
|
||||||
|
*/
|
||||||
|
for (i = 0; i < Insert; i++) {
|
||||||
|
fread(&file, sizeof(file), 1, pFile);
|
||||||
|
/*
|
||||||
|
* If we are importing a file with the same name,
|
||||||
|
* skip the original record and put the new one in place.
|
||||||
|
*/
|
||||||
|
if (strcmp(file.Name, fdb.Name) != 0)
|
||||||
|
fwrite(&file, sizeof(file), 1, fp);
|
||||||
|
}
|
||||||
|
if (area.AddAlpha)
|
||||||
|
fwrite(&fdb, sizeof(fdb), 1, fp);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Append the rest of the records
|
||||||
|
*/
|
||||||
|
while (fread(&file, sizeof(file), 1, fp) == 1) {
|
||||||
|
if (strcmp(file.Name, fdb.Name) != 0)
|
||||||
|
fwrite(&file, sizeof(file), 1, fp);
|
||||||
|
}
|
||||||
|
if (!area.AddAlpha)
|
||||||
|
fwrite(&fdb, sizeof(fdb), 1, fp);
|
||||||
|
fclose(fp);
|
||||||
|
fclose(pFile);
|
||||||
|
|
||||||
|
if (unlink(fAreas) == 0) {
|
||||||
|
rename(temp2, fAreas);
|
||||||
|
chmod(fAreas, 0660);
|
||||||
|
Syslog('+', "Added file in area %d", Area);
|
||||||
|
} else {
|
||||||
|
WriteError("$Can't unlink %s", fAreas);
|
||||||
|
unlink(temp2);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Append file record
|
||||||
|
*/
|
||||||
|
fseek(pFile, 0, SEEK_END);
|
||||||
|
fwrite(&fdb, sizeof(fdb), 1, pFile);
|
||||||
|
fclose(pFile);
|
||||||
|
Syslog('+', "Added file in area %d", Area);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MustRearc) {
|
||||||
|
/* Here we should call the rearc function */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(pwd);
|
free(pwd);
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
*
|
*
|
||||||
* File ..................: setup/m_fdb.c
|
* $Id$
|
||||||
* Purpose ...............: Edit Files DataBase.
|
* Purpose ...............: Edit Files DataBase.
|
||||||
* Last modification date : 19-Oct-2001
|
|
||||||
*
|
*
|
||||||
*****************************************************************************
|
*****************************************************************************
|
||||||
* Copyright (C) 1999-2001
|
* Copyright (C) 1999-2001
|
||||||
@ -209,7 +208,7 @@ void E_F(long areanr)
|
|||||||
|
|
||||||
while(TRUE) {
|
while(TRUE) {
|
||||||
mvprintw(LINES - 4, 6, "Enter your choice >");
|
mvprintw(LINES - 4, 6, "Enter your choice >");
|
||||||
menu = (char *)"0";
|
menu = (char *)"-";
|
||||||
menu = edit_field(LINES - 4, 26, 6, '!', menu);
|
menu = edit_field(LINES - 4, 26, 6, '!', menu);
|
||||||
locate(LINES - 4, 6);
|
locate(LINES - 4, 6);
|
||||||
clrtoeol();
|
clrtoeol();
|
||||||
|
Reference in New Issue
Block a user