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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>Libdar API - Tutorial</title>
<meta content="Denis Corbin" name="author">
<meta content="Tutorial for using libdar library" name="description"></head><body style="background-color: rgb(221, 221, 221); color: rgb(0, 0, 170);" alink="#ff0000" link="#0000ff" vlink="#000055">
<center>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; width: 161px;"><a href="index.html"><img style="border: 0px solid ; width: 160px; height: 120px;" alt="Dar Documentation" src="dar_s_doc.jpg"></a><br>
</td>
<td style="vertical-align: top;">
<h1 style="text-align: center;"> LIBDAR <br>
</h1>
<h1 style="text-align: center;">APPLICATION INTERFACE <br>
</h1>
<h1 style="text-align: center;">TUTORIAL</h1>
<div style="text-align: center;"> for API version 5.x.x<br>
</div>
<h1 style="text-align: center;"> </h1>
</td>
</tr>
</tbody>
</table>
<div style="text-align: center;"><br>
</div>
<hr style="width: 100%; height: 2px;"><br>
<table style="width: 90%; margin-right: auto; margin-left: auto; text-align: left;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<h2>Presentation</h2>
<p style="text-align: justify;">The Libdar library has been built
from source code originally
located directly in the <em><strong>dar</strong></em> command line
application. Libdar provides a complete abstraction layer for handling Disk
ARchive (<em>dar</em>)'s archives. The general operations provided are:</p>
<div style="text-align: justify;"></div>
<div></div>
<ul style="text-align: justify;">
<li>archive creation, </li>
<li>file extraction, </li>
<li>archive listing, </li>
<li>archive testing, </li>
<li>archive comparison,</li>
<li>catalogue isolation</li>
<li>archive merging</li>
<li>dar_manager database manipulations<br>
</li>
</ul>
<div style="text-align: justify;"></div>
Note that <span style="font-style: italic;">Disk ARchive</span> <em>and</em>
libdar
have been released under the <span style="font-style: italic;">Gnu
General Public License </span>(GPL). All code linked to libdar
(statically or dynamically), <span style="font-weight: bold;"> must
also be covered by the GPL.</span><br>
<div style="text-align: justify;"> <br>
</div>
This tutorial will show you how to
use the libdar API. As <span style="font-style: italic;">dar</span> since its release 2.0.0 also uses this API, looking at it's code may also provide a good
illustration. The file <span style="font-style: italic;">src/dar_suite/dar.cpp</span>
is the primary consumer of the libdar API. <br>
<div style="text-align: justify;"> <br>
The sample codes provided here is
solely illustrative and is not guaranteed to compile. More detailed API
documentation is contained in the source code and can be compiled to
the doc/html directory using Doxygen, which is also provided <a href="http://dar.linux.free.fr/doc/html/index.html">online</a>.<br>
</div>
</td>
</tr>
</tbody>
</table>
<br>
<hr style="width: 100%; height: 2px;"><br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<h2>Let's Start</h2>
<h3>Conventions</h3>
<h4>Language</h4>
<div style="text-align: justify;">Dar and libdar are written in
C++, and so is the libdar API. While
written in C++, libdar is easily usable by both C and C++ code.
Access from other languages can be provided by specific bindings. I
would only say that you are welcome to provide the necessary bindings
yourself. :-) </div>
<h4>Libdar namespace</h4>
All libdar symbols are defined under
the <span style="font-style: italic; font-weight: bold;">libdar </span><span style="font-weight: bold;">namespace</span>. You
can either add the <span style="font-style: italic;">using namespace
libdar;</span> line at the beginning of your source files: </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);"><code>using
namespace libdar;<br>
</code><br>
<code>get_version(....);<br>
</code></td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; text-align: justify;"> or,
as shown below, you can
explicitly use the namespace in front of libdar objects : </td>
</tr>
</tbody>
</table>
<br>
<code></code>
<table style="width: 90%; height: 51px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);"><code><br>
libdar::get_version(....);<br>
</code></td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<h4>Exceptions or no Exceptions</h4>
<div style="text-align: justify;">The library can be used with or
without <span style="font-style: italic;">exceptions.</span> For each example we will see a sample code for both ways. To the left is with exceptions, to the right without:<br>
</div>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;"><code><br>
example
code <span style="font-weight: bold;">using exceptions</span><br>
<br>
</code> </td>
<td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code><br>
example
code <span style="font-weight: bold;">not using</span> exceptions</code><br>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; text-align: justify;">All
exceptions used by <span style="font-style: italic;">libdar</span>
inherit from the pure virtual <span style="font-style: italic;"><span style="font-weight: bold;">class Egeneric</span>.</span> The only
method you will need to know about for any exception is the <span style="font-style: italic; font-weight: bold;">get_message()</span>
call, which returns a message string describing the message (in human
language). The type of the error is defined by the class of the
exception. The possible exception types follow: </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; width: 200px;"><code>class
libdar::Egeneric<br>
</code></td>
<td style="vertical-align: top;"> the parent class of all
exceptions (a pure virtual class)<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><code>class libdar::Ememory<br>
</code></td>
<td style="vertical-align: top;">memory has been exhausted<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><code>class libdar::Ebug<br>
</code></td>
<td style="vertical-align: top;">signals a bug, which is
triggered when reaching some code that should never be executed<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><code>class libdar::Einfinint<br>
</code></td>
<td style="vertical-align: top;">arithmetic error detected when
operating on infinint<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><code>class libdar::Elimitint<br>
</code></td>
<td style="vertical-align: top;">a limitint overflow is detected,
indicating the maximum value of the limitint has been exceeded<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><code>class libdar::Erange<br>
</code></td>
<td style="vertical-align: top;">signals a range error<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><code>class libdar::Edeci<br>
</code></td>
<td style="vertical-align: top;">signals conversion problem
between infinint and string (decimal representation)<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><code>class libdar::Efeature<br>
</code></td>
<td style="vertical-align: top;">a requested feature is not (yet)
implemented<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><code>class libdar::Ehardware<br>
</code></td>
<td style="vertical-align: top;">hardware problem is found <br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><code>class libdar::Euser_abort<br>
</code></td>
<td style="vertical-align: top;">signals that the user has
aborted the operation <br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><code>class
libdar::Ethread_cancel</code></td>
<td style="vertical-align: top;">A program has requested the
termination of the current thread while libdar was running<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><code>class libdar::Edata<br>
</code></td>
<td style="vertical-align: top;">an error concerning the treated
data has been encountered<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><code>class libdar::Escript<br>
</code></td>
<td style="vertical-align: top;">the script executed between
slices returned an error code<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><code>class libdar::Elibcall<br>
</code></td>
<td style="vertical-align: top;">signals an error in the
arguments given to a libdar call of the API<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><code>class libdar::Ecompilation<br>
</code></td>
<td style="vertical-align: top;">a requested feature has not been
activated at compilation time<br>
</td>
</tr>
</tbody>
</table>
<br>
<br>
<hr style="width: 100%; height: 2px;"><br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<h2> 1 - First we *must* initialize libdar by checking the libdar version</h2>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;"><code>
<br>
// we'll want to display some messages<br>
#include <io.h><br>
<br>
// we include this header to access lidbar API<br>
#include <dar/libdar.h><br>
<br>
// all sample code shown will be inside this<br>
// function for simplicity's sake<br>
void my_sample_function()<br>
{<br>
try<br>
{<br>
libdar::U_I maj, med, min;<br>
<br>
// first we <span style="font-weight: bold;">MUST </span>call
get_version()<br>
<br>
libdar::<span style="font-weight: bold;">get_version</span>(maj,
med, min); <br>
<br>
if(maj !=
libdar::LIBDAR_COMPILE_TIME_MAJOR ||<br>
med <
libdar::LIBDAR_COMPILE_TIME_MEDIUM)<br>
throw libdar::Erange("initialization", <br>
"we are linking against a
wrong libdar"); <br>
}</code><br>
<code> catch(libdar::Egeneric & e)<br>
{<br>
std::cout << e.get_message()
<<
std::endl;<br>
}<br>
}<br>
<br>
<br>
</code> </td>
<td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code></code><code>
<br>
// we'll want to display some messages<br>
#include <io.h><br>
<br>
// we include this header to access lidbar API<br>
#include <dar/libdar.h><br>
<br>
// all sample code shown will be inside this<br>
// function for simplicity's sake<br>
void my_sample_function()<br>
{<br>
<br>
</code><code> libdar::U_I maj, med, min;<br>
libdar::U_16 excode;<br>
std::string msg;<br>
</code><code><br>
// first we <span style="font-weight: bold;">MUST </span>call
get_version()<br>
<br>
libdar::<span style="font-weight: bold;">get_version_noexcept</span>(maj,
med, min, <br>
excode, msg);<br>
<br>
if(excode != LIBDAR_NOEXCEPT)<br>
{ <br>
std::cout << msg << endl;<br>
return;<br>
}<br>
<br>
if(maj != LIBDAR_COMPILE_TIME_MAJOR ||<br>
</code><code>med <
libdar::LIBDAR_COMPILE_TIME_MEDIUM</code><code>)<br>
{<br>
std::cout << </code><code>"we are
linking against wrong libdar"</code><code> << std::endl;<br>
return;<br>
}<br>
</code> </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">The get_version() function must
be called for
several reasons :<br>
<ul>
<li>
<div style="text-align: justify;">you must check that the
library
you've dynamically linked with is compatible with the features you will
be using. The major number must be the same, for no compatibility is
assured between two libdar versions of different major numbers. While
run-time compatibility is assured between medium numbers, the medium
number must be greater or equal to the one used at compilation time to
be sure that all the features you want are available in the libdar
library you dynamically linked with. Changes between minor versions
correspond to bug fixes and is not to imply any API change, thus no
constraints are present there (except the presence of more bugs in lower numbers).<br>
</div>
</li>
<li style="text-align: justify;">the
get_version() call, as
well as
returning version information, does important initialization tasks for
libdar. If not called first, the libdar library will not initialized
properly and its behavior will be unpredictable. Note that you may call
get_version() several time if you wish, the secon time only the version
information are returned, the libdar library is not reset or the like.<br>
</li>
<li style="text-align: justify;">Last, if strong encryption support is activated at compilation time, libdar will by default
performs libgcrypt initialization when get_version() is called if libgcrypt is
not already initialized. You can avoid having dar initializing libgcrypt by calling get_version()
with an additional argument set to "false" :</li></ul>
<div style="text-align: left; margin-left: 120px;"><span style="font-family: Courier;">ger_version(maj, med, min, </span><span style="font-weight: bold; font-family: Courier;">false</span><span style="font-family: Courier;">)</span><br>
</div>
<ul style="text-align: justify;">
<li>Note
that in multi-thread environment with strong encryption activated in
libdar at compilation time, libgcrypt requires to be initialized from
the application, thus you *must* avoid having libdar initializing
libgcrypt by using the get_version() described just above and proceed
from the application to the initialization of libgcrypt before calling
get_version(). For more details see libgcrypt documentation.</li></ul>
<ul>
</ul>
<br>
<h2>1 bis - We must prepare the end right now!<br>
</h2>
<br>
<div style="text-align: justify;">As we saw, libdar used
some
datastructures (mutex, secured memory, etc.) that need to be released
properly before ending the program. It is mandatory to invoke the
following function before exiting your program if you invoked
get_version() previously. It is a good idea to implement this right now
not to forget later:<br>
</div>
</td>
</tr>
</tbody>
</table>
<br>
<table style="text-align: left; width: 90%; background-color: rgb(153, 255, 255);" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;"><code><span style="font-weight: bold;"><br>
</span></code>
<div style="margin-left: 40px;"><code style="font-weight: bold;">libdar::close_and_clean()</code><span style="font-weight: bold;"></span><br>
<span style="font-weight: bold;"></span></div>
<code style="font-weight: bold;"><br>
</code></td>
</tr>
</tbody>
</table>
<br>
<table style="text-align: left; width: 90%;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<div style="text-align: justify;">In particular, closes_and_clean()
makes the necessary for memory to be released in the proper order. <span style="text-decoration: underline;">Not
calling close_and_clean() at the end of your program may result in uncaught exception message from libdar at the end of
the execution</span>. This depends on the compiler, libc and option activated in libdar at compilation time.<br>
<br>
<br>
</div>
<h2>2 - Let's see the available features</h2>
once we have called one of the <span style="font-style: italic;">get_version*</span>
function it is possible to access the list of features activated at compilation
time:</td>
</tr>
</tbody>
</table>
<br>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;"><code><br>
<br>
void my_sample_function()<br>
{<br>
// let's continue in the
same function<br>
<br>
</code>
<div style="margin-left: 40px;"><code>bool ea = libdar::compile_time::ea();<br>
bool largefile = libdar::compile_time::largefile();<br>
bool nodump = libdar::compile_time::nodump();<br>
bool special_alloc = libdar::compile_time::special_alloc();<br>
U_I bits = libdar::compile_time::bits();<br>
// bits is equal to zero for infinint,<br>
// else it is equal to 32 or 64 depending on<br>
// the compilation mode used.<br>
<br>
bool thread = libdar::compile_time::thread_safe();<br>
bool libz = libdar::compile_time::libz();<br>
bool libbz2 = libdar::compile_time::libbz2();<br>
bool liblzo = libdar::compile_time::liblzo();<br>
bool libcrypto = libdar::compile_time::libgcrypt();<br>
bool furtive_read = libdar::compile_time::furtive_read</code>();<br>
</div>
<code>
</code><br>
}<br>
<br>
</td>
<td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code></code>
<code><br>
<br>
// here there is no difference because no exceptions<br>
// are thrown by the get_compile_time_feature() <br>
// function<br>
</code> </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<div style="text-align: justify;">You can do what you want with
the
resulting values. It's possible to display the available libdar
features or to terminate if you don't find a desired feature. However,
verifying that features are available is not strictly necessary because
libdar will tell you if an operation you call requires a feature that
has not been activated at compilation time, by throwing an Ecompile
exception (or returning
the <span style="font-style: italic;">LIBDAR_ECOMPILATION</span> error
code if you are not using exceptions).<br>
</div>
<br>
<br>
<h2>3 -User interaction</h2>
<div style="text-align: justify;">
<h3>The generic <span style="font-style: italic;">user_interaction</span>
class</h3>
To be able to report messages to the user and prompt for feedback a
special class called<span style="font-style: italic;"> <span style="font-weight: bold;">user_interaction </span></span>has been
introduced. Simply put, <span style="font-style: italic;">user_interaction</span>
is a virtual class which you can derive to provide user interaction (a
GUI's graphical interaction, for example). There are four methods whose
prototypes you must override:<br>
</div>
<br style="font-style: italic; font-weight: bold;">
<span style="font-style: italic; font-weight: bold;">void </span><span style="font-style: italic; font-weight: bold;" class="el">pause</span><span style="font-style: italic; font-weight: bold;"> (const std::string
&message);</span><br>
<div style="margin-left: 40px; text-align: justify;">this method
is
called by libdar when the library needs a yes or no ("continue" or
"kill")
answer to a question, which is provided by the string <em>message</em>.
The question posed by <em>pause()</em> must be answered by returning
normally (= "true") or throwing a <em><strong>Euser_abort</strong></em>
exception if the user refused the proposition<span style="font-weight: bold;"><span style="font-weight: bold;">. </span></span>Don't
worry about throwing an exception in your code; it will be trapped by
libdar if you don't want to manage exceptions, and are using libdar in
the "no exception" method. But if you really don't want to throw
exception from your code see next:<br>
<span style="font-weight: bold;"><span style="font-weight: bold;"><br>
<br>
</span></span></div>
<span style="font-weight: bold;"><span style="font-style: italic; font-weight: bold;">bool </span><span style="font-style: italic; font-weight: bold;" class="el">pause</span><span style="font-style: italic; font-weight: bold;">2(const std::string
&message);</span></span><span style="font-weight: bold;"><br>
</span>
<div style="margin-left: 40px;">This is an alternative method to<span style="font-style: italic;"> pause()</span> as seen above. In place of
defining a <span style="font-style: italic;">pause()</span> method in
your inherited class, you can redefine the <span style="font-style: italic;">pause2()</span> method. The only
difference with <span style="font-style: italic;">pause()</span> is
that the user answer to the question is returned by a boolean value,
your code does no more have to throw a <span style="font-style: italic;">Euser_abort</span> exception to say "no".
Note that <span style="font-weight: bold;">you must not redefine both
pause() and pause2(). </span><span style="text-decoration: underline;"><br>
</span></div>
<span style="font-weight: bold;"><br>
</span><span style="font-style: italic; font-weight: bold;">void </span><span style="font-style: italic; font-weight: bold;" class="el">inherited_warning</span><span style="font-style: italic; font-weight: bold;"> (const std::string
&message);</span><br>
<div style="margin-left: 40px; text-align: justify;">libdar calls
this <span style="font-weight: bold;">protected</span> method (through
the
public method named <span style="font-style: italic;">warning()</span>)
to display an informational message to the user. It is not
always a warning as the name suggests, but sometimes just normal
information. In API 3.0.x this method did not exist, but the
public warning() method itself was pure virtual and thus needed to be
overwritten. Today, the <span style="font-style: italic;">warning()</span>
method is no more pure virtual nor it is even virtual, so the user
defined implementation of message display has to be done in the <span style="font-style: italic;">inherited_warning()</span> method.<br>
</div>
<br>
<span style="font-style: italic; font-weight: bold;">std::string </span><span style="font-style: italic; font-weight: bold;" class="el">get_string</span><span style="font-style: italic; font-weight: bold;"> (const std::string
&message, bool echo);</span><br>
<div style="margin-left: 40px; text-align: justify;">This call is
used
to get an arbitrary answer from the user. This is mainly used to get a
password from the user (when no password has been supplied for an
encrypted archive), the <span style="font-style: italic;">echo </span>argument
indicates if the user response should be displayed back on the screen
(again, very useful for handling password input). If <span style="font-style: italic;">echo</span> is set to "false" the
implementation of <span style="font-style: italic;">get_string() </span>should
hide the characters typed by the user.<br>
</div>
<br style="font-style: italic; font-weight: bold;">
<span style="font-style: italic; font-weight: bold;"> </span><span style="font-style: italic; font-weight: bold;" class="el">user_interaction</span><span style="font-style: italic; font-weight: bold;"> * </span><span style="font-style: italic; font-weight: bold;" class="el">clone</span><span style="font-style: italic; font-weight: bold;">
() const;</span><br>
<div style="margin-left: 40px;">
A deep copy
operation must be implemented here. This is because libdar stores the
reference to the <span style="font-style: italic;">user_interaction</span>
class as a pointer but may want to keep a complete internal copy at
some point. A simple implementation of this method should be something
like this (even if you don't want to use exceptions): </div>
</td>
</tr>
</tbody>
</table>
<br>
<code></code><code></code>
<table style="width: 90%; height: 51px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);"><code><br>
</code><code>user_interaction
*my_own_class::clone() const<br>
{<br>
my_own_class *ret = new my_own_class(*this);<br>
if(ret == NULL)<br>
throw
Ememory("user_interaction_callback::clone");<br>
else<br>
return ret;<br>
}<br>
</code><br>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<h3>The callback interaction class</h3>
<div style="text-align: justify;">An inherited class from<span style="font-style: italic;"> user_interaction</span> called <span style="font-weight: bold; font-style: italic;">user_interaction_callback</span>
provides an implementation of the user interaction based on callback
functions. This allows you to replace the three interactions methods
(pause, warning and get_string) by three normal functions of your
choice, which must be given to the <span style="font-style: italic;">user_interaction_callback</span>'s
constructor. The <span style="font-style: italic;">clone()</span>
method is implemented internally, leaving only the three callback
functions to be implemented. Look at <span style="font-style: italic;">
dar</span>'s command line code for a practical example. <span style="font-style: italic;">dar</span>'s user interaction code is
implemented using an instance of <span style="font-style: italic;">user_interaction_callback</span>
and three static functions in the module<span style="font-style: italic;"> dar_suite/shell_interaction.cpp</span> <br>
</div>
<br>
Pay attention to the <span style="font-style: italic;">contextual</span>
value present in the arguments of these callback functions : </td>
</tr>
</tbody>
</table>
<br>
<div style="text-align: justify;"><code></code><code></code>
<table style="width: 90%; height: 51px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);"><code>
</code><code><br>
// our own callback functions. <br>
// for the illustration of what these 'context' arguments<br>
// can be used for we will imagine the situation where<br>
// multiple windows or multiple threads may each one use <br>
// libdar, but all share the same callback functions.<br>
<br>
typedef class t_window_type t_win;<br>
<br>
// this is an arbitrary type that here we will say<br>
// points to a graphical window object wrapped in a C++<br>
// class. <br>
// Note that the method show() wait_for_click() and so on<br>
// attributed to the t_win class are absolutely<br>
// imaginary. Any link to an existing class is a pure <br>
// coincidence...<br>
<br>
void warning_callback(const std::string &x, void *context)<br>
{<br>
(t_win *)(context)->show(x);<br>
}<br>
<br>
bool answer_callback(const std::string &x, void *context)<br>
{<br>
click_type ret;<br>
<br>
</code><code>(t_win *)(context)->show(x);<br>
ret = (t_win *)(context)->wait_for_click();<br>
<br>
return ret == click_OK;<br>
</code><code>}<br>
<br>
std::string string_callback(const std::string &x, bool echo, void
*context)<br>
{<br>
(t_win *)(context)->show(x);<br>
if(!echo)<br>
(t_win *)(context)->set_hide_typed_char();<br>
(t_win *)(context)->wait_for_click();<br>
return (t_win *)(context)->read_text();<br>
}<br>
<br>
---------8<-------8<-------8<-------<br>
<br>
// So now each window can have its user_interaction object based
on the same<br>
// user_interaction_callback object pointing to the same
functions.<br>
// user_interaction_callback objects can be shared among
different window objects<br>
<br>
libdar::user_interaction_callback dialog = <br>
libdar::user_interaction_callback(&warning_callback,
&answer_callback, &string_callback,<br>
(void *)get_current_windows_id());<br>
<br>
// just the "context" argument changes, and will be passed as is
from the constructor to the callback<br>
// functions<br>
</code><br>
</td>
</tr>
</tbody>
</table>
<br>
</div>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<h2>4 - Masks</h2>
<div style="text-align: justify;">Mask are used to define which
files
will be considered and which will not. Libdar implements masks as
several classes that all inherit from a virtual class that defines the
way masks are used. This root class is the <span style="font-weight: bold; font-style: italic;">class mask</span> and
provides the <span style="font-style: italic;">is_covered()</span>
method which libdar uses to determine which files are considered. There
are many different basic masks classes you can use to build fairly
complex masks: </div>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; width: 200px;">class libdar::mask<br>
</td>
<td style="vertical-align: top;">the generic class, parent of all
masks (a pure virtual class)<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;">class libdar::bool_mask<br>
</td>
<td style="vertical-align: top;">boolean mask, either always true
or false, it matches either all files or no files at all<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;">class libdar::simple_mask<br>
</td>
<td style="vertical-align: top;">matches as done by the shell on
the command
lines (see "man 7 glob")<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;">class libdar::regular_mask<br>
</td>
<td style="vertical-align: top;">matches regular expressions (see
"man 7 regex")<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;">class libdar::not_mask<br>
</td>
<td style="vertical-align: top;">negation of another mask<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;">class libdar::et_mask<br>
</td>
<td style="vertical-align: top;">makes an *AND* operator between
two or more masks<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;">class libdar::ou_mask<br>
</td>
<td style="vertical-align: top;">makes the *OR* operator
between two or more masks <br>
</td>
</tr>
<tr>
<td style="vertical-align: top;">class lbdar::simple_path_mask<br>
</td>
<td style="vertical-align: top;">
<p>string matches if it is subdirectory of mask or is a directory
that contains the specified path itself<br>
</p>
</td>
</tr>
<tr>
<td style="vertical-align: top;">class libdar::same_path_mask<br>
</td>
<td style="vertical-align: top;">matches if the string is exactly
the
given mask (no wild card expression)<br>
</td>
</tr>
<tr>
<td style="vertical-align: top; width: 210px;">class
libdar::exclude_dir_mask<br>
</td>
<td style="vertical-align: top;">matches if string is the given
string or a sub directory of it<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;">class libdar::mask_list<br>
</td>
<td style="vertical-align: top;">matches a list of files defined
in a given file<br>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">Let's play with some masks : </td>
</tr>
</tbody>
</table>
<br>
<code></code><code></code>
<table style="width: 90%; height: 51px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);"><code><br>
</code><code> // all files will be
elected by this mask</code><br>
<code> libdar::bool_mask m1 = true; <br>
<br>
// all file that match the glob
expession "A*~" will match. <br>
// the second argument of the
constructor tell if the match is case sensitive so here <br>
// any file beginning by 'A' or by 'a'
and ending by '~' will be selected by this mask<br>
libdar::simple_mask m2 = libdar::simple_mask(std::string("A*~"),
false);<br>
<br>
// m3 is the negation if m2. This mask
will thus match<br>
// any file that does not begin by 'A'
or 'a' and also finish by '~'<br>
libdar::not_mask m3 = m2;<br>
<br>
// this mask matches any file that is a
subdirectory of "/home/joe"<br>
// and any directory that contains
/home/joe, meaning<br>
// "/", "/home", "/jome/joe" and any
subdirectory are matched.<br>
// here, the second argument is also
case sensitivity (so<br>
// "/HoMe" will not be selected by
this mask.<br>
libdar::simple_path_mask m4 = simple_path_mask("/home/joe",
true);<br>
<br>
// now let's do some more complex things:<br>
</code><code> // m5 will now match
only files that are selected by both m2 AND m4</code><br>
<code> libdar::et_mask m5;<br>
m5.add_mask(m2);<br>
m5.add_mask(m4);<br>
<br>
// we can make more silly things like
this, where m5 will select files<br>
// that match m2 AND m4 AND m3. But <span style="font-style: italic;">m3 =
not m2</span> so now m5 will never<br>
// match any file...<br>
m5.add_mask(m3);<br>
<br>
// but we could do the same with an
"ou_mask" and would get a silly<br>
// counterpart of m1 (a mask that
matches any files)<br>
libdar::ou_mask m6;<br>
m6.add_mask(m2);<br>
m6.add_mask(m4);<br>
m6.add_mask(m3);<br>
<br>
// lastly, the NOT, AND and OR operation
can be used recursively.<br>
</code><code> // Frankly, it's
possible to have masks reference each other!</code><br>
<code> libdar::not_mask m7 = m6;<br>
m6.add_mask(m7);<br>
<br>
</code></td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">Now that you've seen the power
of these masks, you should know that in
libdar there are three masks that are required: <br>
<ul style="text-align: justify;">
<li>The first mask is used against
the
names of all files except directories. It is applied solely to the
names themselves (not the file path). This mask may be any combination
of the masks seen previously; it will only be applied to socket, named
pipes, symbolic links, char or block devices, plain files, but again
not to directories. This way you can filter by file type for save,
restore, list, compare, compress, and other library operations.</li>
<li>The second mask is applied to
any
file including directories, including the path part of the filename. So
with it you can prune directories, or in any other way restrict the
operation to a particular subdirectory, as well as to a particular
plain file for example. <span style="font-weight: bold;">Important note</span>
about this second mask: what your own mask will be compared to by
libdar is the filesystem root (as defined under the argument "fs_root"
of the same call you will give your own mask to) plus the current file
being proceeded:</li>
</ul>
<div style="text-align: justify;"> </div>
<div style="margin-left: 80px; text-align: justify;">Assuming you
choose for example <span style="font-style: italic;">tmp/A</span> as
argument to <span style="font-style: italic;">fs_root</span> (which
argument is present
when creating an archive, for example), your mask will be used against
strings like "<span style="font-style: italic;">tmp/A/some/file</span>"
. This is true up to libdar version 3.0.x (alias release 2.2.x).
Instead, since libdar 4.0.0 the <span style="font-style: italic;">fs_root</span>
argument is expended to an absolute path, so if in the previous
example, your current directory was <span style="font-style: italic;">/var</span>
your masks will be used against strings like "<span style="font-style: italic;">/var/tmp/A/some/file</span>". Of course
there is no difference between these two libdar revisions when the <span style="font-style: italic;">fs_root</span> argument is an absolute
path <span style="font-style: italic;">[this change was necessary to support masks based on a list of files]</span><br>
<br>
An exception is the test operation, which has no <span style="font-style: italic;">fs_root</span> argument (because the
operation is not relative to an existing filesystem), however the <span style="font-style: italic;">subtree</span> argument exist to receive a
mask for comparing the path of file to include or exclude from the test
operation. In this case the situation is as if the <span style="font-style: italic;">fs_root</span> was set to the value "<span style="font-style: italic;"><ROOT></span>". For example, masks
will be compared to <span style="font-style: italic;"><ROOT>/some/file</span>
when performing an archive test operation.<br>
</div>
<div style="margin-left: 80px; text-align: justify;">
</div>
<ul>
<li>The third mask --- which is not always needed --- concerns
Extended Attributes (EA). It is applied to the full EA name in the form
<domain>.<name> where <domain> is any string value
like but not limited to the usual "user" or "system" domains.<br>
</li>
</ul>
<h2><br>
</h2>
<h2>5 - Let's create a simple archive</h2>
Now that we have seen masks and exceptions let's start the real thing:<br>
<br>
All the operations on archives are handled by the archive class which
is defined in libdar/archive.hpp. Each operation requires some
mandatory parameters and some optional parameters. Optional parameters
are gathered in a archive_option auxilliary class, which default
constructor set them to default values. We will see a bit further how
to set these options, but for now let's keep the things simple:<br>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;">
<p><code> // creating an archive is simple; it is just<br>
// a matter of calling the "create" constructor<br>
// of the archive class. It may be used for full or<br>
// differential archives. We'll see an example of<br>
// of differential archives later.<br>
<br>
// note that while this example uses a pointer to store<br>
// my_arch, it is perhaps better practice to use a plain<br>
// stack object. In your code, use an object instead of<br>
// a pointer to an object under normal circumstances.<br>
<br>
libdar::user_interaction_callback dialog =
libdar::user_interaction_callback(ptr1, ptr2, ptr3);<br>
// where ptr1, ptr2 and ptr3 are three callback<br>
// functions.<br>
libdar::statistics ret;<br>
// we will see this structure a bit further<br>
<br>
libdar::archive *my_arch = <br>
new <span style="font-weight: bold;">libdar::archive</span>(dialog,
<br>
"/home", // saving all under this "root"<br>
"/tmp", // where the slices will go<br>
"my_archive", // the basename of the slices<br>
"dar", // the extension used for slices<br>
archive_options_create(), // default options<br>
&ret); // this value is
returned by libdar<br>
//
if you don't want to have statistics of the<br>
//
operation you can set this parameter to NULL<br>
</code> </p>
</td>
<td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code></code><code>
// creating an archive is simple; it is just<br>
// a matter of calling the "create" constructor<br>
// of the archive class. It may be used for full or<br>
// differential archives. We'll see an example of<br>
// of differential archives later.<br>
<br>
// note that while this example uses a pointer to store<br>
// my_arch, it is perhaps better practice to use a plain<br>
// stack object. In your code, use an object instead of<br>
// a pointer to an object under normal circumstances.<br>
</code><code><br>
libdar::user_interaction_callback dialog =
libdar::user_interaction_callback(ptr1, ptr2, ptr3);<br>
// where ptr1, ptr2 and ptr3 are three callback<br>
// functions.<br>
libdar::statistics ret;<br>
</code><code>// we will see this structure a bit further<br>
<br>
</code><code>U_16 exception, <br>
std::string except_msg;</code><br>
<br>
<code><span class="el">libdar::archive *my_arch
= <br>
<span style="font-weight: bold;">libdar::create_archive_noexcept</span>(dialog,</span></code><span class="el"><code> <br>
"/home", // saving all under this "root"<br>
"/tmp", // where the slices will go<br>
"my_archive", <br>
//
the basename of the slices <br>
"dar", // dar's slice extensions<br>
archive_options_create(), // default options</code></span><span class="el"><code></code><br>
</span><span class="el"><code>
&ret, // this value is returned by
libdar<br>
</code></span><span class="el"><code>
// if you don't want to have statistics of the<br>
//
operation you can set this parameter to NULL</code><br>
</span><span class="el"><code> exception,
// this gives the status of the call<br>
except_msg); // and in case of error the cause.<br>
<br>
if(exception != LIBDAR_NOEXCEPT)<br>
std::cout << "an error occurred: " << except_msg <br>
<< std::endl;<br>
<br>
</code></span> </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<div style="text-align: justify;">When creating an archive, the
created
archive object can be used only as reference for an isolation or for
a differential backups. You cannot use it for restoration, listing, or
comparison, because the underlying file descriptors are opened in
write only mode. An implementation which uses file descriptors in
read-write access is not possible and is not a good idea anyway. Why?
Because, for example, if you want to test the newly created archive,
using the newly created object would make the test rely on information
stored in virtual memory (the archive contents, the data location of a
file, etc.), not on the file archive itself. If some corruption
occurred
in the file you would not notice it.<br>
</div>
<br>
<div style="text-align: justify;">So to totally complete the
archive creation we must destroy the archive
object we have just created, which will also close any file descriptors
used by the object : </div>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;"><code><br>
delete my_arch;<br>
<br>
</code> </td>
<td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code><br>
libdar::close_archive_noexcept(my_arch, exception,<br>
except_msg);<br>
<br>
</code><span class="el"><code>if(exception != LIBDAR_NOEXCEPT)<br>
std::cout << "an error occurred: " << except_msg <br>
<<
std::endl;<br>
<br>
</code></span> </td>
</tr>
</tbody>
</table>
<br>
<table style="text-align: left; width: 90%;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<h3>Optional Arguments:</h3>
<br>
<div style="text-align: justify;">Back on the optional arguments.
The archive constructor used above to
create an archive uses an argument of type "archive_option_create". In
the above example, we called the constructor of this class directly
withing the argument list of the constructor. Thsi has for effect to
built
a anonymous temporary object of this class. Such a "just borned" object
has
all the necessary options set to the default values inside it (like
default masks for example) to
correspond to the default options. If you want to use non default
options like compression, slicing, encryption , file filtering and so
on, you must
change the options to your need thanks to the appropriate method
provided by the archive_options_create class. Assuming we want to make
a
compressed an sliced archive we would use the following code:<br>
</div>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;">
<p><code> <br>
// we define an options object to be able to use <br>
// non default options:<br>
libdar::archive_options_create options;<br>
</code></p>
<p><code> // so now we can modify only the option we wish to<br>
options.set_slicing(1024); // 1024 bytes, well that's small<br>
options.set_compression(bzip2); // default is no compression<br>
options.set_compression_level(6); // default is 9<br>
</code></p>
<p><code>
libdar::statistics ret;<br>
// we will see this structure a bit further<br>
<br>
libdar::archive *my_arch = <br>
new <span style="font-weight: bold;">libdar::archive</span>(dialog,
<br>
"/home", // saving all under this "root"<br>
"/tmp", // where the slices will go<br>
"my_archive", // the basename of the slices<br>
"dar", // the extension used for slices<br>
options, // the object we modified above<br>
&ret); // this value is
returned by libdar<br>
//
if you don't want to have statistics of the<br>
//
operation you can set this parameter to NULL<br>
</code> </p>
</td><td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code></code><code></code>
<p><code> // we define an options object to be able to use <br>
// non default options:<br>
libdar::archive_options_create options;<br>
</code></p>
<p><code> // so now we can modify only the option we wish to<br>
options.set_slicing(1024); </code><code>// 1024 bytes, well that's small</code><br>
<code>
options.set_compression(bzip2); // default is no compression<br>
options.set_compression_level(6); // default is 9<br>
</code></p>
<code>libdar::statistics ret;<br>
</code><code>// we will see this structure a bit further<br>
<br>
</code><code>U_16 exception, <br>
std::string except_msg;</code><br>
<br>
<code><span class="el">libdar::archive *my_arch
= <br>
<span style="font-weight: bold;">libdar::create_archive_noexcept</span>(dialog,</span></code><span class="el"><code> <br>
"/home", // saving all under this "root"<br>
"/tmp", // where the slices will go<br>
"my_archive", //
the basename of the slices <br>
"dar", // dar's slice extensions<br>
options, // the object we modified above</code></span><span class="el"><code></code><br>
</span><span class="el"><code>
&ret, // this value is returned by
libdar<br>
</code></span><span class="el"><code>
// if you don't want to have statistics of the<br>
//
operation you can set this parameter to NULL</code><br>
</span><span class="el"><code> exception,
// this gives the status of the call<br>
except_msg); // and in case of error the cause.<br>
<br>
if(exception != LIBDAR_NOEXCEPT)<br>
std::cout << "an error occurred: " << except_msg <br>
<< std::endl;<br>
<br>
</code></span> </td></tr></tbody>
</table>
<br>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<span style="font-weight: bold;"></span>
<p style="text-align: justify;">In
the same way, each other
operation (diff, testing, extraction, merging, ...) has a specific
class that gathers the options parameters. These classes are defined
in the file libdar/archive_options.hpp you are welcome to refer to for
a complete up to date list of available options. The advantage of this
class is to not break ascendant compatibility of the API when new
features get added, while it also improve readability of your code.
This way, the major current number '5' of the API should stay for a
longer time than previous numbers, as for thoses each new feature
implementation broke the ascendant compatibility by adding an new
argument to an API call.<br>
</p>
<span style="font-weight: bold;"></span>
<h2>6 - Testing the archive we have created</h2>
<br>
So, as explained previously, we must create a new archive object but
this time with the "read" constructor: </td>
</tr>
</tbody>
</table>
<code><br>
</code>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;"><code><br>
my_arch = new </code><code>libdar::archive(dialog,
<br>
"/tmp", // where is the
archive <br>
"my_archive", // slice name<br>
"dar", // dar's
archive extensions<br>
archive_options_read()); // default options<br>
</code> </td>
<td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code><br>
my_arch = </code><code>libdar::open_archive_noexcept(</code><code>dialog,
<br>
"/tmp", // where is the
archive <br>
"my_archive", // slice name<br>
"dar", // dar's
archive extensions<br>
archive_options_read(), // default options<br>
</code><span class="el"><code>
exception,// this gives the status of the call<br>
except_msg); // and in case of
error the <br>
// cause of the error<br>
<br>
i</code></span><span class="el"><span class="el"><code>f(exception !=
LIBDAR_NOEXCEPT)<br>
std::cout << "an error occurred: " << except_msg <br>
<<
std::endl;</code></span><br>
</span><span class="el"><code><br>
</code></span> </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;"><br>
Now that we have opened the archive we can perform any operation on it.
Let's thus start by testing the archive coherence: </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;"><code><br>
// for the exercice, we will change the default options:<br>
archive_options_test options;<br>
<br>
options.clear(); // this set back all options to default<br>
// here this is not required as the object has just bee<br>
// created, however it is used here for illustration that<br>
// you can recycle an archive_option_* object.<br>
options.set_info_details(true); // to have a verbose output<br>
<br>
ret = my_arch-><span class="el">op_test</span>(<span class="el"></span>dialog,<br>
options; // the non default options set above</code><code><br>
NULL); // we don't want a progressive report</code><code></code><br>
<br>
</td>
<td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code><br>
// for the exercice, we will change the default options:<br>
archive_options_test options;<br>
<br>
options.clear(); // this set back all options to default<br>
// here this is not required as the object has just bee<br>
// created, however it is used here for illustration that<br>
// you can recycle an archive_option_* object.<br>
options.set_info_details(true); // to have a verbose output</code><br>
<code><br>
<span class="el">ret = libdar::op_test_noexcept(</span></code><span class="el"><code><span class="el"></span>dialog,<br>
my_arch, // the archive
to test<br>
</code></span><span class="el"><code>options, // the non default options set above<br>
NULL, // we don't want a
progressive report<br>
</code> </span> <span class="el"><code>
exception,// this gives the status of the call<br>
except_msg); // and in case of
error the <br>
// cause of the error<br>
<br>
</code></span><span class="el"><span class="el"><code>i</code></span><span class="el"><span class="el"><code>f(exception != LIBDAR_NOEXCEPT)<br>
std::cout << "an error occurred: " << except_msg <br>
<<
std::endl;<br>
<br>
</code></span></span></span> </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<div style="text-align: justify;">We have tested the archive, but
have
not yet seen the libdar::statistics variable. It can be used when
creating an archive as well as when testing it. This object
reports the number of files treated, as well as the number files with
errors and the type of error. You can have a look at the API reference
guide concerning the archive class methods, for more information about
the uses of these different fields. Here is
an example, which relies on the <span style="font-style: italic;"><span style="font-weight: bold;">class deci</span> </span>to display the
value of an infinint variable:<br>
</div>
</td>
</tr>
</tbody>
</table>
<br>
<code></code><code></code>
<table style="width: 90%; height: 51px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);">
<code> <br>
// we need the <span style="font-style: italic;">class deci</span> to display the value of
an infinint:<br>
</code><code></code><code>#include "deci.hpp"<br>
<br>
std::cout << std::string("Number of file treated :")
<< libdar::deci(ret.treated).human() << std::endl;<br>
<br>
// or much simpler (but totally equivalent):<br>
std::cout << std::string("Number of file treated :")
libdar::<< ret.treated << std::endl;<br>
</code><br>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<div style="text-align: justify;">Note that the use of the <span style="font-style: italic;">class
deci
</span>may throw exceptions (in case of lack of memory, for example), and
there is actually no wrapper available to trap the exceptions that may
be thrown by the class<span style="font-style: italic;"> deci</span>.
So you have to protect the code using a<span style="font-style: italic;">
<span style="font-weight: bold;">try {} catch {}</span></span>
statement.<br>
<br>
You may have noticed that we used NULL as argument for
"progressive_report". This argument must either receive NULL as
argument or the address of a real allocated statistics object. This
object will be updated by the libdar call and if multi-threaded support is
enabled it will let a concurrent thread able to reading its value to display the
current number of file treated, for example. Note that there is a little
overhead passing a variable to progressive_report, due to the mutex
that need be used to avoid one reading data while it is updated by
another thread. Follows a example of use of this <span style="font-style: italic;">progressive report</span> feature:<br>
</div>
</td>
</tr>
</tbody>
</table>
<br>
<code></code><code></code>
<table style="width: 90%; height: 51px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);"><code>
<br>
// we need a variable that will be
visible by two threads: <br>
</code><code>libdar::statistics report;<br>
<br>
// and we need store the
libdar call returned value<br>
libdar::statistics final_result;<br>
<br>
// we spawn a first task
with a libdar call passing &report as argument to
"progressive_report"<br>
final_result =
some_call_to_be_defined_to_call_op_test_in_another_tread(...,
&report);<br>
<br>
// doing a endless loop
(assuming the current thread will be signaled or interrupted once the<br>
// previously libdar call running in another thread
will end)<br>
<br>
while(true)<br>
{<br>
sleep(1); // updating
the display each second<br>
some_function_to_update_the_display_with(report);<br>
}<br>
</code><br>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<h2><br>
</h2>
<h2>7 - listing archive contents</h2>
<br>
The simple way:<br>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;"><code><br>
my_arch-><span class="el">op_listing</span>(<span class="el"></span>dialog,<br>
archive_option_listing()); // default options<br>
</code><br>
</td>
<td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code>
<br>
li<span class="el">bdar::op_test_listing(</span></code><span class="el"><code><span class="el"></span>dialog,<br>
archive_options_listing(), // default options</code></span><span class="el"><code></code></span><br>
<span class="el"><code>
exception,// this gives the status of the call<br>
except_msg); // and in case of
error the <br>
// cause of the error<br>
<br>
</code></span><span class="el"><span class="el"><code>i</code></span><span class="el"><span class="el"><code>f(exception != LIBDAR_NOEXCEPT)<br>
std::cout << "an error occurred: " << except_msg <br>
<<
endl;<br>
<br>
</code></span></span></span> </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<div style="text-align: justify;">By default the library will
complete
the listing by calling the<span style="font-style: italic;"> warning()</span>
method of the <span style="font-style: italic;">dialog</span> object
one time for each file listed. The warning text will consist of a
string for each file with the relevant information in columns that
would need to be parsed if individual information was desired. This may
not be appropriate for you and as such there is another way to get
listing information. This requires a simple reimplementation of the <em>user_interaction</em>
object.<br>
</div>
<br>
<div style="text-align: justify;">The <span style="font-style: italic;">user_interaction</span> class
has a<span style="font-style: italic;"> </span><span style="font-weight: bold; font-style: italic;">listing()</span> method
which provides separate arguments for each piece of information that
can be displayed:<br>
</div>
<ul>
<li>filename, </li>
<li>permission, </li>
<li>user, </li>
<li>group, </li>
<li>file size,</li>
<li>last modification date,</li>
<li>if the file is a directory</li>
<li>if the file has children or is an empty dir</li>
<li>file type</li>
<li>flag about saved data / saved EA / compression used</li>
</ul>
<p><br>
</p>
<div style="text-align: justify;"><strong>Technical note:</strong>
<em>You may notice that file
type is
not explicitly given as a parameter in the listing method. File type is
available as the first byte of the permissions string. This is standard
POSIX stuff except for an extension: </em>"h"<em> for files hard
linked several times (it has been removed after release 2.3.0 / API 4.0.0). See </em><strong>man 2 stat</strong> <em>
for
more information about POSIX permissions. Note however that the last
arguments of this call, let you easily know whether a file is a
directory or not and whether it
is empty or not.</em></div>
<div style="text-align: justify;">In the <span style="font-style: italic;">user_interaction</span> class
(a virtual class), the <span style="font-style: italic;">listing()</span>
method is not a pure virtual method, so you are not obliged to
overwrite it, but it has just an empty implementation so it does
nothing.
You understand now that, by default, this method is not used. To
activate it, you must call <span style="font-style: italic;">
set_use_listing(true) </span>protected method and of course you will
have to overwrite the <span style="font-style: italic;">listing()</span>
method to have a less silly behavior: </div>
</td>
</tr>
</tbody>
</table>
<div style="text-align: justify;">
</div>
<br>
<code></code><code></code>
<table style="width: 90%; height: 51px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);"><code>
// here follows the definition of our own implementation of<br>
// of a user_interaction class <br>
<br>
class my_user_interaction : public user_interaction<br>
{<br>
public :<br>
// the inherited pure virtual methods we must define<br>
// as seen at the beginning of this tutorial:<br>
void pause(const std::string & message);<br>
</code><code> void
warning(const std::string & message);<br>
std::string get_string(const
std::string & message, bool echo);<br>
user_interaction *clone() const;<br>
<br>
// we can overwrite this method to have splitted
fields for listing:<br>
void listing(const
std::string & flag,<br>
const std::string
& perm,<br>
const
std::string & uid,<br>
const
std::string & gid,<br>
const std::string &
size,<br>
const
std::string & date,<br>
const std::string &
filename,<br>
bool
is_dir,<br>
bool
has_children);<br>
<br>
// but it will not get used by libdar unless
we call the protected method set_use_listing()<br>
// for example this can be done in the class
constructor :<br>
<br>
my_user_interaction() { <span style="font-weight: bold;">set_use_listing(true);</span> };<br>
};<br>
<br>
</code> </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<div style="text-align: justify;">Now assuming we have
implemented the <span style="font-style: italic;">listing()</span>
method in <span style="font-style: italic;">my_user_interaction</span>
class, calling <span style="font-style: italic;">op_listing()</span>
exactly as we did
before, only replacing the <span style="font-style: italic;">dialog</span>
object by one of the <span style="font-style: italic;">my_user_interaction</span>
class. Then this <span style="font-style: italic;">listing()</span>
method will be called for each file to be listed, in place of the <span style="font-style: italic;">warning()</span> method.<br>
</div>
<br>
<div style="text-align: justify;">As seen at the beginning of
this
tutorial, there is a child class of <span style="font-style: italic;">user_interaction</span>
based on callback functions which is called <span style="font-style: italic;">user_interaction_callback</span>. The <span style="font-style: italic;">listing()</span> method must also be
activated here. This is done automatically when you give a callback
function to the object, thanks to the <span style="font-weight: bold; font-style: italic;">set_listing_callback()</span>
method : </div>
</td>
</tr>
</tbody>
</table>
<br>
<code></code><code></code>
<table style="width: 90%; height: 51px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);"><code>
</code><code><br>
// our mandatory callback functions:<br>
<br>
void warning_callback(const std::string &x, void *context)<br>
{<br>
....<br>
}<br>
<br>
bool answer_callback(const std::string &x, void *context)<br>
{<br>
....<br>
}<br>
<br>
std::string string_callback(const std::string &x, bool echo, void
*context)<br>
{<br>
....<br>
}<br>
<br>
// let's build a user_interaction_callback object:<br>
<br>
libdar::user_interaction_callback dialog = <br>
libdar::user_interaction_callback(&warning_callback,
&answer_callback, &string_callback, NULL);<br>
<br>
// at this point our dialog object is perfectly
operational for listing<br>
// but libdar will call the warning_callback function to
list the archive<br>
// contents<br>
<br>
// a new callback function for listing :<br>
<br>
void listing_callback(const std::string & flag,<br>
const std::string & perm,<br>
const std::string & uid,<br>
const std::string & gid,<br>
const std::string & size,<br>
const std::string & date,<br>
const std::string & filename,<br>
bool is_dir,<br>
bool has_children,<br>
void *context)<br>
{<br>
....<br>
}<br>
<br>
<span style="font-weight: bold;">dialog.set_listing_callback(&listing_callback);</span><br>
<br>
// now libdar will call the listing_callback function when
we <br>
// use this <span style="font-style: italic;">dialog </span>object
for listing the archive contents.<br>
</code><br>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<div style="text-align: justify;">
</div>
<div style="text-align: justify;">Last point about listing, if
you examin the definition of the archive_option_listing class in file
libdar/archive_options.hpp, you will notice the the
set_list_mode() method. It may receive either <span style="font-weight: bold; font-style: italic;">normal,</span> <span style="font-style: italic; font-weight: bold;">tree</span> or <span style="font-style: italic; font-weight: bold;">xml</span> <span style="font-style: italic;">(normal</span> being the default).<br>
</div>
<ul style="text-align: justify;">
<li><span style="font-style: italic;">normal</span>, produces (if the <span style="font-style: italic;">listing()</span>
method of the given
user_interaction object is not overwritten) a listing like tar would
do. <br>
</li>
<li><span style="font-style: italic;"></span><span style="font-style: italic;">tree </span>produces a tree like directory listing (this was the original listing format in dar version 1.0.0)<span style="font-style: italic; font-weight: bold;"><br>
</span></li>
<li><span style="font-style: italic;">xml</span>, produces a XML output as described in doc/dar-catalog-1.0.dtd</li>
</ul>
<div style="text-align: justify;">Note that for these two last formats (tree and xml) the <span style="font-style: italic;">listing()</span> is never used, so even if
you provide a object which listing() method is overwritten, the <span style="font-style: italic;">archive::op_listing()</span> method will
still use the <span style="font-style: italic;">warning()</span>
method of this <span style="font-style: italic;">user_interaction</span>
object to report the archive contents.
<br>
</div>
<h2>7 bis - Dynamic archive contents listing</h2>
<div style="text-align: justify;">Well, in the previous chapter,
we saw
how to list the archive contents. You can imagine that when you have a
huge archive this op_listing() call may take a long time to complete and produces a
long output. If your application uses some graphical components and you
want to have a more interesting way for listing the archive contents,
you would maybe like to have just the first level of the directory tree
and let the user open the subdirectories and list their contents when needed,
having a sort of iterative archive listing. This would avoid having to
wait for the long listing to complete as well as it would avoid having
to allocate memory for all this graphical components representing each
directories and files, entries that will most of the time would not be
read by the user.<br>
</div>
<br>
First step, we need to use the listing() method of the
user_interaction() as seen above. <br>
Second step, we have to call the get_children_of() method of a given
archive class, instead of the op_listing() method.<br>
<div style="text-align: justify;">In the following example, we
will use
the <span style="font-style: italic;">user_interaction_callback</span>
class, but you can use your own inherited class from <span style="font-style: italic;">user_interaction</span>, and its <span style="font-style: italic;">listing()</span> class.<br>
</div>
</td>
</tr>
</tbody>
</table>
<br>
<code></code><code></code>
<table style="width: 90%; height: 51px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);"><code>
</code><code><br>
// our mandatory callback functions:<br>
<br>
void warning_callback(const std::string &x, void *context)<br>
{<br>
....<br>
}<br>
<br>
bool answer_callback(const std::string &x, void *context)<br>
{<br>
....<br>
}<br>
<br>
std::string string_callback(const std::string &x, bool echo, void
*context)<br>
{<br>
....<br>
}<br>
<br>
// Now the callback function implementing the listing() method
of class user_interaction<br>
<br>
</code><code>void listing_callback(const std::string & flag,<br>
const std::string & perm,<br>
const std::string & uid,<br>
const std::string & gid,<br>
const std::string & size,<br>
const std::string & date,<br>
const std::string & filename,<br>
bool is_dir,<br>
bool has_children,<br>
void *context)<br>
{<br>
....<br>
} <br>
<br>
// Now that our callback functions are ready, let's create a
user_interaction callback object named "dialog"<br>
</code><code><br>
libdar::user_interaction_callback dialog = <br>
libdar::user_interaction_callback(&warning_callback,
&answer_callback, &string_callback, NULL);<br>
<br>
// now we must assign the listing_callback() function to
"dialog".<br>
<span style="font-weight: bold;">dialog.set_listing_callback(&listing_callback);</span><br>
<br>
// Let's open an archive:<br>
archive some_archive = archive(dialog, "/some/dir", "basename", "dar", archive_option_read()); <br>
// we are reading a new archive,
but we could have created one instead...<br>
<br>
</code><code> // now, instead of calling op_listing()
method of some_archive giving our dialog object as argument, we can
rather call:<br>
<span style="font-weight: bold;">some_archive.get_children_of(dialog,
"");</span><br>
// the second argument is the directory of which we want to know
the subdirectories and subfiles. Here "" means the <br>
// root of the archive (we cannot use absolute path here).<br>
// get_chidren_of() method will call listing()'s dialog method
(here our listing_callback() function through the<br>
// user_interaction_callback implementation) for each entry of
the root directory.<br>
<br>
// let suppose that thanks to listing_callback() during the
previous call to get_chidren_of() we know that the entry <br>
// "var" exists (filename == var) and is a directory (is_dir ==
true) and has some children (has_children == true),<br>
// suppose the user want to know what is inside this directory,
we would then only have to call:<br>
<br>
<span style="font-weight: bold;">some_archive.get_children_of(dialog,
"var");</span><br>
// assuming through listing_callback we know that a subdirectory
tmp exist and is not empty, assuming that the user<br>
// want to know what is in it:<br>
<br>
s<span style="font-weight: bold;">ome_archive.get_children_of(dialog,
"var/tmp");</span><br>
// and so on.<br>
</code> </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<h2><br>
</h2>
<h2>8 - comparing with filesystem</h2>
We can compare file in an archive with the filesystem by calling the<span style="font-weight: bold; font-style: italic;"> op_diff</span> method
of the <span style="font-style: italic;">class archive</span>. </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;"><code><br>
ret = my_arch->op_diff(dialog,<br>
"/home", // what directory to take<br>
// as root we shall<br>
// compare the archive<br>
// contents to<br>
archive_options_diff(), // default options</code><code><br>
NULL); // we don't use progessive report<br>
</code> <code> <br>
<br>
<br>
<br>
</code> </td>
<td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code>
<br>
ret = </code><code>libdar::op_diff_noexcept(dialog,<br>
my_arch, // the archive to use<br>
"/home", // what directory to take<br>
// as root we shall<br>
// compare the archive<br>
// contents to<br>
</code><code>archive_options_diff(), // default options<br>
NULL, // we don't use progressive report<br>
</code> <code>
files</code><span class="el"><code>exception, // this
gives the<br>
// status of the call<br>
except_msg); // and in case of<br>
// error the cause of the<br>
//
error<br>
<br>
</code></span><span class="el"><span class="el"><code>i</code></span><span class="el"><span class="el"><code>f(exception != LIBDAR_NOEXCEPT)<br>
std::cout << "an error occurred: " << except_msg <br>
<<
std::endl;<br>
<br>
</code></span></span></span><span class="el"><code></code></span>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">Simple, no?<br>
<br>
Just a note about the <span style="font-style: italic;">set_what_to_check() </span>method<span style="font-style: italic;"> </span>argument of the archive_options_diff class.
It may take several values:<br>
<ul>
<li>cf_inode_type (default value): a file is considered as changed if its
inode type
has changed (directory/plain file/symbolic link/ ...)</li>
<li>cf_mtime : permission change is ignored, as well as
ownership
change</li>
<li>cf_ignore_owner : ownership change is ignored</li>
<li>cf_all : all fields denoting a content's file change
triggers a
file changed status (ownership, permission, dates, inode type).<br>
</li>
</ul>
<br style="font-style: italic;">
<h2>9 - restoring files</h2>
Restoration of files is done by calling the <span style="font-style: italic;"> </span><span style="font-weight: bold; font-style: italic;">op_extract</span>
method of <em>class archive</em>. </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;"><code><br>
ret = my_arch-><span class="el">op_extract</span>(<span class="el"></span>dialog,<br>
"/tmp", // where to restore files to<br>
archive_options_extract(), // default options</code><code><br>
NULL);// no progressive report used<br>
</code> </td>
<td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code>
<br>
<span class="el">ret = libdar::op_extract_noexcept(</span></code><span class="el"><code><span class="el"></span>dialog,<br>
my_arch, // the archive
to test<br>
</code></span><span class="el"><code>"/tmp",
// where to restore files to<br>
</code></span><code> archive_options_extract(), // default options</code><span class="el"><code></code><br>
</span><span class="el"><code></code></span><span class="el"><code>
exception,// this gives the status of the call<br>
except_msg); // and in case of
error the <br>
// cause of the error<br>
<br>
</code></span><span class="el"><span class="el"><code>i</code></span><span class="el"><span class="el"><code>f(exception != LIBDAR_NOEXCEPT)<br>
std::cout << "an error occurred: " << except_msg <br>
<<
std::endl;<br>
<br>
</code></span></span></span> </td>
</tr>
</tbody>
</table>
<br>
<table style="text-align: left; width: 90%; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="text-align: justify; vertical-align: top;">Here as we used default options, we restore all the files stored in the
archive in the directory /tmp (we also restore there the directory
structure stored in the archive), but we could also make a flat
restoration (ignore directory structure), as well as restore only some
of the files. By default too, dar asks user confirmation before
overwriting a file. You can change these options and many others using
the methods the class archive_options_extract. We will here restore all
that is under usr/lib and only files which filename ends with ".a", we
want libdar to skip file that would lead to overwriting an existing
file and also have libdar display files that have been skipped from the
restoration.</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody><tr><td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;"><code>archive_options_extract options;<br>
<br>
options.set_selection(simple_mask("*.a", true));<br>
options.set_subtree(simple_path_mask("usr/lib", true));<br>
options.set_allow_over(false);<br>
options.set_display_skipped(true);<br>
<br>
ret = my_arch-><span class="el">op_extract</span>(<span class="el"></span>dialog,<br>
"/tmp", // where to restore files to<br>
options, // non default options set just above</code><code><br>
NULL);// no progressive report used<br>
</code> </td>
<td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code></code><code>archive_options_extract options;<br>
<br>
options.set_selection(simple_mask("*.a", true));<br>
options.set_subtree(simple_path_mask("usr/lib", true));<br>
options.set_allow_over(false);<br>
options.set_display_skipped(true);<br>
<br>
</code><code>
<span class="el">ret = libdar::op_extract_noexcept(</span></code><span class="el"><code><span class="el"></span>dialog,<br>
my_arch, // the archive
to test<br>
</code></span><span class="el"><code>"/tmp",
// where to restore files to<br>
</code></span><code>options, // non default options set just above<br>
NULL,</code><code> // no progressive report used</code><span class="el"><br>
</span><span class="el"><code></code></span><span class="el"><code>
exception,// this gives the status of the call<br>
except_msg); // and in case of
error the <br>
// cause of the error<br>
</code></span></td></tr></tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">last point about optional parameter concerns the <span style="font-style: italic;">set</span>_<span style="font-style: italic;">what_to_check</span> method. It serves two roles here: <br>
<ol style="text-align: justify;">
<li>Which field are to be ignored when looking whether a file is
more
recent than the one in the filesystem (if this feature is enabled)<br>
</li>
<li>Which field to avoid restoring (for example, when not having root
privileges, avoid restoring ownership may be interesting instead of
having a plethora of failure to restore ownership messages).<br>
</li>
</ol>
<h2><br>
</h2>
<h2>10 - Isolating the Catalogue</h2>
<div style="text-align: justify;">OK, I know, <span style="font-style: italic;">catalogue </span>is not an English word
(one would rather write <span style="font-style: italic;">catalog</span>),
but that's the name of the C++ class used in libdar, so we will keep
using it here. Note that you don't have to directly access this
class (if you really don't like French).<br>
</div>
<br>
<div style="text-align: justify;">Isolating the catalogue creates
a new
archive that only contains the list of files and their attributes
(ownership, dates, size, etc.), but no data and no EA are stored in it.
It is very similar to the same archive one gets if one makes a
differential backup of a filesystem that has not changed since the
creation of a reference archive. The usage is very similar to the
archive creation, but it uses a different constructor that has less
arguments:<br>
</div>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;"><code>archive_options_isolate options;<br>
<br>
// we just want to have a compressed isolated catalogue<br>
options.set_compression(gzip);<br>
<br>
libdar::archive *my_cat = new libdar::archive(dialog,<br>
"/tmp", // where the extracted <br>
// catalogue is saved<br>
my_arch, // the archive of reference<br>
// is the one we have been<br>
// playing with previously<br>
"my_catalogue", // slice name<br>
"dar", // file extension<br>
options) // non default options set above<br>
<br>
<br>
</code><br>
</td>
<td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code></code><code>archive_options_isolate options;<br>
<br>
// we just want to have a compressed isolated catalogue<br>
options.set_compression(gzip);<br>
</code><code> <br>
<span class="el">libdar::archive *my_cat = <br>
libdar::op_isolate_noexcept(dialog,<br>
</span></code><span class="el"><code>
"/tmp", // where is saved the <br>
// extracted catalogue<br>
my_arch, // the archive of reference<br>
// is the one we have been<br>
// playing with previously<br>
"my_catalogue", // slice name<br>
"dar", // file extension<br>
options, // non default options set above</code><br>
</span><span class="el"><code></code></span><span class="el"><code>
exception,<br>
// this gives
the status <br>
// of the call<br>
except_msg); <br>
// and in
case of error the <br>
// cause of the error<br>
<br>
</code></span><span class="el"><span class="el"><code>i</code></span><span class="el"><span class="el"><code>f(exception != LIBDAR_NOEXCEPT)<br>
std::cout << "an error occurred: " << except_msg <br>
<<
std::endl;<br>
<br>
</code></span></span></span> </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<div style="text-align: justify;">Now we have two archive
objects. <span style="font-style: italic;">my_arch</span> is a
read-only object
created by the "read" constructor. You can do any operations with it,
like file restoration, file comparison, archive testing, as we have
done in the previous sections. The second archive object is <span style="font-style: italic;">my_cat</span> which is a write only
object. It can only be used as a reference for another backup (a
differential backup) or as a reference for a subsequent catalogue
isolation (which would just clone the already isolated catalogue object
here). <br>
<br>
Note that once closed (object destruction) you can re-open the isolated
catalogue and use it as a read-only object (you can then test its
integrity as seen previously).<br>
<br>
So for now we will just destroy
the extracted catalogue object, so that all its file descriptors are
closed: </div>
</td>
</tr>
</tbody>
</table>
<br>
<div style="text-align: justify;">
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;"><code><br>
delete my_cat; <br>
</code><br>
</td>
<td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code></code><code><br>
close_archive_noexcept (my_cat, exception,<br>
except_msg);<br>
<br>
</code><span class="el"><code>if(exception != LIBDAR_NOEXCEPT)<br>
std::cout << "an error occurred: " << except_msg <br>
<<
std::endl;</code></span><code> <br>
<span class="el"></span></code><span class="el"><span class="el"><span class="el"><code><br>
</code></span></span></span> </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">and we keep the <span style="font-style: italic;">my_arch</span>
object for our last operation:<br>
<h2>11 - creating a differential backup</h2>
<div style="text-align: justify;">This operation is the same as
the
first one we did (archive creation). We will just provide the archive of reference as an optional parameter. If we had
not destroyed <span style="font-style: italic;">my_cat </span>above,
we could have used it in place of <span style="font-style: italic;">my_arch</span>
for exactly the same result.<br>
</div>
</td>
</tr>
</tbody>
</table>
<br>
</div>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;"><code>archive_options_create options;<br>
<br>
// we provide here the reference to an <br>
// existing archive object, this implies that<br>
// the archive will be a differential backup<br>
options.set_reference(my_arch);<br>
<br>
// as we are now used to options, we will set a more<br>
// complex set of other options:<br>
options.set_selection(not_mask(simple_mask("*~")));<br>
options.set_empty_dir(true);<br>
options.set_compression(bzip2);<br>
options.set_compr_mask(not_mask(simple_mask("*.bz2")));<br>
options.set_cache_directory_tagging(true);<br>
options.set_slice_permission("0600");<br>
options.set_slice_user_ownership("root");<br>
options.set_slice_group_ownership("bin");<br>
options.set_crypto_algo(crypto_blowfish);<br>
// if not specified with set_crypto_pass() the password<br>
// will be asked interactively to the user<br>
options.set_slicing(100000000, 20480);<br>
<br>
libdar::archive *my_other_arch = <br>
new libdar::archive(dialog, <br>
"/home", // saving all under this "root"<br>
"/tmp", // where the slices will go<br>
"my_archive", //
the basename of the slices <br>
"dar", // dar's slice extensions<br>
options, // the optional parameter as defined above</code><code></code><br>
<code> NULL); // no progressive report</code><br>
</td>
<td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code>archive_options_create options;<br>
<br>
// we provide here the reference to an <br>
// existing archive object, this implies that<br>
// the archive will be a differential backup<br>
options.set_reference(my_arch);<br>
<br>
// as we are now used to options, we will set a more<br>
// complex set of other options:<br>
options.set_selection(not_mask(simple_mask("*~")));<br>
options.set_empty_dir(true);<br>
options.set_compression(bzip2);<br>
options.set_compr_mask(not_mask(simple_mask("*.bz2")));<br>
options.set_cache_directory_tagging(true);<br>
options.set_slice_permission("0600");<br>
options.set_slice_user_ownership("root");<br>
options.set_slice_group_ownership("bin");<br>
options.set_crypto_algo(crypto_blowfish);<br>
// if not specified with set_crypto_pass() the password<br>
// will be asked interactively to the user<br>
options.set_slicing(100000000, 20480);</code><code><br>
<br>
</code><code></code>
<code><span class="el">libdar::archive *my_other_arch
= <br>
libdar::create_archive_noexcept(dialog,</span></code><span class="el"><code> <br>
"/home", // saving all under this "root"<br>
"/tmp", // where the slices will go<br>
</code></span><span class="el"><code><span style="font-weight: bold;"> my_arch, //
differential backup </span></code></span><span class="el"><code><br>
"my_archive", //
the basename of the slices <br>
"dar", // dar's slice extensions<br>
</code></span><code>options, // the optional parameter as defined above</code><span class="el"><code><br></code></span><span class="el"></span><span class="el"><code> exception,
// thisgives the status of the call<br>
except_msg); // and in case of error the cause.<br>
<br>
if(exception != LIBDAR_NOEXCEPT)<br>
std::cout << "an error occurred: " << except_msg <br>
<<
std::endl;<br>
<br>
</code></span> </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<div style="text-align: justify;">As previously, my_other_arch is
a write only object that we won't need
anymore. So we destroy it: </div>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;"><code><br>
delete my_other_arch;<br>
<br>
</code> </td>
<td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code><br>
libdar::close_archive_noexcept(my_other_arch,<br>
exception,<br>
except_msg);<br>
<br>
</code><span class="el"><code>if(exception != LIBDAR_NOEXCEPT)<br>
std::cout << "an error occurred: " << except_msg <br>
<<
std::endl;<br>
<br>
</code></span> </td>
</tr>
</tbody>
</table>
<br>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; text-align: justify;">We are
at the end of this first part of the tutorial, where we have
seen the general way to manipulate dar archives like dar command-line
does. But we still have an object we need
to destroy to cleanly release the memory used:<br>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;"><code><br>
delete my_arch;<br>
<br>
</code> </td>
<td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code><br>
libdar::close_archive_noexcept(my_arch, exception,<br>
except_msg);<br>
<br>
</code><span class="el"><code>if(exception != LIBDAR_NOEXCEPT)<br>
std::cout << "an error occurred: " << except_msg <br>
<<
std::endl;<br>
<br>
</code></span> </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">For more detailed information
about the API you can build the API
documentation from the source code using Doxygen or get it online from <a href="http://dar.linux.free.fr/doc/man/index.html">dar home page</a> or <a href="http://dar.sourceforge.net/doc/man/index.html">mirror site</a>.<br>
<br>
<br>
<h2>12 - Compilation & Linking<br>
</h2>
<h3>Compilation</h3>
All the symbols found in the libdar API are defined via <span style="font-style: italic; font-weight: bold;"><dar/libdar.h></span>
so you should only need to include this header.<br>
</td>
</tr>
</tbody>
</table>
<br>
<code></code><code></code>
<table style="width: 90%; height: 51px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);"><br>
<code></code>> cat my_prog.cpp<span style="font-weight: bold;"><br>
#include <dar/libdar.h></span><br>
<br>
main()<br>
{<br>
libdar::get_version(...);<br>
...<br>
}<br>
> gcc -c my_prog.cpp<br>
<br>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<h3><br>
</h3>
<h3>Linking</h3>
<br>
Of course, you need to link your program with libdar. This is done by
adding <span style="font-style: italic; font-weight: bold;">-ldar</span>
plus other library libdar can be built to use like libz, libbzip2, liblzo or libgcrypt :<code></code><code></code> <code> </code> </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; height: 51px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);"><code></code><code></code><span style="font-weight: bold;"></span><br>
> gcc <span style="font-weight: bold;">-ldar</span> -lz -lbzip2 -llzo -lgcrypt my_prog.o -o
my_prog<br>
<br>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<h3>Libdar's different flavors</h3>
<br>
<div style="text-align: justify;">Well, all the compilation and
linking
steps described above assume you
have a "<span style="font-style: italic;">full</span>" libdar library.
Beside the <span style="font-style: italic;">full</span> (alias <span style="font-style: italic;">infinint</span>) libdar flavor, libdar
also comes in 32 and 64 bits
versions. In these last ones, in place of internally relying on a
special type (which
is a C++ class called<span style="font-style: italic;"> infinint</span>)
to
handle arbitrary large integers, libdar32 relies on 32 bits integers
and
libdar64 relies on 64 bits integers (there are limitations which are
described in doc/LIMITATIONS). But all these libdar version (infinint,
32bits, 64bits) have the same
interface and must be used the same way, except for compilation and
linking.<br>
</div>
<br>
<div style="text-align: justify;">These different libdar
versions can
coexist on the same system, they
share the same include files. But the MODE macro must be set to 32
or 64 when compiling for linking with libdar32 or libdar64
respectively. The MODE macro defines the way the "<span style="font-style: italic;">class infinint" </span>type is
implemented in libdar, and thus changes the way the libdar headers
files are interpreted by the compiler. </div>
</td>
</tr>
</tbody>
</table>
<br>
<code></code><code></code>
<table style="width: 90%; height: 51px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);"><code></code>>
cat my_prog.cpp<span style="font-weight: bold;"><br>
</span>#include <dar/libdar.h><br>
<br>
main()<br>
{<br>
libdar::get_version(...);<br>
...<br>
}<br>
> gcc -c <span style="font-weight: bold;">-DMODE=32</span>
my_prog.cpp<br>
<br>
<code></code><code></code><span style="font-weight: bold;"></span><br>
> gcc <span style="font-weight: bold;">-ldar32</span> my_prog.o -o
my_prog<br>
<br>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; margin-right: auto; margin-left: auto; text-align: left;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">and replace 32 by 64 to link
with libdar64. <br>
<br>
<div style="text-align: justify;">Note that libdar*.pc files are
installed in the <span style="font-style: italic;">$(PREFIX)/lib/pkgconfig</span>
file that should simplify (depending on the point of view) all these
operations.
For example, if you have all different flavors of libdar installed, the
<span style="font-style: italic;">$(PREFIX)/lib/pkgconfig</span>
dir will contain (among other files) the three
following ones:<br>
</div>
<ul>
<li>libdar.pc</li>
<li>libdar32.pc</li>
<li>libdar64.pc</li>
</ul>
<div style="text-align: justify;">Thus, if you want to build your
application with libdar32 for example, you will have to call (assuming
you have <span style="font-style: italic;">pkg-config</span> installed)<br>
</div>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; height: 51px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);"><code></code>>
gcc <span style="font-weight: bold;">`pkg-config --cflags libdar32`</span>
-c
my_prog.cpp<br>
<br>
<code></code><code></code><span style="font-weight: bold;"></span><br>
> gcc <span style="font-weight: bold;">`pkg-config --libs libdar32`</span>
my_prog.o -o
my_prog<br>
<br>
</td>
</tr>
</tbody>
</table>
<br>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;"><br>
<br>
<br>
<h2>13 - Aborting an Operation</h2>
<div style="text-align: justify;">If the POSIX thread support is
available,<span style="font-style: italic;"> libdar</span> will be
built in a
thread-safe manner, thus you may have several thread using libdar calls
at the same time. You may then wish to interrupt a given thread. But
aborting a thread form the outside (like sending it a KILL signal) will
most of the time let some memory allocated or even worse can lead to
dead-lock
situation, when the killed thread was in a critical section and had not
got the opportunity to release a <span style="font-style: italic;">mutex</span>.
For that reason, libdar proposes a set
of calls to abort any processing libdar call which is ran by a given
thread. <br>
</div>
</td>
</tr>
</tbody>
</table>
<br>
<code></code><code></code>
<table style="width: 90%; height: 51px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);"><code></code>
<span style="font-style: italic;"></span> // next is the
thread ID in which we want to have
lidbar call canceled<br>
// here for simplicity we don't describe the way the
ID has been obtained<br>
pthread_t thread_id = 161720;<br>
<br>
// the most simple call is :<br>
libdar::cancel_thread(thread_id);<br>
// this will make any libdar call in this thread be
canceled immediately<br>
<br>
// but you can use something a bit more interesting:<br>
libdar::cancel_thread(thread_id, false);<br>
// this second argument is true for immediate cancellation,<br>
// of false for a delayed cancellation, in which case
libdar
aborts the operation<br>
// but produces something usable, for example, if you were
backing up something<br>
// you get a real usable archive which only contains
files saved so far, in place<br>
// of having a broken archive which miss a catalogue at
the end. Note that this<br>
// delayed
cancellation needs a bit more time to complete, depending on the<br>
// size of the archive
under process.<br>
<br>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<div style="text-align: justify;">As seen above, cancellation can
be
very simple. What now succeeds when
you ask for a cancellation this way? Well, an exception of type <span style="font-weight: bold; font-style: italic;">Ethread_cancel</span>
is thrown. All along his path, memory is released and mutex are freed.
Last, the exception appears to the libdar caller. So, you can catch it
to define a specific comportment. And if you don't want to use exceptions a
special returned code is used.<br>
</div>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(153, 255, 255); width: 50%;"><code>try<br>
{<br>
</code><code>libdar::archive *my_arch =<br>
new
libdar::archive(...);<br>
...<br>
}<br>
catch(libdar::Ethread_cancel & e)<br>
{<br>
... do something when thread has been canceled;<br>
}<br>
<br>
</code><code> </code><br>
</td>
<td style="vertical-align: top; background-color: rgb(153, 255, 153); width: 50px;"><code></code><code><br>
</code><code>U_16 ex;<br>
std::string msg;<br>
<span class="el"></span></code><span class="el"><span class="el"><span class="el"><code>archive *my_arch =<br>
libdar::open_archive_noexcept(...,ex,msg);<br>
<br>
switch(ex)<br>
{<br>
case ...<br>
.... <br>
break;<br>
case LIBDAR_THREAD_CANCEL:<br>
... do something when thread has been canceled<br>
break;<br>
case ...<br>
}<br>
<br>
</code></span></span></span> </td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<div style="text-align: justify;">Some helper routines are
available to
know the cancellation status for a particular thread or to abort a
cancellation process if it has not yet been engaged.<br>
</div>
</td>
</tr>
</tbody>
</table>
<br>
<code></code><code></code>
<table style="width: 90%; height: 51px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);"> pthread_t
tid;<br>
<br>
// how to know if the thread <span style="font-style: italic;">tid</span> is under cancellation process ?<br>
if(<span style="font-weight: bold;">libdar::cancel_status</span>(tid))<br>
cout << "thread cancellation is under
progress for thread : " << tid << endl;<br>
else<br>
cout << "no thread cancellation is under
progress for thread : " << endl;<br>
<br>
// how to cancel a pending thread cancellation ?<br>
if(<span style="font-weight: bold;">libdar::cancel_clear</span>(tid))<br>
cout << "pending thread cancellation has been
reset, thread " << tid << " has not been canceled" <<
endl;<br>
else<br>
cout << "too late, could not avoid thread
cancellation for thread "<< tid << endl;<br>
<br>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">Last point, back to the<span style="font-weight: bold; font-style: italic;"> Ethread_cancel</span>
exception, this class has two methods you may find useful, when you
catch it: </td>
</tr>
</tbody>
</table>
<br>
<code></code><code></code>
<table style="width: 90%; height: 51px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);"><code></code>try<br>
{<br>
... some libdar calls<br>
}<br>
catch(libdar::Ethread_cancel & e)<br>
{<br>
if(e.<span style="font-weight: bold;">immediate_cancel</span>())<br>
cout << "cancel_thread() has
been called with "true" as second argument" << endl;<br>
else<br>
cout << "cancel_thread() has been
called with "false" as second argument" << endl;<br>
<br>
U64 flag = e.<span style="font-weight: bold;">get_flag</span>();<br>
... do something with the flag variable...<br>
}<br>
<br>
// what is this flag stored in this exception ?<br>
// You must consider that the complete definition of
cancel_thread() is the following:<br>
// <span style="font-style: italic;">void
cancel_thread(pthread_t tid, bool immediate = true, U_64 flag = 0);<br>
</span>// thus, any argument given in third is
passed to the thrown Ethread_cancel exception, <br>
// value which can be retrieved thanks to its
get_flag() method. The value given to this<br>
// flag is not used by libdar itself, it is a facility
for user program to have the possibility <br>
// to include additional information about the
thread cancellation.<br>
<br>
// supposing the thread cancellation has been
invoked by :<br>
libdar::cancel_thread(thread_id, true, 19);<br>
// then the<span style="font-style: italic;"> flag</span>
variable in the catch() statement above would have received<br>
<div style="text-align: justify;"> // the value <span style="font-style: italic;">19</span>.<br>
</div>
</td>
</tr>
</tbody>
</table>
<div style="text-align: justify;"><br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<div style="text-align: justify;">
</div>
<p style="text-align: justify;"><span style="font-weight: bold; text-decoration: underline;">A last and important point about multi-threaded environment: </span>An
object like any other variable cannot be modified or read (with the use
of its methods) without precaution from several threads at the same
time. Care must be taken to avoid this situation, and the use of Posix
mutex is recommanded in your program if you plan to let an archive
object be accessed by more than one thread. See the <a href="http://dar.sourceforge.net/doc/FAQ.html#threadsafe">FAQ</a> for more about this point.<br>
</p>
<br>
<br>
<br>
<h2 style="text-align: justify;">14 - Dar_manager API</h2>
<br>
<div style="text-align: justify;">For more about <span style="font-style: italic;">dar_manager</span>, please read the <span style="font-style: italic;"></span>man page where are described in
detail the available features. Note that for <span style="font-style: italic;">dar_manager</span> there is not
a "<span style="font-style: italic;">without exception</span>" flavor,
your
program
must be able to handle exceptions, which by the way are the same as the
ones described above.<br>
</div>
<br>
<div style="text-align: justify;">To get dar_manager features you
need to use the <span style="font-weight: bold; font-style: italic;">class
database</span>
which is defined in the <span style="font-style: italic;">libdar/database.hpp</span>
header file so you first need to include that file. Most of the methods of the <span style="font-style: italic;">database</span> class do use options. For the same reason as previously seen for <span style="font-style: italic;">archive</span> manipulation, these options are passed thanks to a container class. These container classes for options used by the <span style="font-style: italic;">database</span> class are defined in the<span style="font-style: italic;"> libdar/database_options.hpp</span> file. Let's see the
different method of the class <span style="font-style: italic;">database</span>
:<br>
</div>
<br>
<h3>Database object construction</h3>
Two constructor are available: </td>
</tr>
</tbody>
</table>
<br>
</div>
<code></code><code></code>
<table style="width: 90%; height: 51px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; background-color: rgb(204, 204, 204);"><code>#include
<dar/database.hpp><br>
</code><code><span style="font-weight: bold;"></span><br>
void my_sample_function(user_interaction & dialog)<br>
{<br>
database base; // we have created an empty
database (no archive in it) called "base"<br>
<br>
database other = database(dialog,
"/tmp/existing_base.dmd", database_open_options());<br>
// we have created a database object called "other" which contains <br>
// (in RAM) all information that were contained in the <br>
// database file "/tmp/existing_base.dmd"<br>
// I will explain below the last argument<br>
<br>
database_open_option opt;<br>
opt.set_partial(true);<br>
database other2 = database(dialog, "/tmp/existing_base.dmd", opt);<br>
// we have created a database object called "other2" which differs<br>
// from "other" in the option we used. While "other" is a fully loaded <br>
// database, "other2" is a partial database. This notion is explained <br>
// below<br>
}</code> <br>
<br>
</td>
</tr>
</tbody>
</table>
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<div style="text-align: justify;">So far, this is not much
complicated.
You can build an empty database
from nothing, or load a database to memory from a file using the second
constructor. As you can see over the filename to give in this later
constructor, we need a <span style="font-style: italic;">user_interaction</span>
object to be able to inform the
user of any problem that could be met, and an object of class
database_open_options. This last object contains options to use for
this call (options are set to their default unless modified
explicitely). Currently, the only available option is the "partial"
option which is a boolean argument:<br>
<br>
In all the available methods for class database, some require to load
the whole database in the memory while some other only require
the database header. Loading just the database header is much faster
than loading the whole database, of course, and as you guess it requires
much less memory. While you can perform any operation with a full
loaded database, only a subset of available method will be available
with a partially loaded database. If you try a method that
requires a completely loaded database, you will get an exception if the
object you use has been loaded with "true" as last argument (called
"partial") of the constructor, and of course an empty database (built
with the first
constructor) is a completely loaded database, so you don't have
restriction in using a new database object. <br>
<br>
But now let's see the
available method for that class:<br>
</div>
<br>
<h3>Database's methods <br>
</h3>
First we will see methods that work with both partially and completely
loaded databases:<br>
<ul>
<li>dump(...) : it is used to write back the database to a
file. <br>
</li>
<li>change_name() : change the basename of the archive which
index is
given in argument</li>
<li>set_path() : change the path to the archive which index is
given
in argument</li>
<li>set_options() : change the default options to always pass
to dar
when performing restoration</li>
<li>set_dar_path() : specify the path to dar (use empty string
to
rely on the PATH variable)</li>
<li>show_contents() : list the archives used to build the
database</li>
<li>get_options() : list the options that will be passed to dar
(as
defined with the set_options() method)</li>
<li>get_dar_path() : return the path to dar (or empty string if
relying on the PATH variable)</li>
</ul>
<br>
Now let's see the database methods that only work with completely
loaded databases:<br>
<ul>
<li>add_archive() : add an archive to the database</li>
<li>remove_archive() : remove an archive from the database</li>
<li>set_permutation() : change archive relative order within
the
database</li>
<li>show_files() : list the files which are present in the
given
archive<br>
</li>
<li>show_version() : list the archive where the given file is
saved</li>
<li>show_most_recent_stats() : compute statistics about
the
location of most recent file versions</li>
<li>restore() : restore a set of given files given in argument.</li>
</ul>
<div style="text-align: justify;">Well, you might now say that as
description this is a bit light for a
tutorial, yes. In fact these call are really very simple to use, you
can find a complete description in the reference documentation of the
API. This documentation is built if doxygen is available and is put
under doc/html after calling make in the source
package. It is also available from <a href="http://dar.linux.free.fr/html/">dar's
homepage</a>. </div>
</td>
</tr>
</tbody>
</table>
<br>
<hr style="width: 100%; height: 2px;"><br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<h2>Thanks</h2>
<br>
<div style="text-align: justify;">I would like to thank Wesley
Leggette and Johnathan Burchill for having
given their feedback and
having done grammar corrections to this document. Out of this document,
I would also like to thanks them a second time for their work around
dar and libdar (Johnathan is the author of kdar, the KDE front-end for
dar).<br>
</div>
<br>
Regards,<br>
Denis Corbin.<br>
</td>
</tr>
</tbody>
</table>
<br>
</center>
</body></html>
|