[PATCH:makedepend] Bug 52099 - makedepend rename fails on CIFS mounted shares

Alan Coopersmith alan.coopersmith at oracle.com
Fri Jan 11 22:30:12 PST 2013


From: Glenn Burkhardt <gbburkhardt at gmail.com>

Patch v1: https://bugs.freedesktop.org/attachment.cgi?id=64218

v2: modified by Alan Coopersmith to restore Makefile to original name
if contents cannot be read, instead of leaving it moved to .bak name.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 main.c |   24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/main.c b/main.c
index b13e020..8691395 100644
--- a/main.c
+++ b/main.c
@@ -739,21 +739,23 @@ redirect(const char *line, const char *makefile)
 		else
 			fatalerr("[mM]akefile is not present\n");
 	}
-	else
-	    stat(makefile, &st);
-	if ((fdin = fopen(makefile, "r")) == NULL)
-		fatalerr("cannot open \"%s\"\n", makefile);
+	else {
+		if (stat(makefile, &st) != 0)
+			fatalerr("\"%s\" is not present\n", makefile);
+	}
+
 	snprintf(backup, sizeof(backup), "%s.bak", makefile);
 	unlink(backup);
-#if defined(WIN32) || defined(__CYGWIN__)
-	fclose(fdin);
-#endif
+
+	/* rename() won't work on WIN32, CYGWIN, or CIFS if src file is open */
 	if (rename(makefile, backup) < 0)
 		fatalerr("cannot rename %s to %s\n", makefile, backup);
-#if defined(WIN32) || defined(__CYGWIN__)
-	if ((fdin = fopen(backup, "r")) == NULL)
-		fatalerr("cannot open \"%s\"\n", backup);
-#endif
+	if ((fdin = fopen(backup, "r")) == NULL) {
+		if (rename(backup, makefile) < 0)
+			warning("renamed %s to %s, but can't move it back\n",
+				makefile, backup);
+		fatalerr("cannot open \"%s\"\n", makefile);
+	}
 	if ((fdout = freopen(makefile, "w", stdout)) == NULL)
 		fatalerr("cannot open \"%s\"\n", backup);
 	len = strlen(line);
-- 
1.7.9.2



More information about the xorg-devel mailing list