comparison src/undo.c @ 2267:c08f91142c41 vim73

Crypt the swapfile.
author Bram Moolenaar <bram@vim.org>
date Mon, 21 Jun 2010 06:15:46 +0200
parents ae2e615a7320
children 2b33a7678e7b
comparison
equal deleted inserted replaced
2266:ae2e615a7320 2267:c08f91142c41
884 if (header == NULL) 884 if (header == NULL)
885 return FAIL; 885 return FAIL;
886 len = (int)fwrite(header, (size_t)header_len, (size_t)1, fp); 886 len = (int)fwrite(header, (size_t)header_len, (size_t)1, fp);
887 vim_free(header); 887 vim_free(header);
888 if (len != 1) 888 if (len != 1)
889 {
890 crypt_pop_state();
889 return FAIL; 891 return FAIL;
892 }
890 } 893 }
891 else 894 else
892 #endif 895 #endif
893 put_bytes(fp, (long_u)UF_VERSION, 2); 896 put_bytes(fp, (long_u)UF_VERSION, 2);
894 897
1237 int write_ok = FALSE; 1240 int write_ok = FALSE;
1238 #ifdef UNIX 1241 #ifdef UNIX
1239 int st_old_valid = FALSE; 1242 int st_old_valid = FALSE;
1240 struct stat st_old; 1243 struct stat st_old;
1241 struct stat st_new; 1244 struct stat st_new;
1245 #endif
1246 #ifdef FEAT_CRYPT
1247 int do_crypt = FALSE;
1242 #endif 1248 #endif
1243 1249
1244 if (name == NULL) 1250 if (name == NULL)
1245 { 1251 {
1246 file_name = u_get_undo_file_name(buf->b_ffname, FALSE); 1252 file_name = u_get_undo_file_name(buf->b_ffname, FALSE);
1395 /* 1401 /*
1396 * Write the header. 1402 * Write the header.
1397 */ 1403 */
1398 if (serialize_header(fp, buf, hash) == FAIL) 1404 if (serialize_header(fp, buf, hash) == FAIL)
1399 goto write_error; 1405 goto write_error;
1406 #ifdef FEAT_CRYPT
1407 if (*buf->b_p_key)
1408 do_crypt = TRUE;
1409 #endif
1400 1410
1401 /* 1411 /*
1402 * Iteratively serialize UHPs and their UEPs from the top down. 1412 * Iteratively serialize UHPs and their UEPs from the top down.
1403 */ 1413 */
1404 mark = ++lastmark; 1414 mark = ++lastmark;
1460 mch_set_acl(file_name, acl); 1470 mch_set_acl(file_name, acl);
1461 } 1471 }
1462 #endif 1472 #endif
1463 1473
1464 theend: 1474 theend:
1475 #ifdef FEAT_CRYPT
1476 if (do_crypt)
1477 crypt_pop_state();
1478 #endif
1465 if (file_name != name) 1479 if (file_name != name)
1466 vim_free(file_name); 1480 vim_free(file_name);
1467 } 1481 }
1468 1482
1469 /* 1483 /*
1503 #endif 1517 #endif
1504 #ifdef UNIX 1518 #ifdef UNIX
1505 struct stat st_orig; 1519 struct stat st_orig;
1506 struct stat st_undo; 1520 struct stat st_undo;
1507 #endif 1521 #endif
1522 #ifdef FEAT_CRYPT
1523 int do_decrypt = FALSE;
1524 #endif
1508 1525
1509 if (name == NULL) 1526 if (name == NULL)
1510 { 1527 {
1511 file_name = u_get_undo_file_name(curbuf->b_ffname, TRUE); 1528 file_name = u_get_undo_file_name(curbuf->b_ffname, TRUE);
1512 if (file_name == NULL) 1529 if (file_name == NULL)
1570 if (prepare_crypt_read(fp) == FAIL) 1587 if (prepare_crypt_read(fp) == FAIL)
1571 { 1588 {
1572 EMSG2(_("E826: Undo file decryption failed: %s"), file_name); 1589 EMSG2(_("E826: Undo file decryption failed: %s"), file_name);
1573 goto error; 1590 goto error;
1574 } 1591 }
1592 do_decrypt = TRUE;
1575 #else 1593 #else
1576 EMSG2(_("E827: Undo file is encrypted: %s"), file_name); 1594 EMSG2(_("E827: Undo file is encrypted: %s"), file_name);
1577 goto error; 1595 goto error;
1578 #endif 1596 #endif
1579 } 1597 }
1774 u_free_uhp(uhp_table[i]); 1792 u_free_uhp(uhp_table[i]);
1775 vim_free(uhp_table); 1793 vim_free(uhp_table);
1776 } 1794 }
1777 1795
1778 theend: 1796 theend:
1797 #ifdef FEAT_CRYPT
1798 if (do_decrypt)
1799 crypt_pop_state();
1800 #endif
1779 if (fp != NULL) 1801 if (fp != NULL)
1780 fclose(fp); 1802 fclose(fp);
1781 if (file_name != name) 1803 if (file_name != name)
1782 vim_free(file_name); 1804 vim_free(file_name);
1783 return; 1805 return;