dav/main.c

branch
feature/dav-edit
changeset 716
5c2e4da00b04
parent 715
f4da6141e233
child 717
764e9fac530d
equal deleted inserted replaced
715:f4da6141e233 716:5c2e4da00b04
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");
1314 } 1315 }
1315 } 1316 }
1316 } 1317 }
1317 1318
1318 close(tmp_fd); 1319 close(tmp_fd);
1319 unlink(outfile); 1320 if(ret) {
1321 // if someone went wrong, we are most likely unable to unlink anyway
1322 fprintf(stderr, "File location: %s\n", outfile);
1323 } else {
1324 sys_unlink(outfile);
1325 }
1320 free(path); 1326 free(path);
1321 1327
1322 return ret; 1328 return ret;
1323 #endif 1329 #endif
1324 } 1330 }

mercurial