]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/file.c
Fix clearing mutable flags on ef_close()
[empserver] / src / lib / common / file.c
index a95de92f521f2b6e33f6fbb8f00db9e9bef8248e..388f8c6a5e11a7aac925999c0cb7ee9240bbadd6 100644 (file)
@@ -117,8 +117,8 @@ ef_open(int type, int how, int nelt)
        /* ep->cache already points to space for ep->csize elements */
        if (how & EFF_MEM) {
            if (ep->fids > ep->csize) {
-               logerror("Can't open %s: file larger than %d bytes",
-                        ep->file, ep->fids * ep->size);
+               logerror("Can't open %s (file larger than %d records)",
+                        ep->file, ep->csize);
                close(fd);
                return 0;
            }
@@ -145,7 +145,6 @@ ef_open(int type, int how, int nelt)
     if ((how & EFF_MEM) && ep->fids) {
        if (fillcache(ep, 0) != ep->fids) {
            ep->cids = 0;       /* prevent cache flush */
-           ep->flags &= EFF_IMMUTABLE; /* maintain invariant */
            ef_close(type);
            return 0;
        }
@@ -246,7 +245,7 @@ ef_open_view(int type, int base)
 }
 
 /*
- * Close the file-backed table TYPE (EF_SECTOR, ...).
+ * Close the open table TYPE (EF_SECTOR, ...).
  * Return non-zero on success, zero on failure.
  */
 int
@@ -264,7 +263,6 @@ ef_close(int type)
     else {
        if (!ef_flush(type))
            retval = 0;
-       ep->flags &= EFF_IMMUTABLE;
        if (!(ep->flags & EFF_STATIC)) {
            free(ep->cache);
            ep->cache = NULL;
@@ -275,6 +273,7 @@ ef_close(int type)
        }
        ep->fd = -1;
     }
+    ep->flags &= EFF_IMMUTABLE;
     ep->baseid = ep->cids = ep->fids = 0;
     if (ep->onresize && ep->onresize(type) < 0)
        retval = 0;
@@ -715,7 +714,7 @@ ef_extend(int type, int count)
 }
 
 /*
- * Initialize element ID for EP in BUF.
+ * Initialize element ID for table TYPE in BUF.
  * FIXME pass buffer size!
  * BUF is marked fresh with ef_mark_fresh().
  */