summaryrefslogtreecommitdiffstats
path: root/vi/vim-7.2/7.2.077
blob: 396444c3d0a6ed2eb0d80aae402e8aa46769baa2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
To: vim-dev@vim.org
Subject: Patch 7.2.077
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
------------

Patch 7.2.077 (after 7.2.076)
Problem:    rename(from, to) doesn't work if "from" and "to" differ only in
	    case on a system that ignores case in file names.
Solution:   Go through another file name.
Files:	    src/fileio.c


*** ../vim-7.2.076/src/fileio.c	Tue Dec 30 16:15:16 2008
--- src/fileio.c	Wed Dec 31 14:59:59 2008
***************
*** 6106,6117 ****
  #ifdef HAVE_ACL
      vim_acl_T	acl;		/* ACL from original file */
  #endif
  
      /*
!      * When the names are identical, there is nothing to do.
       */
      if (fnamecmp(from, to) == 0)
! 	return 0;
  
      /*
       * Fail if the "from" file doesn't exist.  Avoids that "to" is deleted.
--- 6106,6129 ----
  #ifdef HAVE_ACL
      vim_acl_T	acl;		/* ACL from original file */
  #endif
+ #if defined(UNIX) || defined(CASE_INSENSITIVE_FILENAME)
+     int		use_tmp_file = FALSE;
+ #endif
  
      /*
!      * When the names are identical, there is nothing to do.  When they refer
!      * to the same file (ignoring case and slash/backslash differences) but
!      * the file name differs we need to go through a temp file.
       */
      if (fnamecmp(from, to) == 0)
!     {
! #ifdef CASE_INSENSITIVE_FILENAME
! 	if (STRCMP(gettail(from), gettail(to)) != 0)
! 	    use_tmp_file = TRUE;
! 	else
! #endif
! 	    return 0;
!     }
  
      /*
       * Fail if the "from" file doesn't exist.  Avoids that "to" is deleted.
***************
*** 6122,6128 ****
  #ifdef UNIX
      {
  	struct stat	st_to;
- 	char		tempname[MAXPATHL + 1];
  
  	/* It's possible for the source and destination to be the same file.
  	 * This happens when "from" and "to" differ in case and are on a FAT32
--- 6134,6139 ----
***************
*** 6130,6162 ****
  	if (mch_stat((char *)to, &st_to) >= 0
  		&& st.st_dev == st_to.st_dev
  		&& st.st_ino == st_to.st_ino)
  	{
! 	    /* Find a name that doesn't exist and is in the same directory.
! 	     * Move "from" to "tempname" and then to "to". */
! 	    if (STRLEN(from) >= MAXPATHL - 5)
! 		return -1;
! 	    STRCPY(tempname, from);
! 	    for (n = 123; n < 99999; ++n)
  	    {
! 		sprintf(gettail(tempname), "%d", n);
! 		if (mch_stat(tempname, &st_to) < 0)
  		{
! 		    if (mch_rename((char *)from, tempname) == 0)
! 		    {
! 			if (mch_rename(tempname, (char *)to) == 0)
! 			    return 0;
! 			/* Strange, the second step failed.  Try moving the
! 			 * file back and return failure. */
! 			mch_rename(tempname, (char *)from);
! 			return -1;
! 		    }
! 		    /* If it fails for one temp name it will most likely fail
! 		     * for any temp name, give up. */
  		    return -1;
  		}
  	    }
- 	    return -1;
  	}
      }
  #endif
  
--- 6141,6182 ----
  	if (mch_stat((char *)to, &st_to) >= 0
  		&& st.st_dev == st_to.st_dev
  		&& st.st_ino == st_to.st_ino)
+ 	    use_tmp_file = TRUE;
+     }
+ #endif
+ 
+ #if defined(UNIX) || defined(CASE_INSENSITIVE_FILENAME)
+     if (use_tmp_file)
+     {
+ 	char	tempname[MAXPATHL + 1];
+ 
+ 	/*
+ 	 * Find a name that doesn't exist and is in the same directory.
+ 	 * Rename "from" to "tempname" and then rename "tempname" to "to".
+ 	 */
+ 	if (STRLEN(from) >= MAXPATHL - 5)
+ 	    return -1;
+ 	STRCPY(tempname, from);
+ 	for (n = 123; n < 99999; ++n)
  	{
! 	    sprintf((char *)gettail((char_u *)tempname), "%d", n);
! 	    if (mch_stat(tempname, &st) < 0)
  	    {
! 		if (mch_rename((char *)from, tempname) == 0)
  		{
! 		    if (mch_rename(tempname, (char *)to) == 0)
! 			return 0;
! 		    /* Strange, the second step failed.  Try moving the
! 		     * file back and return failure. */
! 		    mch_rename(tempname, (char *)from);
  		    return -1;
  		}
+ 		/* If it fails for one temp name it will most likely fail
+ 		 * for any temp name, give up. */
+ 		return -1;
  	    }
  	}
+ 	return -1;
      }
  #endif
  
*** ../vim-7.2.076/src/version.c	Tue Dec 30 16:15:16 2008
--- src/version.c	Wed Dec 31 16:19:29 2008
***************
*** 678,679 ****
--- 678,681 ----
  {   /* Add new patch number below this line */
+ /**/
+     77,
  /**/

-- 
We apologise again for the fault in the subtitles.  Those responsible for
sacking the people who have just been sacked have been sacked.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///