Implemented mbfile move
This commit is contained in:
parent
752f85de56
commit
deb4433932
@ -4369,6 +4369,8 @@ v0.33.19 26-Oct-2001
|
||||
errors).
|
||||
The mbfile list function now gives a listing of the contents
|
||||
of a file area if the area number is given as argument.
|
||||
Implemented "mbfile move" command. You can only move one file
|
||||
at the same time.
|
||||
|
||||
mball:
|
||||
The index function is now obsolete, this is added to mbfile.
|
||||
|
@ -11,7 +11,7 @@
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<BLOCKQUOTE>
|
||||
<h5>Last update 25-Nov-2001</h5>
|
||||
<h5>Last update 02-Dec-2001</h5>
|
||||
<P>
|
||||
|
||||
<H1>mbfile - File database maintenance program.</H1>
|
||||
@ -103,6 +103,11 @@ List all defined file areas, the number of files, the total size of the files
|
||||
and the primary group. If and area is given on the commandline, the files in
|
||||
that area are listed.
|
||||
|
||||
<P>
|
||||
<code><strong>mbfile</strong> move <from> <to> <file></code>
|
||||
This command will move a file from one area to another. No actions on the file
|
||||
are performed.
|
||||
|
||||
<P>
|
||||
<code><strong>mbfile</strong> pack</code>
|
||||
This command will actualy remove the records of files that are marked for
|
||||
|
@ -46,8 +46,8 @@ extern int do_annon; /* Supress announce file */
|
||||
|
||||
void AdoptFile(int Area, char *File, char *Description)
|
||||
{
|
||||
FILE *pAreas, *fp;
|
||||
char *sAreas, *temp, *temp2, *unarc, *pwd;
|
||||
FILE *fp;
|
||||
char *temp, *temp2, *unarc, *pwd;
|
||||
char Desc[256], TDesc[256];
|
||||
int IsArchive = FALSE, MustRearc = FALSE, UnPacked = FALSE;
|
||||
int IsVirus = FALSE, File_Id = FALSE;
|
||||
@ -59,34 +59,8 @@ void AdoptFile(int Area, char *File, char *Description)
|
||||
if (!do_quiet)
|
||||
colour(CYAN, BLACK);
|
||||
|
||||
sAreas = calloc(PATH_MAX, sizeof(char));
|
||||
|
||||
sprintf(sAreas, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
|
||||
if ((pAreas = fopen (sAreas, "r")) == NULL) {
|
||||
WriteError("$Can't open %s", sAreas);
|
||||
if (!do_quiet)
|
||||
printf("Can't open %s\n", sAreas);
|
||||
if (LoadAreaRec(Area) == FALSE)
|
||||
die(0);
|
||||
}
|
||||
|
||||
fread(&areahdr, sizeof(areahdr), 1, pAreas);
|
||||
if (fseek(pAreas, ((Area - 1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET)) {
|
||||
WriteError("$Can't seek record %d in %s", Area, sAreas);
|
||||
if (!do_quiet)
|
||||
printf("Can't seek record %d in %s\n", Area, sAreas);
|
||||
fclose(pAreas);
|
||||
free(sAreas);
|
||||
die(0);
|
||||
}
|
||||
|
||||
if (fread(&area, areahdr.recsize, 1, pAreas) != 1) {
|
||||
WriteError("$Can't read record %d in %s", Area, sAreas);
|
||||
if (!do_quiet)
|
||||
printf("Can't read record %d in %s\n", Area, sAreas);
|
||||
fclose(pAreas);
|
||||
free(sAreas);
|
||||
die(0);
|
||||
}
|
||||
|
||||
if (area.Available) {
|
||||
temp = calloc(PATH_MAX, sizeof(char));
|
||||
@ -308,12 +282,9 @@ void AdoptFile(int Area, char *File, char *Description)
|
||||
printf("Area %d is not available\n", Area);
|
||||
}
|
||||
|
||||
fclose(pAreas);
|
||||
if (!do_quiet) {
|
||||
printf("\r \r");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
free(sAreas);
|
||||
}
|
||||
|
||||
|
@ -119,20 +119,11 @@ int main(int argc, char **argv)
|
||||
do_annon = TRUE;
|
||||
} else {
|
||||
Description = xstrcpy(argv[i]);
|
||||
if (argc > (i + 1)) {
|
||||
i++;
|
||||
cmd = xstrcat(cmd, (char *)" ");
|
||||
cmd = xstrcat(cmd, argv[i]);
|
||||
if (!strncasecmp(argv[i], "-a", 2)) {
|
||||
do_annon = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!strncasecmp(argv[i], "in", 2))
|
||||
} else if (!strncasecmp(argv[i], "in", 2)) {
|
||||
do_index = TRUE;
|
||||
if (!strncasecmp(argv[i], "im", 2)) {
|
||||
} else if (!strncasecmp(argv[i], "im", 2)) {
|
||||
if (argc > (i + 1)) {
|
||||
do_import = TRUE;
|
||||
i++;
|
||||
@ -140,8 +131,7 @@ int main(int argc, char **argv)
|
||||
cmd = xstrcat(cmd, (char *)" ");
|
||||
cmd = xstrcat(cmd, argv[i]);
|
||||
}
|
||||
}
|
||||
if (!strncasecmp(argv[i], "l", 1)) {
|
||||
} else if (!strncasecmp(argv[i], "l", 1)) {
|
||||
do_list = TRUE;
|
||||
if (argc > (i + 1)) {
|
||||
i++;
|
||||
@ -149,8 +139,7 @@ int main(int argc, char **argv)
|
||||
cmd = xstrcat(cmd, (char *)" ");
|
||||
cmd = xstrcat(cmd, argv[i]);
|
||||
}
|
||||
}
|
||||
if (!strncasecmp(argv[i], "m", 1)) {
|
||||
} else if (!strncasecmp(argv[i], "m", 1)) {
|
||||
if (argc > (i + 1)) {
|
||||
i++;
|
||||
Area = atoi(argv[i]);
|
||||
@ -170,20 +159,22 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!strncasecmp(argv[i], "p", 1))
|
||||
} else if (!strncasecmp(argv[i], "p", 1)) {
|
||||
do_pack = TRUE;
|
||||
if (!strncasecmp(argv[i], "c", 1))
|
||||
} else if (!strncasecmp(argv[i], "c", 1)) {
|
||||
do_check = TRUE;
|
||||
if (!strncasecmp(argv[i], "k", 1))
|
||||
} else if (!strncasecmp(argv[i], "k", 1)) {
|
||||
do_kill = TRUE;
|
||||
if (!strncasecmp(argv[i], "t", 1))
|
||||
} else if (!strncasecmp(argv[i], "t", 1)) {
|
||||
do_tobe = TRUE;
|
||||
if (!strncasecmp(argv[i], "-q", 2))
|
||||
} else if (!strncasecmp(argv[i], "-q", 2)) {
|
||||
do_quiet = TRUE;
|
||||
} else if (!strncasecmp(argv[i], "-a", 2)) {
|
||||
do_annon = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(do_pack || do_check || do_kill || do_index || do_import || do_list || do_adopt || do_tobe))
|
||||
if (!(do_pack || do_check || do_kill || do_index || do_import || do_list || do_adopt || do_move || do_tobe))
|
||||
Help();
|
||||
|
||||
ProgName();
|
||||
|
@ -46,8 +46,8 @@ extern int do_annon; /* Supress announce files */
|
||||
|
||||
void ImportFiles(int Area)
|
||||
{
|
||||
char *sAreas, *pwd, *temp, *temp2, *String, *token, *dest, *unarc;
|
||||
FILE *pAreas, *fbbs;
|
||||
char *pwd, *temp, *temp2, *String, *token, *dest, *unarc;
|
||||
FILE *fbbs;
|
||||
int Append = FALSE, Files = 0, i, j = 0, k = 0, x, Doit;
|
||||
int Imported = 0, Errors = 0;
|
||||
struct FILERecord fdb;
|
||||
@ -58,37 +58,8 @@ void ImportFiles(int Area)
|
||||
if (!do_quiet)
|
||||
colour(CYAN, BLACK);
|
||||
|
||||
sAreas = calloc(PATH_MAX, sizeof(char));
|
||||
|
||||
sprintf(sAreas, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
|
||||
if ((pAreas = fopen (sAreas, "r")) == NULL) {
|
||||
WriteError("$Can't open %s", sAreas);
|
||||
if (!do_quiet)
|
||||
printf("Can't open %s\n", sAreas);
|
||||
if (LoadAreaRec(Area) == FALSE)
|
||||
die(0);
|
||||
}
|
||||
|
||||
fread(&areahdr, sizeof(areahdr), 1, pAreas);
|
||||
if (fseek(pAreas, ((Area - 1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET)) {
|
||||
WriteError("$Can't seek record %d in %s", Area, sAreas);
|
||||
if (!do_quiet)
|
||||
printf("Can't seek record %d in %s\n", Area, sAreas);
|
||||
fclose(pAreas);
|
||||
free(sAreas);
|
||||
die(0);
|
||||
}
|
||||
|
||||
if (fread(&area, areahdr.recsize, 1, pAreas) != 1) {
|
||||
WriteError("$Can't read record %d in %s", Area, sAreas);
|
||||
if (!do_quiet)
|
||||
printf("Can't read record %d in %s\n", Area, sAreas);
|
||||
fclose(pAreas);
|
||||
free(sAreas);
|
||||
die(0);
|
||||
}
|
||||
|
||||
fclose(pAreas);
|
||||
free(sAreas);
|
||||
|
||||
if (area.Available && !area.CDrom) {
|
||||
temp = calloc(PATH_MAX, sizeof(char));
|
||||
|
121
mbfido/mbfmove.c
121
mbfido/mbfmove.c
@ -48,6 +48,127 @@ extern int do_quiet; /* Supress screen output */
|
||||
*/
|
||||
void Move(int From, int To, char *File)
|
||||
{
|
||||
char *frompath, *topath, *temp1, *temp2;
|
||||
struct FILERecord fdb;
|
||||
FILE *fp1, *fp2;
|
||||
int rc = FALSE;
|
||||
|
||||
IsDoing("Move file");
|
||||
colour(LIGHTRED, BLACK);
|
||||
|
||||
if (From == To) {
|
||||
WriteError("Area numbers are the same");
|
||||
if (!do_quiet)
|
||||
printf("Can't move to the same area\n");
|
||||
die(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check From area
|
||||
*/
|
||||
if (LoadAreaRec(From) == FALSE) {
|
||||
WriteError("Can't load record %d", From);
|
||||
die(0);
|
||||
}
|
||||
if (!area.Available) {
|
||||
WriteError("Area %d not available", From);
|
||||
if (!do_quiet)
|
||||
printf("Area %d not available\n", From);
|
||||
die(0);
|
||||
}
|
||||
if (area.CDrom) {
|
||||
WriteError("Can't move from CD-ROM");
|
||||
if (!do_quiet)
|
||||
printf("Can't move from CD-ROM\n");
|
||||
die(0);
|
||||
}
|
||||
if (CheckFDB(From, area.Path))
|
||||
die(0);
|
||||
frompath = xstrcpy(area.Path);
|
||||
frompath = xstrcat(frompath, (char *)"/");
|
||||
frompath = xstrcat(frompath, File);
|
||||
|
||||
/*
|
||||
* Check Destination area
|
||||
*/
|
||||
if (LoadAreaRec(To) == FALSE) {
|
||||
WriteError("Can't load record %d", To);
|
||||
die(0);
|
||||
}
|
||||
if (!area.Available) {
|
||||
WriteError("Area %d not available", To);
|
||||
if (!do_quiet)
|
||||
printf("Area %d not available\n", To);
|
||||
die(0);
|
||||
}
|
||||
if (area.CDrom) {
|
||||
WriteError("Can't move to CD-ROM");
|
||||
if (!do_quiet)
|
||||
printf("Can't move to CD-ROM\n");
|
||||
die(0);
|
||||
}
|
||||
if (CheckFDB(To, area.Path))
|
||||
die(0);
|
||||
topath = xstrcpy(area.Path);
|
||||
topath = xstrcat(topath, (char *)"/");
|
||||
topath = xstrcat(topath, File);
|
||||
|
||||
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)
|
||||
die(0);
|
||||
if ((fp2 = fopen(temp2, "a+")) == NULL)
|
||||
die(0);
|
||||
|
||||
/*
|
||||
* Search the file if the From area, if found, the
|
||||
* temp database holds all records except the moved
|
||||
* file.
|
||||
*/
|
||||
while (fread(&fdb, sizeof(fdb), 1, fp1) == 1) {
|
||||
if (strcmp(fdb.LName, File))
|
||||
fwrite(&fdb, sizeof(fdb), 1, fp2);
|
||||
else
|
||||
rc = AddFile(fdb, To, topath, frompath);
|
||||
}
|
||||
fclose(fp1);
|
||||
fclose(fp2);
|
||||
|
||||
if (rc) {
|
||||
/*
|
||||
* The move was successfull
|
||||
*/
|
||||
if (unlink(temp1) == 0) {
|
||||
rename(temp2, temp1);
|
||||
chmod(temp1, 0660);
|
||||
} else {
|
||||
WriteError("$Can't unlink %s", temp1);
|
||||
unlink(temp2);
|
||||
}
|
||||
unlink(frompath);
|
||||
colour(CYAN, BLACK);
|
||||
} else {
|
||||
/*
|
||||
* The move failed, it is possible that the file is
|
||||
* copied already. Don't remove it here, it might
|
||||
* be removed if it was not meant to be, ie if you
|
||||
* gave this command twice. Let "mbfile check" take
|
||||
* care of unwanted copies.
|
||||
*/
|
||||
unlink(temp2);
|
||||
}
|
||||
|
||||
Syslog('+', "Move %s from %d to %d %s", File, From, To, rc ? "successfull":"failed");
|
||||
if (!do_quiet)
|
||||
printf("Move %s from %d to %d %s\n", File, From, To, rc ? "successfull":"failed");
|
||||
|
||||
free(temp1);
|
||||
free(temp2);
|
||||
free(frompath);
|
||||
free(topath);
|
||||
}
|
||||
|
||||
|
||||
|
@ -455,3 +455,47 @@ int CheckFDB(int Area, char *Path)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Load Area Record
|
||||
*/
|
||||
int LoadAreaRec(int Area)
|
||||
{
|
||||
FILE *pAreas;
|
||||
char *sAreas;
|
||||
|
||||
sAreas = calloc(PATH_MAX, sizeof(char));
|
||||
|
||||
sprintf(sAreas, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
|
||||
if ((pAreas = fopen (sAreas, "r")) == NULL) {
|
||||
WriteError("$Can't open %s", sAreas);
|
||||
if (!do_quiet)
|
||||
printf("Can't open %s\n", sAreas);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fread(&areahdr, sizeof(areahdr), 1, pAreas);
|
||||
if (fseek(pAreas, ((Area - 1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET)) {
|
||||
WriteError("$Can't seek record %d in %s", Area, sAreas);
|
||||
if (!do_quiet)
|
||||
printf("Can't seek record %d in %s\n", Area, sAreas);
|
||||
fclose(pAreas);
|
||||
free(sAreas);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (fread(&area, areahdr.recsize, 1, pAreas) != 1) {
|
||||
WriteError("$Can't read record %d in %s", Area, sAreas);
|
||||
if (!do_quiet)
|
||||
printf("Can't read record %d in %s\n", Area, sAreas);
|
||||
fclose(pAreas);
|
||||
free(sAreas);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fclose(pAreas);
|
||||
free(sAreas);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,5 +11,6 @@ void DeleteVirusWork(void); /* Delete unarc directory */
|
||||
int UnpackFile(char *File); /* Unpack archive */
|
||||
int AddFile(struct FILERecord, int, char *, char *);
|
||||
int CheckFDB(int, char *); /* Check FDB of area */
|
||||
int LoadAreaRec(int); /* Load Area record */
|
||||
|
||||
#endif
|
||||
|
@ -137,11 +137,11 @@ void File_List()
|
||||
|
||||
if (file.Deleted)
|
||||
/* D E L E T E D */ /* Uploaded by: */
|
||||
printf("%-12s %s [%ld] %s%s\n", file.Name, (char *) Language(239), file.TimesDL, (char *) Language(238), file.Uploader);
|
||||
printf(" -- %-12s %s [%4ld] %s%s\n", file.Name, (char *) Language(239), file.TimesDL, (char *) Language(238), file.Uploader);
|
||||
|
||||
if (file.Missing)
|
||||
/* M I S S I N G */ /* Uploaded by: */
|
||||
printf("%-12s %s [%ld] %s%s\n", file.Name, (char *) Language(240), file.TimesDL, (char *) Language(238), file.Uploader);
|
||||
printf(" -- %-12s %s [%4ld] %s%s\n", file.Name, (char *) Language(240), file.TimesDL, (char *) Language(238), file.Uploader);
|
||||
|
||||
FileCount++; /* Increase File Counter by 1 */
|
||||
FileBytes += file.Size; /* Increase File Byte Count */
|
||||
|
Reference in New Issue
Block a user