[3046] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[PATCH] owl_util_file_deleteline should not error on non-existent file

daemon@ATHENA.MIT.EDU (Jason Gross)
Tue May 17 11:46:35 2011

From: Jason Gross <jgross@MIT.EDU>
To: barnowl-dev@mit.edu
Cc: Jason Gross <jgross@mit.edu>
Date: Tue, 17 May 2011 11:46:19 -0400

This fixes trac #175: '"startup" command produces error when run for the
first time'.  The startup command deletes duplicate lines, and thus
errored when no file existed.  The purpose of owl_util_file_deleteline
is to make sure that the given line is no longer in the file, so there
seems to be no harm in returning 0 (meaning no lines were deleted) on
the file not existing.
---
 util.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/util.c b/util.c
index 82f36ef..44899f0 100644
--- a/util.c
+++ b/util.c
@@ -423,6 +423,7 @@ gchar *owl_util_recursive_resolve_link(const char *filename)
  * case-insensitive.
  *
  * Returns the number of lines removed on success.  Returns -1 on failure.
+ * Returns 0 if the file does not exist; the line wasn't present.
  */
 int owl_util_file_deleteline(const char *filename, const char *line, int backup)
 {
@@ -433,6 +434,7 @@ int owl_util_file_deleteline(const char *filename, const char *line, int backup)
   int numremoved = 0;
 
   if ((old = fopen(filename, "r")) == NULL) {
+    if (errno == ENOENT) return 0;
     owl_function_error("Cannot open %s (for reading): %s",
 		       filename, strerror(errno));
     return -1;
-- 
1.7.2.3


home help back first fref pref prev next nref lref last post