Login | Register
My pages Projects Community openCollabNet

Discussions > commits > svn commit: r1552 - trunk: . fsvs/src

fsvs
Discussion topic

Back to topic list

svn commit: r1552 - trunk: . fsvs/src

Author pmarek
Full name P.Marek
Date 2008-03-16 23:08:53 PDT
Message Author: pmarek
Date: 2008-03-16 23:08:53-0700
New Revision: 1552

Modified:
   trunk/ (props changed)
   trunk/fsvs/src/waa.c

Log:
Allow waa__close() to close filehandles not stored in the array.
Now it's easier to open a file with
  (expr) ? WAA__APPEND | WAA__WRITE,
and just do always a waa__close() later.




Modified: trunk/fsvs/src/waa.c
Url: http://fsvs.tigris.o​rg/source/browse/fsv​s/trunk/fsvs/src/waa​.c?view=diff&rev​=1552&p1=trunk/f​svs/src/waa.c&p2​=trunk/fsvs/src/waa.​c&r1=1551&r2​=1552
====================​====================​====================​==================
--- trunk/fsvs/src/waa.c (original)
+++ trunk/fsvs/src/waa.c 2008-03-16 23:08:53-0700
@@ -596,47 +596,44 @@
  * failed somewhere; so the temporary file is not renamed to the
  * destination name, just removed.
  *
- * This may be called only for *writeable* files of waa__open and similar;
- * readonly files should just be close()d. */
+ * This may be called only for \b writeable files of waa__open() and
+ * similar; readonly files should just be \c close()d. */
 int waa__close(int filehandle, int has_failed)
 {
     int status, do_unlink;
     struct waa___temp_names_t *target;
- char *cp;
 
 
     /* Assume we have to remove the file; only if the rename
      * is successful, this ain't true. */
     do_unlink=1;
     status=0;
- BUG_ON(!target_name_array);
- target=target_name_a​rray+filehandle;
- BUG_ON(!target);
 
+ target= target_name_array ? target_name_array+filehandle : NULL;
+
+ if (target)
     DEBUGP("filehandle %d should be %s", filehandle, target->dest_name);
+ else
+ DEBUGP("filehandle %d wasn't opened via waa__open()!", filehandle);
 
     status=close(filehandle);
     if (!has_failed)
     {
         STOPIF_CODE_ERR(status == -1, errno, "closing tmp file");
 
+ if (target)
+ {
         /* Now that we know we'd like to keep that file, make the directories
- * as needed.
- * Sadly we have to duplicate some logic from waa__mkdir().
- * Maybe that could be refactored a bit - with a function like
- * waa__make_parent_dirs()? */
- cp=strrchr(target-​>dest_name, PATH_SEPARATOR);
- BUG_ON(!cp);
-
- *cp=0;
- STOPIF( waa__mkdir(target-​>dest_name, 1), NULL);
- *cp=PATH_SEPARATOR;
+ * as needed. */
+ STOPIF( waa__mkdir(target-​>dest_name, 0), NULL);
 
         /* And give it the correct name. */
         STOPIF_CODE_ERR(
                 rename(target->temp_name, target->dest_name) == -1,
                 errno, "renaming tmp file from %s to %s",
                 target->temp_name, target->dest_name);
+ }
+
         do_unlink=0;
     }
 
@@ -645,15 +642,18 @@
 ex:
     /* If there's an error while closing the file (or already given
      * due to has_failed), unlink the file. */
- if (do_unlink)
+ if (do_unlink && target)
     {
         do_unlink=0;
         STOPIF_CODE_ERR( unlink(target->temp_name) == -1, errno,
                 "Cannot remove temporary file %s", target->temp_name);
     }
 
+ if (target)
+ {
     IF_FREE(target->temp_name);
     IF_FREE(target->dest_name);
+ }
 
     return status;
 }

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

svn commit: r1552 - trunk: . fsvs/src pmarek P.Marek 2008-03-16 23:08:53 PDT
Messages per page: