Implemeted mbfile delete and mbfile undelete commands

This commit is contained in:
Michiel Broek 2001-12-02 22:36:22 +00:00
parent deb4433932
commit 077152b767
7 changed files with 181 additions and 14 deletions

View File

@ -4371,6 +4371,7 @@ v0.33.19 26-Oct-2001
of a file area if the area number is given as argument. of a file area if the area number is given as argument.
Implemented "mbfile move" command. You can only move one file Implemented "mbfile move" command. You can only move one file
at the same time. at the same time.
Implemented "mbfile delete" and "mbfile undelete" commands.
mball: mball:
The index function is now obsolete, this is added to mbfile. The index function is now obsolete, this is added to mbfile.

View File

@ -68,6 +68,11 @@ file is removed. If the area is a CD-rom area, the check that files on disk
must exist in the filedatabase is skipped. must exist in the filedatabase is skipped.
<P> <P>
<code><strong>mbfile</strong> delete &lt;area&gt; &lt;file&gt;</code>
Mark a file in an area for later deletion.
The file is not removed until you run <strong>mbfile pack</strong>.
<P>
<code><strong>mbfile</strong> import &lt;area&gt;</code> <code><strong>mbfile</strong> import &lt;area&gt;</code>
Import files to the given area using files.bbs descriptions. Import files to the given area using files.bbs descriptions.
You need to be in the area where the files are stored. You need to be in the area where the files are stored.
@ -89,7 +94,7 @@ created, starting at the ftp pub directory.
<P> <P>
<code><strong>mbfile</strong> kill</code> <code><strong>mbfile</strong> kill</code>
Delete or move files in areas that have the <strong>download age</strong> Mark files to delete or move files in areas that have the <strong>download age</strong>
set or the <strong>filedate age</strong> set. A setting of 0 is ignored. set or the <strong>filedate age</strong> set. A setting of 0 is ignored.
Areas on CD-rom are always skipped. Areas on CD-rom are always skipped.
If the Move to Area option is set the files are moved to the given area. The If the Move to Area option is set the files are moved to the given area. The
@ -102,18 +107,23 @@ there for 14 days after the move. This is good for automatic "last chance" areas
List all defined file areas, the number of files, the total size of the files 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 and the primary group. If and area is given on the commandline, the files in
that area are listed. that area are listed.
<P> <P>
<code><strong>mbfile</strong> move &lt;from&gt; &lt;to&gt; &lt;file&gt;</code> <code><strong>mbfile</strong> move &lt;from&gt; &lt;to&gt; &lt;file&gt;</code>
This command will move a file from one area to another. No actions on the file This command will move a file from one area to another. No actions on the file
are performed. are performed.
<P> <P>
<code><strong>mbfile</strong> pack</code> <code><strong>mbfile</strong> pack</code>
This command will actualy remove the records of files that are marked for This command will actualy remove the records of files that are marked for
deletion. If the file is still on disk, it will be removed also. So when deletion. If the file is still on disk, it will be removed also. So when
you delete files with mbsetup, they are still in your database and on disk you delete files with mbsetup or with mbfile, they are still in your database and on disk
until you run <strong>mbfile pack</strong>. until you run <strong>mbfile pack</strong>.
<P>
<code><strong>mbfile</strong> undelete &lt;area&gt; &lt;file&gt;</code>
Mark a file that is marked for deletion to be available again, ie. undo the deletion
mark.
<P>&nbsp;<P> <P>&nbsp;<P>
<H3>Options.</H3> <H3>Options.</H3>

View File

@ -13,7 +13,7 @@ SRCS = addbbs.c backalias.c flock.c hatch.c mbdiff.c mgrutil.c pack.c \
mbmsg.c newspost.c postemail.c scan.c toberep.c atoul.c filemgr.c \ mbmsg.c newspost.c postemail.c scan.c toberep.c atoul.c filemgr.c \
hash.c mbaff.c mbseq.c notify.c postnetmail.c scannews.c tosspkt.c \ hash.c mbaff.c mbseq.c notify.c postnetmail.c scannews.c tosspkt.c \
mbfkill.c mbfutil.c mbfindex.c mbfcheck.c mbfpack.c mbflist.c mbfadopt.c \ mbfkill.c mbfutil.c mbfindex.c mbfcheck.c mbfpack.c mbflist.c mbfadopt.c \
mbfimport.c virscan.c mbftoberep.c mbfmove.c mbfimport.c virscan.c mbftoberep.c mbfmove.c mbfdel.c
HDRS = addbbs.h backalias.h flock.h hatch.h mbdiff.h mgrutil.h pack.h \ HDRS = addbbs.h backalias.h flock.h hatch.h mbdiff.h mgrutil.h pack.h \
postnetmail.h scannews.h tosspkt.h addpkt.h bwrite.h forward.h \ postnetmail.h scannews.h tosspkt.h addpkt.h bwrite.h forward.h \
lhash.h mbfido.h mkftnhdr.h paths.h ptic.h sendmail.h tracker.h \ lhash.h mbfido.h mkftnhdr.h paths.h ptic.h sendmail.h tracker.h \
@ -23,7 +23,7 @@ HDRS = addbbs.h backalias.h flock.h hatch.h mbdiff.h mgrutil.h pack.h \
grlist.h maketags.h mbmsg.h newspost.h postecho.h rollover.h tic.h \ grlist.h maketags.h mbmsg.h newspost.h postecho.h rollover.h tic.h \
atoul.h filemgr.h hash.h mbaff.h mbseq.h notify.h postemail.h scan.h toberep.h \ atoul.h filemgr.h hash.h mbaff.h mbseq.h notify.h postemail.h scan.h toberep.h \
mbfkill.h mbfutil.h mbfindex.h mbfcheck.h mbfpack.h mbflist.h mbfadopt.h \ mbfkill.h mbfutil.h mbfindex.h mbfcheck.h mbfpack.h mbflist.h mbfadopt.h \
mbfimport.h virscan.h mbftoberep.h mbfmove.h mbfimport.h virscan.h mbftoberep.h mbfmove.h mbfdel.h
MBFIDO_OBJS = flock.o tosspkt.o mbfido.o hatch.o maketags.o virscan.o \ MBFIDO_OBJS = flock.o tosspkt.o mbfido.o hatch.o maketags.o virscan.o \
tracker.o makestat.o scannews.o lhash.o \ tracker.o makestat.o scannews.o lhash.o \
pack.o ulock.o tic.o ptic.o utic.o mover.o hash.o mkftnhdr.o \ pack.o ulock.o tic.o ptic.o utic.o mover.o hash.o mkftnhdr.o \
@ -36,7 +36,7 @@ MBAFF_OBJS = announce.o fflist.o filefind.o grlist.o mbaff.o msgutil.o
MBINDEX_OBJS = mbindex.o MBINDEX_OBJS = mbindex.o
MBDIFF_OBJS = mbdiff.o MBDIFF_OBJS = mbdiff.o
MBFILE_OBJS = mbfile.o mbfkill.o mbfutil.o mbfindex.o mbfcheck.o mbfpack.o mbflist.o mbfadopt.o \ MBFILE_OBJS = mbfile.o mbfkill.o mbfutil.o mbfindex.o mbfcheck.o mbfpack.o mbflist.o mbfadopt.o \
mbfimport.o virscan.o mbftoberep.o mbfmove.o mbfimport.o virscan.o mbftoberep.o mbfmove.o mbfdel.o
MBMSG_OBJS = post.o mbmsg.o MBMSG_OBJS = post.o mbmsg.o
MBFIDO_LIBS = ../lib/libmemwatch.a ../lib/libclcomm.a ../lib/libcommon.a ../lib/libmsgbase.a \ MBFIDO_LIBS = ../lib/libmemwatch.a ../lib/libclcomm.a ../lib/libcommon.a ../lib/libmsgbase.a \
../lib/libdbase.a ../lib/libmbinet.a ../lib/libdbase.a ../lib/libmbinet.a

126
mbfido/mbfdel.c Normal file
View File

@ -0,0 +1,126 @@
/*****************************************************************************
*
* $Id$
* Purpose: File Database Maintenance - Delete/Undelete a file
*
*****************************************************************************
* Copyright (C) 1997-2001
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MBSE BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MBSE BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
#include "../lib/libs.h"
#include "../lib/structs.h"
#include "../lib/records.h"
#include "../lib/common.h"
#include "../lib/clcomm.h"
#include "../lib/dbcfg.h"
#include "mbfutil.h"
#include "mbfmove.h"
extern int do_quiet; /* Supress screen output */
/*
* Move a file
*/
void Delete(int UnDel, int Area, char *File)
{
char *temp;
struct FILERecord fdb;
FILE *fp;
int rc = FALSE;
if (UnDel)
IsDoing("Undelete file");
else
IsDoing("Delete file");
colour(LIGHTRED, BLACK);
/*
* Check area
*/
if (LoadAreaRec(Area) == FALSE) {
WriteError("Can't load record %d", Area);
die(0);
}
if (!area.Available) {
WriteError("Area %d not available", Area);
if (!do_quiet)
printf("Area %d not available\n", Area);
die(0);
}
if (area.CDrom) {
WriteError("Can't %sdelete from CD-ROM", UnDel?"un":"");
if (!do_quiet)
printf("Can't %sdelete from CD-ROM\n", UnDel?"un":"");
die(0);
}
if (CheckFDB(Area, area.Path))
die(0);
temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), Area);
if ((fp = fopen(temp, "r+")) == NULL)
die(0);
colour(CYAN, BLACK);
while (fread(&fdb, sizeof(fdb), 1, fp) == 1) {
if (! strcmp(fdb.LName, File)) {
if (UnDel && fdb.Deleted) {
fdb.Deleted = FALSE;
Syslog('+', "Marked file %s in area %d for undeletion", File, Area);
if (!do_quiet)
printf("Marked file %s in area %d for undeletion\n", File, Area);
rc = TRUE;
}
if (!UnDel && !fdb.Deleted) {
fdb.Deleted = TRUE;
Syslog('+', "Marked file %s in area %d for undeletion", File, Area);
if (!do_quiet)
printf("Marked file %s in area %d for undeletion\n", File, Area);
rc = TRUE;
}
if (rc) {
fseek(fp, - sizeof(fdb), SEEK_CUR);
fwrite(&fdb, sizeof(fdb), 1, fp);
}
break;
}
}
fclose(fp);
if (!rc) {
Syslog('+', "%selete %s in area %d failed", UnDel?"Und":"D", File, Area);
if (!do_quiet)
printf("%selete %s in area %d failed\n", UnDel?"Und":"D", File, Area);
}
free(temp);
}

8
mbfido/mbfdel.h Normal file
View File

@ -0,0 +1,8 @@
/* $Id$ */
#ifndef _MBFDELE_H
#define _MBFDELE_H
void Delete(int, int, char *);
#endif

View File

@ -43,6 +43,7 @@
#include "mbfimport.h" #include "mbfimport.h"
#include "mbftoberep.h" #include "mbftoberep.h"
#include "mbfmove.h" #include "mbfmove.h"
#include "mbfdel.h"
#include "mbfutil.h" #include "mbfutil.h"
#include "mbfile.h" #include "mbfile.h"
@ -59,6 +60,7 @@ int do_import= FALSE; /* Import files in area */
int do_list = FALSE; /* List fileareas */ int do_list = FALSE; /* List fileareas */
int do_tobe = FALSE; /* List toberep database */ int do_tobe = FALSE; /* List toberep database */
int do_move = FALSE; /* Move a file */ int do_move = FALSE; /* Move a file */
int do_del = FALSE; /* Delete/undelete a file */
extern int e_pid; /* Pid of external process */ extern int e_pid; /* Pid of external process */
extern int show_log; /* Show logging */ extern int show_log; /* Show logging */
time_t t_start; /* Start time */ time_t t_start; /* Start time */
@ -68,7 +70,7 @@ time_t t_end; /* End time */
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int i, Area = 0, ToArea = 0; int i, Area = 0, ToArea = 0, UnDel = FALSE;
char *cmd, *FileName = NULL, *Description = NULL; char *cmd, *FileName = NULL, *Description = NULL;
struct passwd *pw; struct passwd *pw;
@ -121,6 +123,22 @@ int main(int argc, char **argv)
Description = xstrcpy(argv[i]); Description = xstrcpy(argv[i]);
} }
} }
} else if ((!strncasecmp(argv[i], "d", 1)) || (!strncasecmp(argv[i], "u", 1))) {
if (!strncasecmp(argv[i], "u", 1))
UnDel = TRUE;
if (argc > (i + 1)) {
i++;
Area = atoi(argv[i]);
cmd = xstrcat(cmd, argv[i]);
cmd = xstrcat(cmd, argv[i]);
if (argc > (i + 1)) {
i++;
FileName = xstrcpy(argv[i]);
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
do_del = TRUE;
}
}
} else if (!strncasecmp(argv[i], "in", 2)) { } else if (!strncasecmp(argv[i], "in", 2)) {
do_index = TRUE; do_index = TRUE;
} else if (!strncasecmp(argv[i], "im", 2)) { } else if (!strncasecmp(argv[i], "im", 2)) {
@ -174,7 +192,7 @@ int main(int argc, char **argv)
} }
} }
if (!(do_pack || do_check || do_kill || do_index || do_import || do_list || do_adopt || do_move || do_tobe)) if (!(do_pack || do_check || do_kill || do_index || do_import || do_list || do_adopt || do_del || do_move || do_tobe))
Help(); Help();
ProgName(); ProgName();
@ -219,6 +237,11 @@ int main(int argc, char **argv)
die(0); die(0);
} }
if (do_del) {
Delete(UnDel, Area, FileName);
die(0);
}
if (do_list) { if (do_list) {
ListFileAreas(Area); ListFileAreas(Area);
die(0); die(0);

View File

@ -95,8 +95,8 @@ void die(int onsig)
Syslog(' ', "MBFILE finished in %s", t_elapsed(t_start, t_end)); Syslog(' ', "MBFILE finished in %s", t_elapsed(t_start, t_end));
if (!do_quiet) { if (!do_quiet) {
colour(7, 0); colour(LIGHTGRAY, BLACK);
printf("\n"); fflush(stdout);
} }
ExitClient(onsig); ExitClient(onsig);
} }
@ -115,7 +115,7 @@ void Help(void)
colour(CYAN, BLACK); colour(CYAN, BLACK);
printf(" a adopt <area> <file> [desc] Adopt file to area\n"); printf(" a adopt <area> <file> [desc] Adopt file to area\n");
printf(" c check Check filebase\n"); printf(" c check Check filebase\n");
// printf(" d delete <area> <file> Mark file in area for deletion\n"); printf(" d delete <area> <file> Mark file in area for deletion\n");
printf(" im import <area> Import files in current dir to area\n"); printf(" im import <area> Import files in current dir to area\n");
printf(" in index Create filerequest index\n"); printf(" in index Create filerequest index\n");
printf(" k kill Kill/move old files\n"); printf(" k kill Kill/move old files\n");
@ -124,13 +124,12 @@ void Help(void)
printf(" p pack Pack filebase\n"); printf(" p pack Pack filebase\n");
// printf(" r rearc <area> [file] [arc] Rearc file(s) in area\n"); // printf(" r rearc <area> [file] [arc] Rearc file(s) in area\n");
printf(" t toberep Show toberep database\n"); printf(" t toberep Show toberep database\n");
printf(" u undelete <area> <file> Mark file in area for undeletion\n");
colour(LIGHTBLUE, BLACK); colour(LIGHTBLUE, BLACK);
printf("\n Options are:\n\n"); printf("\n Options are:\n\n");
colour(CYAN, BLACK); colour(CYAN, BLACK);
printf(" -a -announce Supress announce added files\n"); printf(" -a -announce Supress announce added files\n");
printf(" -q -quiet Quiet mode\n"); printf(" -q -quiet Quiet mode\n");
colour(LIGHTGRAY, BLACK);
printf("\n");
die(0); die(0);
} }