From deb44339321e0b4362ed591a96438f5032fc05a8 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sun, 2 Dec 2001 20:49:36 +0000 Subject: [PATCH] Implemented mbfile move --- ChangeLog | 2 + html/programs/mbfile.html | 7 ++- mbfido/mbfadopt.c | 35 +---------- mbfido/mbfile.c | 35 ++++------- mbfido/mbfimport.c | 35 +---------- mbfido/mbfmove.c | 121 ++++++++++++++++++++++++++++++++++++++ mbfido/mbfutil.c | 44 ++++++++++++++ mbfido/mbfutil.h | 1 + mbsebbs/file.c | 4 +- 9 files changed, 195 insertions(+), 89 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6b8e2635..3694b95c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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. diff --git a/html/programs/mbfile.html b/html/programs/mbfile.html index ec3e7929..306c6944 100644 --- a/html/programs/mbfile.html +++ b/html/programs/mbfile.html @@ -11,7 +11,7 @@
-
Last update 25-Nov-2001
+
Last update 02-Dec-2001

mbfile - File database maintenance program.

@@ -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. +

+mbfile move <from> <to> <file> +This command will move a file from one area to another. No actions on the file +are performed. +

mbfile pack This command will actualy remove the records of files that are marked for diff --git a/mbfido/mbfadopt.c b/mbfido/mbfadopt.c index 40c5c560..060f944a 100644 --- a/mbfido/mbfadopt.c +++ b/mbfido/mbfadopt.c @@ -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); } diff --git a/mbfido/mbfile.c b/mbfido/mbfile.c index 980d33bc..aefc8c2e 100644 --- a/mbfido/mbfile.c +++ b/mbfido/mbfile.c @@ -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(); diff --git a/mbfido/mbfimport.c b/mbfido/mbfimport.c index 914d5a55..4850933f 100644 --- a/mbfido/mbfimport.c +++ b/mbfido/mbfimport.c @@ -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)); diff --git a/mbfido/mbfmove.c b/mbfido/mbfmove.c index dee58e2a..49027cdd 100644 --- a/mbfido/mbfmove.c +++ b/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); } diff --git a/mbfido/mbfutil.c b/mbfido/mbfutil.c index 66767ee2..bf62c8ab 100644 --- a/mbfido/mbfutil.c +++ b/mbfido/mbfutil.c @@ -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; +} + + diff --git a/mbfido/mbfutil.h b/mbfido/mbfutil.h index 05f65c22..f43a8365 100644 --- a/mbfido/mbfutil.h +++ b/mbfido/mbfutil.h @@ -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 diff --git a/mbsebbs/file.c b/mbsebbs/file.c index 7f8286dc..7f8bc4f0 100644 --- a/mbsebbs/file.c +++ b/mbsebbs/file.c @@ -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 */