summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Burkhardt <gbburkhardt@gmail.com>2013-01-11 22:09:54 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-01-16 22:58:53 -0800
commit059e9be5a7321974b190d786d426b2ae27be8c56 (patch)
tree763d349c89473c8f3f4831cd3916022e3c49ca76
parentbb29c304c09aba567af0f0d77a63f0202c3836c6 (diff)
downloadxorg-util-makedepend-059e9be5a7321974b190d786d426b2ae27be8c56.tar.gz
Bug 52099 - makedepend rename fails on CIFS mounted shares
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@oracle.com>
-rw-r--r--main.c24
1 files 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);