lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] svn commit: r1375860 - in /lucy/trunk/charmonizer/src/Charmonizer: Core/Compiler.c Core/Util.c Core/Util.h Probe.c
Date Wed, 22 Aug 2012 00:14:33 GMT
Author: marvin
Date: Wed Aug 22 00:14:33 2012
New Revision: 1375860

URL: http://svn.apache.org/viewvc?rev=1375860&view=rev
Log:
LUCY-243 Warn when file deletion fails.

*   Use the return value of remove() to determine success/failure
    instead of fopen().
*   Warn if it cannot be guaranteed that the file is gone.
*   Wrap all file removals from the Charmonizer core in
    Util_remove_and_verify().

This commit requires ENOENT which is POSIX not C89 but should work for 
the time being.

Modified:
    lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.c
    lucy/trunk/charmonizer/src/Charmonizer/Core/Util.c
    lucy/trunk/charmonizer/src/Charmonizer/Core/Util.h
    lucy/trunk/charmonizer/src/Charmonizer/Probe.c

Modified: lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.c
URL: http://svn.apache.org/viewvc/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.c?rev=1375860&r1=1375859&r2=1375860&view=diff
==============================================================================
--- lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.c (original)
+++ lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.c Wed Aug 22 00:14:33 2012
@@ -219,11 +219,11 @@ CC_compile_exe(const char *source_path, 
     if (defines__MSC_VER) {
         /* Zap MSVC junk. */
         sprintf(junk, "%s.obj", exe_name);
-        OS_remove(junk);
+        Util_remove_and_verify(junk);
         sprintf(junk, "%s.ilk", exe_name);
-        OS_remove(junk);
+        Util_remove_and_verify(junk);
         sprintf(junk, "%s.pdb", exe_name);
-        OS_remove(junk);
+        Util_remove_and_verify(junk);
     }
 
     /* See if compilation was successful.  Remove the source file. */
@@ -295,7 +295,7 @@ CC_test_compile(const char *source) {
     }
     compile_succeeded = CC_compile_obj(TRY_SOURCE_PATH, TRY_BASENAME,
                                        source);
-    OS_remove(try_obj_name);
+    Util_remove_and_verify(try_obj_name);
     return compile_succeeded;
 }
 
@@ -324,9 +324,9 @@ CC_capture_output(const char *source, si
     }
 
     /* Remove all the files we just created. */
-    OS_remove(TRY_SOURCE_PATH);
-    OS_remove_exe(TRY_BASENAME);
-    OS_remove(TARGET_PATH);
+    Util_remove_and_verify(TRY_SOURCE_PATH);
+    Util_remove_and_verify(try_exe_name);
+    Util_remove_and_verify(TARGET_PATH);
 
     return captured_output;
 }

Modified: lucy/trunk/charmonizer/src/Charmonizer/Core/Util.c
URL: http://svn.apache.org/viewvc/lucy/trunk/charmonizer/src/Charmonizer/Core/Util.c?rev=1375860&r1=1375859&r2=1375860&view=diff
==============================================================================
--- lucy/trunk/charmonizer/src/Charmonizer/Core/Util.c (original)
+++ lucy/trunk/charmonizer/src/Charmonizer/Core/Util.c Wed Aug 22 00:14:33 2012
@@ -132,11 +132,18 @@ Util_warn(const char* format, ...) {
 
 int
 Util_remove_and_verify(const char *file_path) {
-    /* Try to remove the file. */
-    OS_remove(file_path);
+    /* Attempt to delete the file.  If it's gone after the attempt, return
+     * success, whether or not it was there to begin with.
+     * (ENOENT is POSIX not C89, but let's go with it for now.) */
+    int result = OS_remove(file_path);
+    if (result || errno == ENOENT) {
+        return 1;
+    }
 
-    /* Return what *might* be success or failure. */
-    return Util_can_open_file(file_path) ? 0 : 1;
+    /* Issue a warning and return failure. */
+    Util_warn("Failed to remove '%s': %s at %s line %d",
+              file_path, strerror(errno), __FILE__, __LINE__);
+    return 0;
 }
 
 int

Modified: lucy/trunk/charmonizer/src/Charmonizer/Core/Util.h
URL: http://svn.apache.org/viewvc/lucy/trunk/charmonizer/src/Charmonizer/Core/Util.h?rev=1375860&r1=1375859&r2=1375860&view=diff
==============================================================================
--- lucy/trunk/charmonizer/src/Charmonizer/Core/Util.h (original)
+++ lucy/trunk/charmonizer/src/Charmonizer/Core/Util.h Wed Aug 22 00:14:33 2012
@@ -61,11 +61,9 @@ chaz_Util_die(const char *format, ...);
 void
 chaz_Util_warn(const char *format, ...);
 
-/* Attept to delete a file.  Don't error if the file wasn't there to begin
- * with.  Return 1 if it seems like the file is gone because an attempt to
- * open it for reading fails (this doesn't guarantee that the file is gone,
- * but it works well enough for our purposes).  Return 0 if we can still
- * read the file.
+/* Attept to delete a file.  Return true if the file is gone, whether or not
+ * it was there to begin with.  Issue a warning and return false if the file
+ * still exists.
  */
 int
 chaz_Util_remove_and_verify(const char *file_path);

Modified: lucy/trunk/charmonizer/src/Charmonizer/Probe.c
URL: http://svn.apache.org/viewvc/lucy/trunk/charmonizer/src/Charmonizer/Probe.c?rev=1375860&r1=1375859&r2=1375860&view=diff
==============================================================================
--- lucy/trunk/charmonizer/src/Charmonizer/Probe.c (original)
+++ lucy/trunk/charmonizer/src/Charmonizer/Probe.c Wed Aug 22 00:14:33 2012
@@ -78,6 +78,6 @@ S_write_charm_h(void) {
 
 static void
 S_remove_charm_h(void) {
-    OS_remove("_charm.h");
+    Util_remove_and_verify("_charm.h");
 }
 



Mime
View raw message