comparison src/fileio.c @ 1779:28e9eb0f2d84 v7.2.077

updated for version 7.2-077
author vimboss
date Wed, 31 Dec 2008 15:21:32 +0000
parents 0b42546f036b
children ccbd8177e1f4
comparison
equal deleted inserted replaced
1778:0b42546f036b 1779:28e9eb0f2d84
6104 struct stat st; 6104 struct stat st;
6105 long perm; 6105 long perm;
6106 #ifdef HAVE_ACL 6106 #ifdef HAVE_ACL
6107 vim_acl_T acl; /* ACL from original file */ 6107 vim_acl_T acl; /* ACL from original file */
6108 #endif 6108 #endif
6109 #if defined(UNIX) || defined(CASE_INSENSITIVE_FILENAME)
6110 int use_tmp_file = FALSE;
6111 #endif
6109 6112
6110 /* 6113 /*
6111 * When the names are identical, there is nothing to do. 6114 * When the names are identical, there is nothing to do. When they refer
6115 * to the same file (ignoring case and slash/backslash differences) but
6116 * the file name differs we need to go through a temp file.
6112 */ 6117 */
6113 if (fnamecmp(from, to) == 0) 6118 if (fnamecmp(from, to) == 0)
6114 return 0; 6119 {
6120 #ifdef CASE_INSENSITIVE_FILENAME
6121 if (STRCMP(gettail(from), gettail(to)) != 0)
6122 use_tmp_file = TRUE;
6123 else
6124 #endif
6125 return 0;
6126 }
6115 6127
6116 /* 6128 /*
6117 * Fail if the "from" file doesn't exist. Avoids that "to" is deleted. 6129 * Fail if the "from" file doesn't exist. Avoids that "to" is deleted.
6118 */ 6130 */
6119 if (mch_stat((char *)from, &st) < 0) 6131 if (mch_stat((char *)from, &st) < 0)
6120 return -1; 6132 return -1;
6121 6133
6122 #ifdef UNIX 6134 #ifdef UNIX
6123 { 6135 {
6124 struct stat st_to; 6136 struct stat st_to;
6125 char tempname[MAXPATHL + 1];
6126 6137
6127 /* It's possible for the source and destination to be the same file. 6138 /* It's possible for the source and destination to be the same file.
6128 * This happens when "from" and "to" differ in case and are on a FAT32 6139 * This happens when "from" and "to" differ in case and are on a FAT32
6129 * filesystem. In that case go through a temp file name. */ 6140 * filesystem. In that case go through a temp file name. */
6130 if (mch_stat((char *)to, &st_to) >= 0 6141 if (mch_stat((char *)to, &st_to) >= 0
6131 && st.st_dev == st_to.st_dev 6142 && st.st_dev == st_to.st_dev
6132 && st.st_ino == st_to.st_ino) 6143 && st.st_ino == st_to.st_ino)
6133 { 6144 use_tmp_file = TRUE;
6134 /* Find a name that doesn't exist and is in the same directory. 6145 }
6135 * Move "from" to "tempname" and then to "to". */ 6146 #endif
6136 if (STRLEN(from) >= MAXPATHL - 5) 6147
6137 return -1; 6148 #if defined(UNIX) || defined(CASE_INSENSITIVE_FILENAME)
6138 STRCPY(tempname, from); 6149 if (use_tmp_file)
6139 for (n = 123; n < 99999; ++n) 6150 {
6140 { 6151 char tempname[MAXPATHL + 1];
6141 sprintf(gettail(tempname), "%d", n); 6152
6142 if (mch_stat(tempname, &st_to) < 0) 6153 /*
6154 * Find a name that doesn't exist and is in the same directory.
6155 * Rename "from" to "tempname" and then rename "tempname" to "to".
6156 */
6157 if (STRLEN(from) >= MAXPATHL - 5)
6158 return -1;
6159 STRCPY(tempname, from);
6160 for (n = 123; n < 99999; ++n)
6161 {
6162 sprintf((char *)gettail((char_u *)tempname), "%d", n);
6163 if (mch_stat(tempname, &st) < 0)
6164 {
6165 if (mch_rename((char *)from, tempname) == 0)
6143 { 6166 {
6144 if (mch_rename((char *)from, tempname) == 0) 6167 if (mch_rename(tempname, (char *)to) == 0)
6145 { 6168 return 0;
6146 if (mch_rename(tempname, (char *)to) == 0) 6169 /* Strange, the second step failed. Try moving the
6147 return 0; 6170 * file back and return failure. */
6148 /* Strange, the second step failed. Try moving the 6171 mch_rename(tempname, (char *)from);
6149 * file back and return failure. */
6150 mch_rename(tempname, (char *)from);
6151 return -1;
6152 }
6153 /* If it fails for one temp name it will most likely fail
6154 * for any temp name, give up. */
6155 return -1; 6172 return -1;
6156 } 6173 }
6157 } 6174 /* If it fails for one temp name it will most likely fail
6158 return -1; 6175 * for any temp name, give up. */
6159 } 6176 return -1;
6177 }
6178 }
6179 return -1;
6160 } 6180 }
6161 #endif 6181 #endif
6162 6182
6163 /* 6183 /*
6164 * Delete the "to" file, this is required on some systems to make the 6184 * Delete the "to" file, this is required on some systems to make the