Author: marvin
Date: Wed Aug 22 00:22:25 2012
New Revision: 1375861
URL: http://svn.apache.org/viewvc?rev=1375861&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/branches/0.3/ (props changed)
lucy/branches/0.3/charmonizer/src/Charmonizer/Core/Compiler.c
lucy/branches/0.3/charmonizer/src/Charmonizer/Core/Util.c
lucy/branches/0.3/charmonizer/src/Charmonizer/Core/Util.h
lucy/branches/0.3/charmonizer/src/Charmonizer/Probe.c
Propchange: lucy/branches/0.3/
------------------------------------------------------------------------------
Merged /lucy/trunk:r1375860
Modified: lucy/branches/0.3/charmonizer/src/Charmonizer/Core/Compiler.c
URL:
http://svn.apache.org/viewvc/lucy/branches/0.3/charmonizer/src/Charmonizer/Core/Compiler.c?rev=1375861&r1=1375860&r2=1375861&view=diff
==============================================================================
--- lucy/branches/0.3/charmonizer/src/Charmonizer/Core/Compiler.c (original)
+++ lucy/branches/0.3/charmonizer/src/Charmonizer/Core/Compiler.c Wed Aug 22
00:22:25 2012
@@ -168,17 +168,11 @@ CC_compile_exe(const char *source_path,
/* TODO: Key this off the compiler supplied as argument, not the compiler
* used to compile Charmonizer. */
sprintf(junk, "%s.obj", exe_name);
- if (!OS_remove(junk)) {
- Util_warn("Error removing [%s] due to the following error: [%s]\n",
junk, strerror(errno));
- }
+ Util_remove_and_verify(junk);
sprintf(junk, "%s.ilk", exe_name);
- if (!OS_remove(junk)) {
- Util_warn("Error removing [%s] due to the following error: [%s]\n",
junk, strerror(errno));
- }
+ Util_remove_and_verify(junk);
sprintf(junk, "%s.pdb", exe_name);
- if (!OS_remove(junk)) {
- Util_warn("Error removing [%s] due to the following error: [%s]\n",
junk, strerror(errno));
- }
+ Util_remove_and_verify(junk);
#endif
/* See if compilation was successful. Remove the source file. */
@@ -249,9 +243,7 @@ CC_test_compile(const char *source, size
}
compile_succeeded = CC_compile_obj(TRY_SOURCE_PATH, TRY_BASENAME,
source, source_len);
- if (!OS_remove(try_obj_name)) {
- Util_warn("Error removing [%s] due to the following error: [%s]\n",
try_obj_name, strerror(errno));
- }
+ Util_remove_and_verify(try_obj_name);
return compile_succeeded;
}
@@ -280,13 +272,9 @@ CC_capture_output(const char *source, si
}
/* Remove all the files we just created. */
- if (!OS_remove(TRY_SOURCE_PATH)) {
- Util_warn("Error removing [%s] due to the following error: [%s]\n",
TRY_SOURCE_PATH, strerror(errno));
- }
- OS_remove_exe(TRY_BASENAME);
- if (!OS_remove(TARGET_PATH)) {
- Util_warn("Error removing [%s] due to the following error: [%s]\n",
TARGET_PATH, strerror(errno));
- }
+ 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/branches/0.3/charmonizer/src/Charmonizer/Core/Util.c
URL:
http://svn.apache.org/viewvc/lucy/branches/0.3/charmonizer/src/Charmonizer/Core/Util.c?rev=1375861&r1=1375860&r2=1375861&view=diff
==============================================================================
--- lucy/branches/0.3/charmonizer/src/Charmonizer/Core/Util.c (original)
+++ lucy/branches/0.3/charmonizer/src/Charmonizer/Core/Util.c Wed Aug 22
00:22:25 2012
@@ -133,13 +133,18 @@ Util_warn(const char* format, ...) {
int
Util_remove_and_verify(const char *file_path) {
- /* Try to remove the file. */
- if (!OS_remove(file_path)) {
- Util_warn("Error removing [%s] due to the following error: [%s]\n",
file_path, strerror(errno));
+ /* 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/branches/0.3/charmonizer/src/Charmonizer/Core/Util.h
URL:
http://svn.apache.org/viewvc/lucy/branches/0.3/charmonizer/src/Charmonizer/Core/Util.h?rev=1375861&r1=1375860&r2=1375861&view=diff
==============================================================================
--- lucy/branches/0.3/charmonizer/src/Charmonizer/Core/Util.h (original)
+++ lucy/branches/0.3/charmonizer/src/Charmonizer/Core/Util.h Wed Aug 22
00:22:25 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/branches/0.3/charmonizer/src/Charmonizer/Probe.c
URL:
http://svn.apache.org/viewvc/lucy/branches/0.3/charmonizer/src/Charmonizer/Probe.c?rev=1375861&r1=1375860&r2=1375861&view=diff
==============================================================================
--- lucy/branches/0.3/charmonizer/src/Charmonizer/Probe.c (original)
+++ lucy/branches/0.3/charmonizer/src/Charmonizer/Probe.c Wed Aug 22 00:22:25
2012
@@ -85,6 +85,6 @@ S_write_charm_h(void) {
static void
S_remove_charm_h(void) {
- OS_remove("_charm.h");
+ Util_remove_and_verify("_charm.h");
}