1244 return -1; |
1244 return -1; |
1245 } |
1245 } |
1246 if(dav_get_content(res, tmp_stream, (dav_write_func)fwrite)) { |
1246 if(dav_get_content(res, tmp_stream, (dav_write_func)fwrite)) { |
1247 print_resource_error(sn, path); |
1247 print_resource_error(sn, path); |
1248 close(tmp_fd); |
1248 close(tmp_fd); |
1249 unlink(outfile); |
1249 sys_unlink(outfile); |
1250 return -1; |
1250 return -1; |
1251 } |
1251 } |
1252 fclose(tmp_stream); |
1252 fclose(tmp_stream); |
1253 } |
1253 } |
1254 |
1254 |
1255 // remember time s.t. we can later check if the file has changed |
1255 // remember time s.t. we can later check if the file has changed |
1256 SYS_STAT tmp_stat; |
1256 SYS_STAT tmp_stat; |
1257 if(sys_stat(outfile, &tmp_stat)) { |
1257 if(sys_stat(outfile, &tmp_stat)) { |
1258 perror("Cannot stat temporary file"); |
1258 perror("Cannot stat temporary file"); |
1259 close(tmp_fd); |
1259 close(tmp_fd); |
1260 unlink(outfile); |
1260 sys_unlink(outfile); |
1261 return -1; |
1261 return -1; |
1262 } |
1262 } |
1263 time_t dl_mtime = tmp_stat.st_mtime; |
1263 time_t dl_mtime = tmp_stat.st_mtime; |
1264 |
1264 |
1265 // open in editor |
1265 // open in editor |
1288 "Editor closed abnormally - file will not be uploaded.\n"); |
1288 "Editor closed abnormally - file will not be uploaded.\n"); |
1289 ret = 1; |
1289 ret = 1; |
1290 } else { |
1290 } else { |
1291 // check if the file has changed |
1291 // check if the file has changed |
1292 if (sys_stat(outfile, &tmp_stat)) { |
1292 if (sys_stat(outfile, &tmp_stat)) { |
|
1293 // very rare case when someone concurrently changes permissions |
1293 perror("Cannot stat temporary file"); |
1294 perror("Cannot stat temporary file"); |
1294 ret = 1; |
1295 ret = 1; |
1295 } else if (dl_mtime < tmp_stat.st_mtime) { |
1296 } else if (dl_mtime < tmp_stat.st_mtime) { |
1296 // upload changed file |
1297 // upload changed file |
1297 FILE* tmp_stream = sys_fopen(outfile, "rb"); |
1298 FILE* tmp_stream = sys_fopen(outfile, "rb"); |