X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=bfile%2Fmfile.c;h=5f0547355e2285b816e58334fa4d559c806209ac;hb=9eaf65aa25be411fbd6298292f5ad7a7df7083ed;hp=7a437c0b56e8f3fcebcbd61fbc097c8fe3d96949;hpb=30bb91a2915de98455a8f7a5af5c087239f22203;p=idzebra-moved-to-github.git diff --git a/bfile/mfile.c b/bfile/mfile.c index 7a437c0..5f05473 100644 --- a/bfile/mfile.c +++ b/bfile/mfile.c @@ -1,5 +1,5 @@ -/* $Id: mfile.c,v 1.64 2006-05-05 09:14:02 adam Exp $ - Copyright (C) 1995-2005 +/* $Id: mfile.c,v 1.69 2006-10-10 10:19:28 adam Exp $ + Copyright (C) 1995-2006 Index Data ApS This file is part of the Zebra server. @@ -15,9 +15,9 @@ 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 Zebra; see the file LICENSE.zebra. If not, write to the -Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ @@ -252,7 +252,6 @@ MFile_area mf_init(const char *name, const char *spec, const char *base) meta_f->next = ma->mfiles; meta_f->open = 0; meta_f->cur_file = -1; - meta_f->unlink_flag = 0; ma->mfiles = meta_f; strcpy(meta_f->name, metaname); part_f = &meta_f->files[0]; @@ -298,7 +297,6 @@ MFile_area mf_init(const char *name, const char *spec, const char *base) void mf_destroy(MFile_area ma) { mf_dir *dp; - meta_file *meta_f; if (!ma) return; @@ -309,24 +307,11 @@ void mf_destroy(MFile_area ma) dp = dp->next; xfree (d); } - meta_f = ma->mfiles; - while (meta_f) - { - int i; - meta_file *m = meta_f; - - for (i = 0; ino_files; i++) - { - xfree (m->files[i].path); - } - zebra_mutex_destroy (&meta_f->mutex); - meta_f = meta_f->next; - xfree (m); - } + mf_reset(ma, 0); xfree (ma); } -void mf_reset(MFile_area ma) +void mf_reset(MFile_area ma, int unlink_flag) { meta_file *meta_f; @@ -338,13 +323,16 @@ void mf_reset(MFile_area ma) int i; meta_file *m = meta_f; + meta_f = meta_f->next; + assert (!m->open); for (i = 0; ino_files; i++) { - unlink (m->files[i].path); + if (unlink_flag) + unlink (m->files[i].path); xfree (m->files[i].path); } - meta_f = meta_f->next; + zebra_mutex_destroy (&m->mutex); xfree (m); } ma->mfiles = 0; @@ -352,7 +340,6 @@ void mf_reset(MFile_area ma) /* * Open a metafile. - * If !ma, Use MF_DEFAULT_AREA. */ MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag) { @@ -384,7 +371,6 @@ MFile mf_open(MFile_area ma, const char *name, int block_size, int wflag) mnew->files[0].top = -1; mnew->files[0].number = 0; mnew->files[0].fd = -1; - mnew->unlink_flag = 0; mnew->min_bytes_creat = MF_MIN_BLOCKS_CREAT * block_size; for (dp = ma->dirs; dp && dp->max_bytes >= 0 && dp->avail_bytes < mnew->min_bytes_creat; dp = dp->next); @@ -437,7 +423,7 @@ int mf_close(MFile mf) { int i; - yaz_log (YLOG_DEBUG, "mf_close(%s) unlink=%d", mf->name, mf->unlink_flag); + yaz_log (YLOG_DEBUG, "mf_close(%s)", mf->name); assert(mf->open); for (i = 0; i < mf->no_files; i++) { @@ -449,8 +435,6 @@ int mf_close(MFile mf) close(mf->files[i].fd); mf->files[i].fd = -1; } - if (mf->unlink_flag) - unlink(mf->files[i].path); } mf->open = 0; return 0; @@ -598,24 +582,6 @@ int mf_write(MFile mf, zint no, int offset, int nbytes, const void *buf) return 0; } -/* - * Destroy a metafile, unlinking component files. File must be open. - */ -int mf_unlink(MFile mf) -{ - if (mf->open) - { - mf->unlink_flag = 1; - } - else - { - int i; - for (i = 0; ino_files; i++) - unlink(mf->files[i].path); - } - return 0; -} - int mf_area_directory_stat(MFile_area ma, int no, const char **directory, double *used_bytes, double *max_bytes) { @@ -628,8 +594,22 @@ int mf_area_directory_stat(MFile_area ma, int no, const char **directory, if (directory) *directory = d->name; if (max_bytes) - *max_bytes = d->max_bytes; + { + /* possible loss of data. But it's just statistics and lies */ + *max_bytes = (double) d->max_bytes; + } if (used_bytes) - *used_bytes = d->max_bytes - d->avail_bytes; + { + /* possible loss of data. But it's just statistics and lies */ + *used_bytes = (double) (d->max_bytes - d->avail_bytes); + } return 1; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +