Commit 2376cd26226771dcf8ef5dfd04c83a50c50bf3d4

Edward Thomson 2019-07-20T20:48:49

Merge pull request #5151 from pks-t/pks/w32-unlink-symlink w32: fix unlinking of directory symlinks

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
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
diff --git a/fuzzers/standalone_driver.c b/fuzzers/standalone_driver.c
index c661970..90e7013 100644
--- a/fuzzers/standalone_driver.c
+++ b/fuzzers/standalone_driver.c
@@ -8,7 +8,7 @@
 #include <stdio.h>
 
 #include "git2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "path.h"
 
 extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size);
diff --git a/src/apply.c b/src/apply.c
index 9d607dd..55b1a39 100644
--- a/src/apply.c
+++ b/src/apply.c
@@ -18,7 +18,7 @@
 #include "git2/repository.h"
 #include "array.h"
 #include "patch.h"
-#include "fileops.h"
+#include "futils.h"
 #include "delta.h"
 #include "zstream.h"
 #include "reader.h"
diff --git a/src/attr_file.h b/src/attr_file.h
index 9538f47..f4f9a09 100644
--- a/src/attr_file.h
+++ b/src/attr_file.h
@@ -14,7 +14,7 @@
 #include "vector.h"
 #include "pool.h"
 #include "buffer.h"
-#include "fileops.h"
+#include "futils.h"
 
 #define GIT_ATTR_FILE			".gitattributes"
 #define GIT_ATTR_FILE_INREPO	"attributes"
diff --git a/src/blob.h b/src/blob.h
index b9aa330..0d743ec 100644
--- a/src/blob.h
+++ b/src/blob.h
@@ -12,7 +12,7 @@
 #include "git2/blob.h"
 #include "repository.h"
 #include "odb.h"
-#include "fileops.h"
+#include "futils.h"
 
 struct git_blob {
 	git_object object;
diff --git a/src/checkout.c b/src/checkout.c
index 730ec62..d618e3d 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -1893,11 +1893,18 @@ static int checkout_create_the_new(
 				return error;
 		}
 
-		if (actions[i] & CHECKOUT_ACTION__UPDATE_BLOB) {
-			error = checkout_blob(data, &delta->new_file);
-			if (error < 0)
+		if (actions[i] & CHECKOUT_ACTION__UPDATE_BLOB && !S_ISLNK(delta->new_file.mode)) {
+			if ((error = checkout_blob(data, &delta->new_file)) < 0)
 				return error;
+			data->completed_steps++;
+			report_progress(data, delta->new_file.path);
+		}
+	}
 
+	git_vector_foreach(&data->diff->deltas, i, delta) {
+		if (actions[i] & CHECKOUT_ACTION__UPDATE_BLOB && S_ISLNK(delta->new_file.mode)) {
+			if ((error = checkout_blob(data, &delta->new_file)) < 0)
+				return error;
 			data->completed_steps++;
 			report_progress(data, delta->new_file.path);
 		}
diff --git a/src/clone.c b/src/clone.c
index 4e2dd50..e0b43f1 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -19,7 +19,7 @@
 #include "git2/tree.h"
 
 #include "remote.h"
-#include "fileops.h"
+#include "futils.h"
 #include "refs.h"
 #include "path.h"
 #include "repository.h"
diff --git a/src/config_cache.c b/src/config_cache.c
index dbc463b..e4e071b 100644
--- a/src/config_cache.c
+++ b/src/config_cache.c
@@ -7,7 +7,7 @@
 
 #include "common.h"
 
-#include "fileops.h"
+#include "futils.h"
 #include "repository.h"
 #include "config.h"
 #include "git2/config.h"
diff --git a/src/config_parse.h b/src/config_parse.h
index 0129ee3..b791d32 100644
--- a/src/config_parse.h
+++ b/src/config_parse.h
@@ -10,7 +10,7 @@
 #include "common.h"
 
 #include "array.h"
-#include "fileops.h"
+#include "futils.h"
 #include "oid.h"
 #include "parse.h"
 
diff --git a/src/crlf.c b/src/crlf.c
index 22989c1..edccc0a 100644
--- a/src/crlf.c
+++ b/src/crlf.c
@@ -12,7 +12,7 @@
 #include "git2/index.h"
 #include "git2/sys/filter.h"
 
-#include "fileops.h"
+#include "futils.h"
 #include "hash.h"
 #include "filter.h"
 #include "buf_text.h"
diff --git a/src/diff_file.c b/src/diff_file.c
index 48e95eb..978d7ea 100644
--- a/src/diff_file.c
+++ b/src/diff_file.c
@@ -12,7 +12,7 @@
 #include "diff.h"
 #include "diff_generate.h"
 #include "odb.h"
-#include "fileops.h"
+#include "futils.h"
 #include "filter.h"
 
 #define DIFF_MAX_FILESIZE 0x20000000
diff --git a/src/diff_generate.c b/src/diff_generate.c
index dad3c0c..7ec317b 100644
--- a/src/diff_generate.c
+++ b/src/diff_generate.c
@@ -9,7 +9,7 @@
 
 #include "diff.h"
 #include "patch_generate.h"
-#include "fileops.h"
+#include "futils.h"
 #include "config.h"
 #include "attr_file.h"
 #include "filter.h"
diff --git a/src/diff_print.c b/src/diff_print.c
index 664336e..f1aac5e 100644
--- a/src/diff_print.c
+++ b/src/diff_print.c
@@ -10,7 +10,7 @@
 #include "diff.h"
 #include "diff_file.h"
 #include "patch_generate.h"
-#include "fileops.h"
+#include "futils.h"
 #include "zstream.h"
 #include "blob.h"
 #include "delta.h"
diff --git a/src/diff_tform.c b/src/diff_tform.c
index a87661e..fc60121 100644
--- a/src/diff_tform.c
+++ b/src/diff_tform.c
@@ -14,7 +14,7 @@
 #include "diff.h"
 #include "diff_generate.h"
 #include "path.h"
-#include "fileops.h"
+#include "futils.h"
 #include "config.h"
 
 git_diff_delta *git_diff__delta_dup(
diff --git a/src/fetchhead.c b/src/fetchhead.c
index bdded02..a3f6fbc 100644
--- a/src/fetchhead.c
+++ b/src/fetchhead.c
@@ -11,7 +11,7 @@
 #include "git2/oid.h"
 
 #include "buffer.h"
-#include "fileops.h"
+#include "futils.h"
 #include "filebuf.h"
 #include "refs.h"
 #include "repository.h"
diff --git a/src/filebuf.c b/src/filebuf.c
index 8a70bcd..aaebf82 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -7,7 +7,7 @@
 
 #include "filebuf.h"
 
-#include "fileops.h"
+#include "futils.h"
 
 static const size_t WRITE_BUFFER_SIZE = (4096 * 2);
 
diff --git a/src/filebuf.h b/src/filebuf.h
index f51ff23..b5002ec 100644
--- a/src/filebuf.h
+++ b/src/filebuf.h
@@ -9,7 +9,7 @@
 
 #include "common.h"
 
-#include "fileops.h"
+#include "futils.h"
 #include "hash.h"
 #include <zlib.h>
 
diff --git a/src/fileops.c b/src/fileops.c
deleted file mode 100644
index 648ffbe..0000000
--- a/src/fileops.c
+++ /dev/null
@@ -1,1183 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-
-#include "fileops.h"
-
-#include "global.h"
-#include "strmap.h"
-#include <ctype.h>
-#if GIT_WIN32
-#include "win32/findfile.h"
-#endif
-
-int git_futils_mkpath2file(const char *file_path, const mode_t mode)
-{
-	return git_futils_mkdir(
-		file_path, mode,
-		GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR);
-}
-
-int git_futils_mktmp(git_buf *path_out, const char *filename, mode_t mode)
-{
-	int fd;
-	mode_t mask;
-
-	p_umask(mask = p_umask(0));
-
-	git_buf_sets(path_out, filename);
-	git_buf_puts(path_out, "_git2_XXXXXX");
-
-	if (git_buf_oom(path_out))
-		return -1;
-
-	if ((fd = p_mkstemp(path_out->ptr)) < 0) {
-		git_error_set(GIT_ERROR_OS,
-			"failed to create temporary file '%s'", path_out->ptr);
-		return -1;
-	}
-
-	if (p_chmod(path_out->ptr, (mode & ~mask))) {
-		git_error_set(GIT_ERROR_OS,
-			"failed to set permissions on file '%s'", path_out->ptr);
-		return -1;
-	}
-
-	return fd;
-}
-
-int git_futils_creat_withpath(const char *path, const mode_t dirmode, const mode_t mode)
-{
-	int fd;
-
-	if (git_futils_mkpath2file(path, dirmode) < 0)
-		return -1;
-
-	fd = p_creat(path, mode);
-	if (fd < 0) {
-		git_error_set(GIT_ERROR_OS, "failed to create file '%s'", path);
-		return -1;
-	}
-
-	return fd;
-}
-
-int git_futils_creat_locked(const char *path, const mode_t mode)
-{
-	int fd = p_open(path, O_WRONLY | O_CREAT | O_EXCL | O_BINARY | O_CLOEXEC,
-		mode);
-
-	if (fd < 0) {
-		int error = errno;
-		git_error_set(GIT_ERROR_OS, "failed to create locked file '%s'", path);
-		switch (error) {
-		case EEXIST:
-			return GIT_ELOCKED;
-		case ENOENT:
-			return GIT_ENOTFOUND;
-		default:
-			return -1;
-		}
-	}
-
-	return fd;
-}
-
-int git_futils_creat_locked_withpath(const char *path, const mode_t dirmode, const mode_t mode)
-{
-	if (git_futils_mkpath2file(path, dirmode) < 0)
-		return -1;
-
-	return git_futils_creat_locked(path, mode);
-}
-
-int git_futils_open_ro(const char *path)
-{
-	int fd = p_open(path, O_RDONLY);
-	if (fd < 0)
-		return git_path_set_error(errno, path, "open");
-	return fd;
-}
-
-int git_futils_truncate(const char *path, int mode)
-{
-	int fd = p_open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, mode);
-	if (fd < 0)
-		return git_path_set_error(errno, path, "open");
-
-	close(fd);
-	return 0;
-}
-
-git_off_t git_futils_filesize(git_file fd)
-{
-	struct stat sb;
-
-	if (p_fstat(fd, &sb)) {
-		git_error_set(GIT_ERROR_OS, "failed to stat file descriptor");
-		return -1;
-	}
-
-	return sb.st_size;
-}
-
-mode_t git_futils_canonical_mode(mode_t raw_mode)
-{
-	if (S_ISREG(raw_mode))
-		return S_IFREG | GIT_PERMS_CANONICAL(raw_mode);
-	else if (S_ISLNK(raw_mode))
-		return S_IFLNK;
-	else if (S_ISGITLINK(raw_mode))
-		return S_IFGITLINK;
-	else if (S_ISDIR(raw_mode))
-		return S_IFDIR;
-	else
-		return 0;
-}
-
-int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
-{
-	ssize_t read_size = 0;
-	size_t alloc_len;
-
-	git_buf_clear(buf);
-
-	if (!git__is_ssizet(len)) {
-		git_error_set(GIT_ERROR_INVALID, "read too large");
-		return -1;
-	}
-
-	GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, len, 1);
-	if (git_buf_grow(buf, alloc_len) < 0)
-		return -1;
-
-	/* p_read loops internally to read len bytes */
-	read_size = p_read(fd, buf->ptr, len);
-
-	if (read_size != (ssize_t)len) {
-		git_error_set(GIT_ERROR_OS, "failed to read descriptor");
-		git_buf_dispose(buf);
-		return -1;
-	}
-
-	buf->ptr[read_size] = '\0';
-	buf->size = read_size;
-
-	return 0;
-}
-
-int git_futils_readbuffer_updated(
-	git_buf *out, const char *path, git_oid *checksum, int *updated)
-{
-	int error;
-	git_file fd;
-	struct stat st;
-	git_buf buf = GIT_BUF_INIT;
-	git_oid checksum_new;
-
-	assert(out && path && *path);
-
-	if (updated != NULL)
-		*updated = 0;
-
-	if (p_stat(path, &st) < 0)
-		return git_path_set_error(errno, path, "stat");
-
-
-	if (S_ISDIR(st.st_mode)) {
-		git_error_set(GIT_ERROR_INVALID, "requested file is a directory");
-		return GIT_ENOTFOUND;
-	}
-
-	if (!git__is_sizet(st.st_size+1)) {
-		git_error_set(GIT_ERROR_OS, "invalid regular file stat for '%s'", path);
-		return -1;
-	}
-
-	if ((fd = git_futils_open_ro(path)) < 0)
-		return fd;
-
-	if (git_futils_readbuffer_fd(&buf, fd, (size_t)st.st_size) < 0) {
-		p_close(fd);
-		return -1;
-	}
-
-	p_close(fd);
-
-	if (checksum) {
-		if ((error = git_hash_buf(&checksum_new, buf.ptr, buf.size)) < 0) {
-			git_buf_dispose(&buf);
-			return error;
-		}
-
-		/*
-		 * If we were given a checksum, we only want to use it if it's different
-		 */
-		if (!git_oid__cmp(checksum, &checksum_new)) {
-			git_buf_dispose(&buf);
-			if (updated)
-				*updated = 0;
-
-			return 0;
-		}
-
-		git_oid_cpy(checksum, &checksum_new);
-	}
-
-	/*
-	 * If we're here, the file did change, or the user didn't have an old version
-	 */
-	if (updated != NULL)
-		*updated = 1;
-
-	git_buf_swap(out, &buf);
-	git_buf_dispose(&buf);
-
-	return 0;
-}
-
-int git_futils_readbuffer(git_buf *buf, const char *path)
-{
-	return git_futils_readbuffer_updated(buf, path, NULL, NULL);
-}
-
-int git_futils_writebuffer(
-	const git_buf *buf,	const char *path, int flags, mode_t mode)
-{
-	int fd, do_fsync = 0, error = 0;
-
-	if (!flags)
-		flags = O_CREAT | O_TRUNC | O_WRONLY;
-
-	if ((flags & O_FSYNC) != 0)
-		do_fsync = 1;
-
-	flags &= ~O_FSYNC;
-
-	if (!mode)
-		mode = GIT_FILEMODE_BLOB;
-
-	if ((fd = p_open(path, flags, mode)) < 0) {
-		git_error_set(GIT_ERROR_OS, "could not open '%s' for writing", path);
-		return fd;
-	}
-
-	if ((error = p_write(fd, git_buf_cstr(buf), git_buf_len(buf))) < 0) {
-		git_error_set(GIT_ERROR_OS, "could not write to '%s'", path);
-		(void)p_close(fd);
-		return error;
-	}
-
-	if (do_fsync && (error = p_fsync(fd)) < 0) {
-		git_error_set(GIT_ERROR_OS, "could not fsync '%s'", path);
-		p_close(fd);
-		return error;
-	}
-
-	if ((error = p_close(fd)) < 0) {
-		git_error_set(GIT_ERROR_OS, "error while closing '%s'", path);
-		return error;
-	}
-
-	if (do_fsync && (flags & O_CREAT))
-		error = git_futils_fsync_parent(path);
-
-	return error;
-}
-
-int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmode)
-{
-	if (git_futils_mkpath2file(to, dirmode) < 0)
-		return -1;
-
-	if (p_rename(from, to) < 0) {
-		git_error_set(GIT_ERROR_OS, "failed to rename '%s' to '%s'", from, to);
-		return -1;
-	}
-
-	return 0;
-}
-
-int git_futils_mmap_ro(git_map *out, git_file fd, git_off_t begin, size_t len)
-{
-	return p_mmap(out, len, GIT_PROT_READ, GIT_MAP_SHARED, fd, begin);
-}
-
-int git_futils_mmap_ro_file(git_map *out, const char *path)
-{
-	git_file fd = git_futils_open_ro(path);
-	git_off_t len;
-	int result;
-
-	if (fd < 0)
-		return fd;
-
-	if ((len = git_futils_filesize(fd)) < 0) {
-		result = -1;
-		goto out;
-	}
-
-	if (!git__is_sizet(len)) {
-		git_error_set(GIT_ERROR_OS, "file `%s` too large to mmap", path);
-		result = -1;
-		goto out;
-	}
-
-	result = git_futils_mmap_ro(out, fd, 0, (size_t)len);
-out:
-	p_close(fd);
-	return result;
-}
-
-void git_futils_mmap_free(git_map *out)
-{
-	p_munmap(out);
-}
-
-GIT_INLINE(int) mkdir_validate_dir(
-	const char *path,
-	struct stat *st,
-	mode_t mode,
-	uint32_t flags,
-	struct git_futils_mkdir_options *opts)
-{
-	/* with exclusive create, existing dir is an error */
-	if ((flags & GIT_MKDIR_EXCL) != 0) {
-		git_error_set(GIT_ERROR_FILESYSTEM,
-			"failed to make directory '%s': directory exists", path);
-		return GIT_EEXISTS;
-	}
-
-	if ((S_ISREG(st->st_mode) && (flags & GIT_MKDIR_REMOVE_FILES)) ||
-		(S_ISLNK(st->st_mode) && (flags & GIT_MKDIR_REMOVE_SYMLINKS))) {
-		if (p_unlink(path) < 0) {
-			git_error_set(GIT_ERROR_OS, "failed to remove %s '%s'",
-				S_ISLNK(st->st_mode) ? "symlink" : "file", path);
-			return GIT_EEXISTS;
-		}
-
-		opts->perfdata.mkdir_calls++;
-
-		if (p_mkdir(path, mode) < 0) {
-			git_error_set(GIT_ERROR_OS, "failed to make directory '%s'", path);
-			return GIT_EEXISTS;
-		}
-	}
-
-	else if (S_ISLNK(st->st_mode)) {
-		/* Re-stat the target, make sure it's a directory */
-		opts->perfdata.stat_calls++;
-
-		if (p_stat(path, st) < 0) {
-			git_error_set(GIT_ERROR_OS, "failed to make directory '%s'", path);
-			return GIT_EEXISTS;
-		}
-	}
-
-	else if (!S_ISDIR(st->st_mode)) {
-		git_error_set(GIT_ERROR_FILESYSTEM,
-			"failed to make directory '%s': directory exists", path);
-		return GIT_EEXISTS;
-	}
-
-	return 0;
-}
-
-GIT_INLINE(int) mkdir_validate_mode(
-	const char *path,
-	struct stat *st,
-	bool terminal_path,
-	mode_t mode,
-	uint32_t flags,
-	struct git_futils_mkdir_options *opts)
-{
-	if (((terminal_path && (flags & GIT_MKDIR_CHMOD) != 0) ||
-		(flags & GIT_MKDIR_CHMOD_PATH) != 0) && st->st_mode != mode) {
-
-		opts->perfdata.chmod_calls++;
-
-		if (p_chmod(path, mode) < 0) {
-			git_error_set(GIT_ERROR_OS, "failed to set permissions on '%s'", path);
-			return -1;
-		}
-	}
-
-	return 0;
-}
-
-GIT_INLINE(int) mkdir_canonicalize(
-	git_buf *path,
-	uint32_t flags)
-{
-	ssize_t root_len;
-
-	if (path->size == 0) {
-		git_error_set(GIT_ERROR_OS, "attempt to create empty path");
-		return -1;
-	}
-
-	/* Trim trailing slashes (except the root) */
-	if ((root_len = git_path_root(path->ptr)) < 0)
-		root_len = 0;
-	else
-		root_len++;
-
-	while (path->size > (size_t)root_len && path->ptr[path->size - 1] == '/')
-		path->ptr[--path->size] = '\0';
-
-	/* if we are not supposed to made the last element, truncate it */
-	if ((flags & GIT_MKDIR_SKIP_LAST2) != 0) {
-		git_path_dirname_r(path, path->ptr);
-		flags |= GIT_MKDIR_SKIP_LAST;
-	}
-	if ((flags & GIT_MKDIR_SKIP_LAST) != 0) {
-		git_path_dirname_r(path, path->ptr);
-	}
-
-	/* We were either given the root path (or trimmed it to
-	* the root), we don't have anything to do.
-	*/
-	if (path->size <= (size_t)root_len)
-		git_buf_clear(path);
-
-	return 0;
-}
-
-int git_futils_mkdir(
-	const char *path,
-	mode_t mode,
-	uint32_t flags)
-{
-	git_buf make_path = GIT_BUF_INIT, parent_path = GIT_BUF_INIT;
-	const char *relative;
-	struct git_futils_mkdir_options opts = { 0 };
-	struct stat st;
-	size_t depth = 0;
-	int len = 0, root_len, error;
-
-	if ((error = git_buf_puts(&make_path, path)) < 0 ||
-		(error = mkdir_canonicalize(&make_path, flags)) < 0 ||
-		(error = git_buf_puts(&parent_path, make_path.ptr)) < 0 ||
-		make_path.size == 0)
-		goto done;
-
-	root_len = git_path_root(make_path.ptr);
-
-	/* find the first parent directory that exists.  this will be used
-	 * as the base to dirname_relative.
-	 */
-	for (relative = make_path.ptr; parent_path.size; ) {
-		error = p_lstat(parent_path.ptr, &st);
-
-		if (error == 0) {
-			break;
-		} else if (errno != ENOENT) {
-			git_error_set(GIT_ERROR_OS, "failed to stat '%s'", parent_path.ptr);
-			goto done;
-		}
-
-		depth++;
-
-		/* examine the parent of the current path */
-		if ((len = git_path_dirname_r(&parent_path, parent_path.ptr)) < 0) {
-			error = len;
-			goto done;
-		}
-
-		assert(len);
-
-		/*
-		 * We've walked all the given path's parents and it's either relative
-		 * (the parent is simply '.') or rooted (the length is less than or
-		 * equal to length of the root path).  The path may be less than the
-		 * root path length on Windows, where `C:` == `C:/`.
-		 */
-		if ((len == 1 && parent_path.ptr[0] == '.') ||
-		    (len == 1 && parent_path.ptr[0] == '/') ||
-		    len <= root_len) {
-			relative = make_path.ptr;
-			break;
-		}
-
-		relative = make_path.ptr + len + 1;
-
-		/* not recursive? just make this directory relative to its parent. */
-		if ((flags & GIT_MKDIR_PATH) == 0)
-			break;
-	}
-
-	/* we found an item at the location we're trying to create,
-	 * validate it.
-	 */
-	if (depth == 0) {
-		error = mkdir_validate_dir(make_path.ptr, &st, mode, flags, &opts);
-
-		if (!error)
-			error = mkdir_validate_mode(
-				make_path.ptr, &st, true, mode, flags, &opts);
-
-		goto done;
-	}
-
-	/* we already took `SKIP_LAST` and `SKIP_LAST2` into account when
-	 * canonicalizing `make_path`.
-	 */
-	flags &= ~(GIT_MKDIR_SKIP_LAST2 | GIT_MKDIR_SKIP_LAST);
-
-	error = git_futils_mkdir_relative(relative,
-		parent_path.size ? parent_path.ptr : NULL, mode, flags, &opts);
-
-done:
-	git_buf_dispose(&make_path);
-	git_buf_dispose(&parent_path);
-	return error;
-}
-
-int git_futils_mkdir_r(const char *path, const mode_t mode)
-{
-	return git_futils_mkdir(path, mode, GIT_MKDIR_PATH);
-}
-
-int git_futils_mkdir_relative(
-	const char *relative_path,
-	const char *base,
-	mode_t mode,
-	uint32_t flags,
-	struct git_futils_mkdir_options *opts)
-{
-	git_buf make_path = GIT_BUF_INIT;
-	ssize_t root = 0, min_root_len;
-	char lastch = '/', *tail;
-	struct stat st;
-	struct git_futils_mkdir_options empty_opts = {0};
-	int error;
-
-	if (!opts)
-		opts = &empty_opts;
-
-	/* build path and find "root" where we should start calling mkdir */
-	if (git_path_join_unrooted(&make_path, relative_path, base, &root) < 0)
-		return -1;
-
-	if ((error = mkdir_canonicalize(&make_path, flags)) < 0 ||
-		make_path.size == 0)
-		goto done;
-
-	/* if we are not supposed to make the whole path, reset root */
-	if ((flags & GIT_MKDIR_PATH) == 0)
-		root = git_buf_rfind(&make_path, '/');
-
-	/* advance root past drive name or network mount prefix */
-	min_root_len = git_path_root(make_path.ptr);
-	if (root < min_root_len)
-		root = min_root_len;
-	while (root >= 0 && make_path.ptr[root] == '/')
-		++root;
-
-	/* clip root to make_path length */
-	if (root > (ssize_t)make_path.size)
-		root = (ssize_t)make_path.size; /* i.e. NUL byte of string */
-	if (root < 0)
-		root = 0;
-
-	/* walk down tail of path making each directory */
-	for (tail = &make_path.ptr[root]; *tail; *tail = lastch) {
-		bool mkdir_attempted = false;
-
-		/* advance tail to include next path component */
-		while (*tail == '/')
-			tail++;
-		while (*tail && *tail != '/')
-			tail++;
-
-		/* truncate path at next component */
-		lastch = *tail;
-		*tail = '\0';
-		st.st_mode = 0;
-
-		if (opts->dir_map && git_strmap_exists(opts->dir_map, make_path.ptr))
-			continue;
-
-		/* See what's going on with this path component */
-		opts->perfdata.stat_calls++;
-
-retry_lstat:
-		if (p_lstat(make_path.ptr, &st) < 0) {
-			if (mkdir_attempted || errno != ENOENT) {
-				git_error_set(GIT_ERROR_OS, "cannot access component in path '%s'", make_path.ptr);
-				error = -1;
-				goto done;
-			}
-
-			git_error_clear();
-			opts->perfdata.mkdir_calls++;
-			mkdir_attempted = true;
-			if (p_mkdir(make_path.ptr, mode) < 0) {
-				if (errno == EEXIST)
-					goto retry_lstat;
-				git_error_set(GIT_ERROR_OS, "failed to make directory '%s'", make_path.ptr);
-				error = -1;
-				goto done;
-			}
-		} else {
-			if ((error = mkdir_validate_dir(
-				make_path.ptr, &st, mode, flags, opts)) < 0)
-				goto done;
-		}
-
-		/* chmod if requested and necessary */
-		if ((error = mkdir_validate_mode(
-			make_path.ptr, &st, (lastch == '\0'), mode, flags, opts)) < 0)
-			goto done;
-
-		if (opts->dir_map && opts->pool) {
-			char *cache_path;
-			size_t alloc_size;
-
-			GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, make_path.size, 1);
-			cache_path = git_pool_malloc(opts->pool, alloc_size);
-			GIT_ERROR_CHECK_ALLOC(cache_path);
-
-			memcpy(cache_path, make_path.ptr, make_path.size + 1);
-
-			if ((error = git_strmap_set(opts->dir_map, cache_path, cache_path)) < 0)
-				goto done;
-		}
-	}
-
-	error = 0;
-
-	/* check that full path really is a directory if requested & needed */
-	if ((flags & GIT_MKDIR_VERIFY_DIR) != 0 &&
-		lastch != '\0') {
-		opts->perfdata.stat_calls++;
-
-		if (p_stat(make_path.ptr, &st) < 0 || !S_ISDIR(st.st_mode)) {
-			git_error_set(GIT_ERROR_OS, "path is not a directory '%s'",
-				make_path.ptr);
-			error = GIT_ENOTFOUND;
-		}
-	}
-
-done:
-	git_buf_dispose(&make_path);
-	return error;
-}
-
-typedef struct {
-	const char *base;
-	size_t baselen;
-	uint32_t flags;
-	int depth;
-} futils__rmdir_data;
-
-#define FUTILS_MAX_DEPTH 100
-
-static int futils__error_cannot_rmdir(const char *path, const char *filemsg)
-{
-	if (filemsg)
-		git_error_set(GIT_ERROR_OS, "could not remove directory '%s': %s",
-				   path, filemsg);
-	else
-		git_error_set(GIT_ERROR_OS, "could not remove directory '%s'", path);
-
-	return -1;
-}
-
-static int futils__rm_first_parent(git_buf *path, const char *ceiling)
-{
-	int error = GIT_ENOTFOUND;
-	struct stat st;
-
-	while (error == GIT_ENOTFOUND) {
-		git_buf_rtruncate_at_char(path, '/');
-
-		if (!path->size || git__prefixcmp(path->ptr, ceiling) != 0)
-			error = 0;
-		else if (p_lstat_posixly(path->ptr, &st) == 0) {
-			if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))
-				error = p_unlink(path->ptr);
-			else if (!S_ISDIR(st.st_mode))
-				error = -1; /* fail to remove non-regular file */
-		} else if (errno != ENOTDIR)
-			error = -1;
-	}
-
-	if (error)
-		futils__error_cannot_rmdir(path->ptr, "cannot remove parent");
-
-	return error;
-}
-
-static int futils__rmdir_recurs_foreach(void *opaque, git_buf *path)
-{
-	int error = 0;
-	futils__rmdir_data *data = opaque;
-	struct stat st;
-
-	if (data->depth > FUTILS_MAX_DEPTH)
-		error = futils__error_cannot_rmdir(
-			path->ptr, "directory nesting too deep");
-
-	else if ((error = p_lstat_posixly(path->ptr, &st)) < 0) {
-		if (errno == ENOENT)
-			error = 0;
-		else if (errno == ENOTDIR) {
-			/* asked to remove a/b/c/d/e and a/b is a normal file */
-			if ((data->flags & GIT_RMDIR_REMOVE_BLOCKERS) != 0)
-				error = futils__rm_first_parent(path, data->base);
-			else
-				futils__error_cannot_rmdir(
-					path->ptr, "parent is not directory");
-		}
-		else
-			error = git_path_set_error(errno, path->ptr, "rmdir");
-	}
-
-	else if (S_ISDIR(st.st_mode)) {
-		data->depth++;
-
-		error = git_path_direach(path, 0, futils__rmdir_recurs_foreach, data);
-
-		data->depth--;
-
-		if (error < 0)
-			return error;
-
-		if (data->depth == 0 && (data->flags & GIT_RMDIR_SKIP_ROOT) != 0)
-			return error;
-
-		if ((error = p_rmdir(path->ptr)) < 0) {
-			if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) != 0 &&
-				(errno == ENOTEMPTY || errno == EEXIST || errno == EBUSY))
-				error = 0;
-			else
-				error = git_path_set_error(errno, path->ptr, "rmdir");
-		}
-	}
-
-	else if ((data->flags & GIT_RMDIR_REMOVE_FILES) != 0) {
-		if (p_unlink(path->ptr) < 0)
-			error = git_path_set_error(errno, path->ptr, "remove");
-	}
-
-	else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0)
-		error = futils__error_cannot_rmdir(path->ptr, "still present");
-
-	return error;
-}
-
-static int futils__rmdir_empty_parent(void *opaque, const char *path)
-{
-	futils__rmdir_data *data = opaque;
-	int error = 0;
-
-	if (strlen(path) <= data->baselen)
-		error = GIT_ITEROVER;
-
-	else if (p_rmdir(path) < 0) {
-		int en = errno;
-
-		if (en == ENOENT || en == ENOTDIR) {
-			/* do nothing */
-		} else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0 &&
-			en == EBUSY) {
-			error = git_path_set_error(errno, path, "rmdir");
-		} else if (en == ENOTEMPTY || en == EEXIST || en == EBUSY) {
-			error = GIT_ITEROVER;
-		} else {
-			error = git_path_set_error(errno, path, "rmdir");
-		}
-	}
-
-	return error;
-}
-
-int git_futils_rmdir_r(
-	const char *path, const char *base, uint32_t flags)
-{
-	int error;
-	git_buf fullpath = GIT_BUF_INIT;
-	futils__rmdir_data data;
-
-	/* build path and find "root" where we should start calling mkdir */
-	if (git_path_join_unrooted(&fullpath, path, base, NULL) < 0)
-		return -1;
-
-	memset(&data, 0, sizeof(data));
-	data.base    = base ? base : "";
-	data.baselen = base ? strlen(base) : 0;
-	data.flags   = flags;
-
-	error = futils__rmdir_recurs_foreach(&data, &fullpath);
-
-	/* remove now-empty parents if requested */
-	if (!error && (flags & GIT_RMDIR_EMPTY_PARENTS) != 0)
-		error = git_path_walk_up(
-			&fullpath, base, futils__rmdir_empty_parent, &data);
-
-	if (error == GIT_ITEROVER) {
-		git_error_clear();
-		error = 0;
-	}
-
-	git_buf_dispose(&fullpath);
-
-	return error;
-}
-
-int git_futils_fake_symlink(const char *old, const char *new)
-{
-	int retcode = GIT_ERROR;
-	int fd = git_futils_creat_withpath(new, 0755, 0644);
-	if (fd >= 0) {
-		retcode = p_write(fd, old, strlen(old));
-		p_close(fd);
-	}
-	return retcode;
-}
-
-static int cp_by_fd(int ifd, int ofd, bool close_fd_when_done)
-{
-	int error = 0;
-	char buffer[FILEIO_BUFSIZE];
-	ssize_t len = 0;
-
-	while (!error && (len = p_read(ifd, buffer, sizeof(buffer))) > 0)
-		/* p_write() does not have the same semantics as write().  It loops
-		 * internally and will return 0 when it has completed writing.
-		 */
-		error = p_write(ofd, buffer, len);
-
-	if (len < 0) {
-		git_error_set(GIT_ERROR_OS, "read error while copying file");
-		error = (int)len;
-	}
-
-	if (error < 0)
-		git_error_set(GIT_ERROR_OS, "write error while copying file");
-
-	if (close_fd_when_done) {
-		p_close(ifd);
-		p_close(ofd);
-	}
-
-	return error;
-}
-
-int git_futils_cp(const char *from, const char *to, mode_t filemode)
-{
-	int ifd, ofd;
-
-	if ((ifd = git_futils_open_ro(from)) < 0)
-		return ifd;
-
-	if ((ofd = p_open(to, O_WRONLY | O_CREAT | O_EXCL, filemode)) < 0) {
-		p_close(ifd);
-		return git_path_set_error(errno, to, "open for writing");
-	}
-
-	return cp_by_fd(ifd, ofd, true);
-}
-
-int git_futils_touch(const char *path, time_t *when)
-{
-	struct p_timeval times[2];
-	int ret;
-
-	times[0].tv_sec =  times[1].tv_sec  = when ? *when : time(NULL);
-	times[0].tv_usec = times[1].tv_usec = 0;
-
-	ret = p_utimes(path, times);
-
-	return (ret < 0) ? git_path_set_error(errno, path, "touch") : 0;
-}
-
-static int cp_link(const char *from, const char *to, size_t link_size)
-{
-	int error = 0;
-	ssize_t read_len;
-	char *link_data;
-	size_t alloc_size;
-
-	GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, link_size, 1);
-	link_data = git__malloc(alloc_size);
-	GIT_ERROR_CHECK_ALLOC(link_data);
-
-	read_len = p_readlink(from, link_data, link_size);
-	if (read_len != (ssize_t)link_size) {
-		git_error_set(GIT_ERROR_OS, "failed to read symlink data for '%s'", from);
-		error = -1;
-	}
-	else {
-		link_data[read_len] = '\0';
-
-		if (p_symlink(link_data, to) < 0) {
-			git_error_set(GIT_ERROR_OS, "could not symlink '%s' as '%s'",
-				link_data, to);
-			error = -1;
-		}
-	}
-
-	git__free(link_data);
-	return error;
-}
-
-typedef struct {
-	const char *to_root;
-	git_buf to;
-	ssize_t from_prefix;
-	uint32_t flags;
-	uint32_t mkdir_flags;
-	mode_t dirmode;
-} cp_r_info;
-
-#define GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT (1u << 10)
-
-static int _cp_r_mkdir(cp_r_info *info, git_buf *from)
-{
-	int error = 0;
-
-	/* create root directory the first time we need to create a directory */
-	if ((info->flags & GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT) == 0) {
-		error = git_futils_mkdir(
-			info->to_root, info->dirmode,
-			(info->flags & GIT_CPDIR_CHMOD_DIRS) ? GIT_MKDIR_CHMOD : 0);
-
-		info->flags |= GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT;
-	}
-
-	/* create directory with root as base to prevent excess chmods */
-	if (!error)
-		error = git_futils_mkdir_relative(
-			from->ptr + info->from_prefix, info->to_root,
-			info->dirmode, info->mkdir_flags, NULL);
-
-	return error;
-}
-
-static int _cp_r_callback(void *ref, git_buf *from)
-{
-	int error = 0;
-	cp_r_info *info = ref;
-	struct stat from_st, to_st;
-	bool exists = false;
-
-	if ((info->flags & GIT_CPDIR_COPY_DOTFILES) == 0 &&
-		from->ptr[git_path_basename_offset(from)] == '.')
-		return 0;
-
-	if ((error = git_buf_joinpath(
-			&info->to, info->to_root, from->ptr + info->from_prefix)) < 0)
-		return error;
-
-	if (!(error = git_path_lstat(info->to.ptr, &to_st)))
-		exists = true;
-	else if (error != GIT_ENOTFOUND)
-		return error;
-	else {
-		git_error_clear();
-		error = 0;
-	}
-
-	if ((error = git_path_lstat(from->ptr, &from_st)) < 0)
-		return error;
-
-	if (S_ISDIR(from_st.st_mode)) {
-		mode_t oldmode = info->dirmode;
-
-		/* if we are not chmod'ing, then overwrite dirmode */
-		if ((info->flags & GIT_CPDIR_CHMOD_DIRS) == 0)
-			info->dirmode = from_st.st_mode;
-
-		/* make directory now if CREATE_EMPTY_DIRS is requested and needed */
-		if (!exists && (info->flags & GIT_CPDIR_CREATE_EMPTY_DIRS) != 0)
-			error = _cp_r_mkdir(info, from);
-
-		/* recurse onto target directory */
-		if (!error && (!exists || S_ISDIR(to_st.st_mode)))
-			error = git_path_direach(from, 0, _cp_r_callback, info);
-
-		if (oldmode != 0)
-			info->dirmode = oldmode;
-
-		return error;
-	}
-
-	if (exists) {
-		if ((info->flags & GIT_CPDIR_OVERWRITE) == 0)
-			return 0;
-
-		if (p_unlink(info->to.ptr) < 0) {
-			git_error_set(GIT_ERROR_OS, "cannot overwrite existing file '%s'",
-				info->to.ptr);
-			return GIT_EEXISTS;
-		}
-	}
-
-	/* Done if this isn't a regular file or a symlink */
-	if (!S_ISREG(from_st.st_mode) &&
-		(!S_ISLNK(from_st.st_mode) ||
-		 (info->flags & GIT_CPDIR_COPY_SYMLINKS) == 0))
-		return 0;
-
-	/* Make container directory on demand if needed */
-	if ((info->flags & GIT_CPDIR_CREATE_EMPTY_DIRS) == 0 &&
-		(error = _cp_r_mkdir(info, from)) < 0)
-		return error;
-
-	/* make symlink or regular file */
-	if (info->flags & GIT_CPDIR_LINK_FILES) {
-		if ((error = p_link(from->ptr, info->to.ptr)) < 0)
-			git_error_set(GIT_ERROR_OS, "failed to link '%s'", from->ptr);
-	} else if (S_ISLNK(from_st.st_mode)) {
-		error = cp_link(from->ptr, info->to.ptr, (size_t)from_st.st_size);
-	} else {
-		mode_t usemode = from_st.st_mode;
-
-		if ((info->flags & GIT_CPDIR_SIMPLE_TO_MODE) != 0)
-			usemode = GIT_PERMS_FOR_WRITE(usemode);
-
-		error = git_futils_cp(from->ptr, info->to.ptr, usemode);
-	}
-
-	return error;
-}
-
-int git_futils_cp_r(
-	const char *from,
-	const char *to,
-	uint32_t flags,
-	mode_t dirmode)
-{
-	int error;
-	git_buf path = GIT_BUF_INIT;
-	cp_r_info info;
-
-	if (git_buf_joinpath(&path, from, "") < 0) /* ensure trailing slash */
-		return -1;
-
-	memset(&info, 0, sizeof(info));
-	info.to_root = to;
-	info.flags   = flags;
-	info.dirmode = dirmode;
-	info.from_prefix = path.size;
-	git_buf_init(&info.to, 0);
-
-	/* precalculate mkdir flags */
-	if ((flags & GIT_CPDIR_CREATE_EMPTY_DIRS) == 0) {
-		/* if not creating empty dirs, then use mkdir to create the path on
-		 * demand right before files are copied.
-		 */
-		info.mkdir_flags = GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST;
-		if ((flags & GIT_CPDIR_CHMOD_DIRS) != 0)
-			info.mkdir_flags |= GIT_MKDIR_CHMOD_PATH;
-	} else {
-		/* otherwise, we will do simple mkdir as directories are encountered */
-		info.mkdir_flags =
-			((flags & GIT_CPDIR_CHMOD_DIRS) != 0) ? GIT_MKDIR_CHMOD : 0;
-	}
-
-	error = _cp_r_callback(&info, &path);
-
-	git_buf_dispose(&path);
-	git_buf_dispose(&info.to);
-
-	return error;
-}
-
-int git_futils_filestamp_check(
-	git_futils_filestamp *stamp, const char *path)
-{
-	struct stat st;
-
-	/* if the stamp is NULL, then always reload */
-	if (stamp == NULL)
-		return 1;
-
-	if (p_stat(path, &st) < 0)
-		return GIT_ENOTFOUND;
-
-	if (stamp->mtime.tv_sec == st.st_mtime &&
-#if defined(GIT_USE_NSEC)
-		stamp->mtime.tv_nsec == st.st_mtime_nsec &&
-#endif
-		stamp->size  == (git_off_t)st.st_size   &&
-		stamp->ino   == (unsigned int)st.st_ino)
-		return 0;
-
-	stamp->mtime.tv_sec = st.st_mtime;
-#if defined(GIT_USE_NSEC)
-	stamp->mtime.tv_nsec = st.st_mtime_nsec;
-#endif
-	stamp->size  = (git_off_t)st.st_size;
-	stamp->ino   = (unsigned int)st.st_ino;
-
-	return 1;
-}
-
-void git_futils_filestamp_set(
-	git_futils_filestamp *target, const git_futils_filestamp *source)
-{
-	assert(target);
-
-	if (source)
-		memcpy(target, source, sizeof(*target));
-	else
-		memset(target, 0, sizeof(*target));
-}
-
-
-void git_futils_filestamp_set_from_stat(
-	git_futils_filestamp *stamp, struct stat *st)
-{
-	if (st) {
-		stamp->mtime.tv_sec = st->st_mtime;
-#if defined(GIT_USE_NSEC)
-		stamp->mtime.tv_nsec = st->st_mtime_nsec;
-#else
-		stamp->mtime.tv_nsec = 0;
-#endif
-		stamp->size  = (git_off_t)st->st_size;
-		stamp->ino   = (unsigned int)st->st_ino;
-	} else {
-		memset(stamp, 0, sizeof(*stamp));
-	}
-}
-
-int git_futils_fsync_dir(const char *path)
-{
-#ifdef GIT_WIN32
-	GIT_UNUSED(path);
-	return 0;
-#else
-	int fd, error = -1;
-
-	if ((fd = p_open(path, O_RDONLY)) < 0) {
-		git_error_set(GIT_ERROR_OS, "failed to open directory '%s' for fsync", path);
-		return -1;
-	}
-
-	if ((error = p_fsync(fd)) < 0)
-		git_error_set(GIT_ERROR_OS, "failed to fsync directory '%s'", path);
-
-	p_close(fd);
-	return error;
-#endif
-}
-
-int git_futils_fsync_parent(const char *path)
-{
-	char *parent;
-	int error;
-
-	if ((parent = git_path_dirname(path)) == NULL)
-		return -1;
-
-	error = git_futils_fsync_dir(parent);
-	git__free(parent);
-	return error;
-}
diff --git a/src/fileops.h b/src/fileops.h
deleted file mode 100644
index 85131f8..0000000
--- a/src/fileops.h
+++ /dev/null
@@ -1,390 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-#ifndef INCLUDE_fileops_h__
-#define INCLUDE_fileops_h__
-
-#include "common.h"
-
-#include "map.h"
-#include "posix.h"
-#include "path.h"
-#include "pool.h"
-#include "strmap.h"
-#include "oid.h"
-
-/**
- * Filebuffer methods
- *
- * Read whole files into an in-memory buffer for processing
- */
-extern int git_futils_readbuffer(git_buf *obj, const char *path);
-extern int git_futils_readbuffer_updated(
-	git_buf *obj, const char *path, git_oid *checksum, int *updated);
-extern int git_futils_readbuffer_fd(git_buf *obj, git_file fd, size_t len);
-
-/* Additional constants for `git_futils_writebuffer`'s `open_flags`.  We
- * support these internally and they will be removed before the `open` call.
- */
-#ifndef O_FSYNC
-# define O_FSYNC (1 << 31)
-#endif
-
-extern int git_futils_writebuffer(
-	const git_buf *buf, const char *path, int open_flags, mode_t mode);
-
-/**
- * File utils
- *
- * These are custom filesystem-related helper methods. They are
- * rather high level, and wrap the underlying POSIX methods
- *
- * All these methods return 0 on success,
- * or an error code on failure and an error message is set.
- */
-
-/**
- * Create and open a file, while also
- * creating all the folders in its path
- */
-extern int git_futils_creat_withpath(const char *path, const mode_t dirmode, const mode_t mode);
-
-/**
- * Create and open a process-locked file
- */
-extern int git_futils_creat_locked(const char *path, const mode_t mode);
-
-/**
- * Create and open a process-locked file, while
- * also creating all the folders in its path
- */
-extern int git_futils_creat_locked_withpath(const char *path, const mode_t dirmode, const mode_t mode);
-
-/**
- * Create a path recursively.
- */
-extern int git_futils_mkdir_r(const char *path, const mode_t mode);
-
-/**
- * Flags to pass to `git_futils_mkdir`.
- *
- * * GIT_MKDIR_EXCL is "exclusive" - i.e. generate an error if dir exists.
- * * GIT_MKDIR_PATH says to make all components in the path.
- * * GIT_MKDIR_CHMOD says to chmod the final directory entry after creation
- * * GIT_MKDIR_CHMOD_PATH says to chmod each directory component in the path
- * * GIT_MKDIR_SKIP_LAST says to leave off the last element of the path
- * * GIT_MKDIR_SKIP_LAST2 says to leave off the last 2 elements of the path
- * * GIT_MKDIR_VERIFY_DIR says confirm final item is a dir, not just EEXIST
- * * GIT_MKDIR_REMOVE_FILES says to remove files and recreate dirs
- * * GIT_MKDIR_REMOVE_SYMLINKS says to remove symlinks and recreate dirs
- *
- * Note that the chmod options will be executed even if the directory already
- * exists, unless GIT_MKDIR_EXCL is given.
- */
-typedef enum {
-	GIT_MKDIR_EXCL = 1,
-	GIT_MKDIR_PATH = 2,
-	GIT_MKDIR_CHMOD = 4,
-	GIT_MKDIR_CHMOD_PATH = 8,
-	GIT_MKDIR_SKIP_LAST = 16,
-	GIT_MKDIR_SKIP_LAST2 = 32,
-	GIT_MKDIR_VERIFY_DIR = 64,
-	GIT_MKDIR_REMOVE_FILES = 128,
-	GIT_MKDIR_REMOVE_SYMLINKS = 256,
-} git_futils_mkdir_flags;
-
-struct git_futils_mkdir_perfdata
-{
-	size_t stat_calls;
-	size_t mkdir_calls;
-	size_t chmod_calls;
-};
-
-struct git_futils_mkdir_options
-{
-	git_strmap *dir_map;
-	git_pool *pool;
-	struct git_futils_mkdir_perfdata perfdata;
-};
-
-/**
- * Create a directory or entire path.
- *
- * This makes a directory (and the entire path leading up to it if requested),
- * and optionally chmods the directory immediately after (or each part of the
- * path if requested).
- *
- * @param path The path to create, relative to base.
- * @param base Root for relative path.  These directories will never be made.
- * @param mode The mode to use for created directories.
- * @param flags Combination of the mkdir flags above.
- * @param opts Extended options, or null.
- * @return 0 on success, else error code
- */
-extern int git_futils_mkdir_relative(const char *path, const char *base, mode_t mode, uint32_t flags, struct git_futils_mkdir_options *opts);
-
-/**
- * Create a directory or entire path.  Similar to `git_futils_mkdir_relative`
- * without performance data.
- */
-extern int git_futils_mkdir(const char *path, mode_t mode, uint32_t flags);
-
-/**
- * Create all the folders required to contain
- * the full path of a file
- */
-extern int git_futils_mkpath2file(const char *path, const mode_t mode);
-
-/**
- * Flags to pass to `git_futils_rmdir_r`.
- *
- * * GIT_RMDIR_EMPTY_HIERARCHY - the default; remove hierarchy of empty
- *       dirs and generate error if any files are found.
- * * GIT_RMDIR_REMOVE_FILES    - attempt to remove files in the hierarchy.
- * * GIT_RMDIR_SKIP_NONEMPTY   - skip non-empty directories with no error.
- * * GIT_RMDIR_EMPTY_PARENTS   - remove containing directories up to base
- *       if removing this item leaves them empty
- * * GIT_RMDIR_REMOVE_BLOCKERS - remove blocking file that causes ENOTDIR
- * * GIT_RMDIR_SKIP_ROOT       - don't remove root directory itself
- */
-typedef enum {
-	GIT_RMDIR_EMPTY_HIERARCHY = 0,
-	GIT_RMDIR_REMOVE_FILES    = (1 << 0),
-	GIT_RMDIR_SKIP_NONEMPTY   = (1 << 1),
-	GIT_RMDIR_EMPTY_PARENTS   = (1 << 2),
-	GIT_RMDIR_REMOVE_BLOCKERS = (1 << 3),
-	GIT_RMDIR_SKIP_ROOT       = (1 << 4),
-} git_futils_rmdir_flags;
-
-/**
- * Remove path and any files and directories beneath it.
- *
- * @param path Path to the top level directory to process.
- * @param base Root for relative path.
- * @param flags Combination of git_futils_rmdir_flags values
- * @return 0 on success; -1 on error.
- */
-extern int git_futils_rmdir_r(const char *path, const char *base, uint32_t flags);
-
-/**
- * Create and open a temporary file with a `_git2_` suffix.
- * Writes the filename into path_out.
- * @return On success, an open file descriptor, else an error code < 0.
- */
-extern int git_futils_mktmp(git_buf *path_out, const char *filename, mode_t mode);
-
-/**
- * Move a file on the filesystem, create the
- * destination path if it doesn't exist
- */
-extern int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmode);
-
-/**
- * Copy a file
- *
- * The filemode will be used for the newly created file.
- */
-extern int git_futils_cp(
-	const char *from,
-	const char *to,
-	mode_t filemode);
-
-/**
- * Set the files atime and mtime to the given time, or the current time
- * if `ts` is NULL.
- */
-extern int git_futils_touch(const char *path, time_t *when);
-
-/**
- * Flags that can be passed to `git_futils_cp_r`.
- *
- * - GIT_CPDIR_CREATE_EMPTY_DIRS: create directories even if there are no
- *   files under them (otherwise directories will only be created lazily
- *   when a file inside them is copied).
- * - GIT_CPDIR_COPY_SYMLINKS: copy symlinks, otherwise they are ignored.
- * - GIT_CPDIR_COPY_DOTFILES: copy files with leading '.', otherwise ignored.
- * - GIT_CPDIR_OVERWRITE: overwrite pre-existing files with source content,
- *   otherwise they are silently skipped.
- * - GIT_CPDIR_CHMOD_DIRS: explicitly chmod directories to `dirmode`
- * - GIT_CPDIR_SIMPLE_TO_MODE: default tries to replicate the mode of the
- *   source file to the target; with this flag, always use 0666 (or 0777 if
- *   source has exec bits set) for target.
- * - GIT_CPDIR_LINK_FILES will try to use hardlinks for the files
- */
-typedef enum {
-	GIT_CPDIR_CREATE_EMPTY_DIRS = (1u << 0),
-	GIT_CPDIR_COPY_SYMLINKS     = (1u << 1),
-	GIT_CPDIR_COPY_DOTFILES     = (1u << 2),
-	GIT_CPDIR_OVERWRITE         = (1u << 3),
-	GIT_CPDIR_CHMOD_DIRS        = (1u << 4),
-	GIT_CPDIR_SIMPLE_TO_MODE    = (1u << 5),
-	GIT_CPDIR_LINK_FILES        = (1u << 6),
-} git_futils_cpdir_flags;
-
-/**
- * Copy a directory tree.
- *
- * This copies directories and files from one root to another.  You can
- * pass a combinationof GIT_CPDIR flags as defined above.
- *
- * If you pass the CHMOD flag, then the dirmode will be applied to all
- * directories that are created during the copy, overiding the natural
- * permissions.  If you do not pass the CHMOD flag, then the dirmode
- * will actually be copied from the source files and the `dirmode` arg
- * will be ignored.
- */
-extern int git_futils_cp_r(
-	const char *from,
-	const char *to,
-	uint32_t flags,
-	mode_t dirmode);
-
-/**
- * Open a file readonly and set error if needed.
- */
-extern int git_futils_open_ro(const char *path);
-
-/**
- * Truncate a file, creating it if it doesn't exist.
- */
-extern int git_futils_truncate(const char *path, int mode);
-
-/**
- * Get the filesize in bytes of a file
- */
-extern git_off_t git_futils_filesize(git_file fd);
-
-#define GIT_PERMS_IS_EXEC(MODE)		(((MODE) & 0111) != 0)
-#define GIT_PERMS_CANONICAL(MODE)	(GIT_PERMS_IS_EXEC(MODE) ? 0755 : 0644)
-#define GIT_PERMS_FOR_WRITE(MODE)   (GIT_PERMS_IS_EXEC(MODE) ? 0777 : 0666)
-
-#define GIT_MODE_PERMS_MASK			0777
-#define GIT_MODE_TYPE_MASK			0170000
-#define GIT_MODE_TYPE(MODE)			((MODE) & GIT_MODE_TYPE_MASK)
-#define GIT_MODE_ISBLOB(MODE)		(GIT_MODE_TYPE(MODE) == GIT_MODE_TYPE(GIT_FILEMODE_BLOB))
-
-/**
- * Convert a mode_t from the OS to a legal git mode_t value.
- */
-extern mode_t git_futils_canonical_mode(mode_t raw_mode);
-
-
-/**
- * Read-only map all or part of a file into memory.
- * When possible this function should favor a virtual memory
- * style mapping over some form of malloc()+read(), as the
- * data access will be random and is not likely to touch the
- * majority of the region requested.
- *
- * @param out buffer to populate with the mapping information.
- * @param fd open descriptor to configure the mapping from.
- * @param begin first byte to map, this should be page aligned.
- * @param len number of bytes to map.
- * @return
- * - 0 on success;
- * - -1 on error.
- */
-extern int git_futils_mmap_ro(
-	git_map *out,
-	git_file fd,
-	git_off_t begin,
-	size_t len);
-
-/**
- * Read-only map an entire file.
- *
- * @param out buffer to populate with the mapping information.
- * @param path path to file to be opened.
- * @return
- * - 0 on success;
- * - GIT_ENOTFOUND if not found;
- * - -1 on an unspecified OS related error.
- */
-extern int git_futils_mmap_ro_file(
-	git_map *out,
-	const char *path);
-
-/**
- * Release the memory associated with a previous memory mapping.
- * @param map the mapping description previously configured.
- */
-extern void git_futils_mmap_free(git_map *map);
-
-/**
- * Create a "fake" symlink (text file containing the target path).
- *
- * @param new symlink file to be created
- * @param old original symlink target
- * @return 0 on success, -1 on error
- */
-extern int git_futils_fake_symlink(const char *new, const char *old);
-
-/**
- * A file stamp represents a snapshot of information about a file that can
- * be used to test if the file changes.  This portable implementation is
- * based on stat data about that file, but it is possible that OS specific
- * versions could be implemented in the future.
- */
-typedef struct {
-	struct timespec mtime;
-	git_off_t  size;
-	unsigned int ino;
-} git_futils_filestamp;
-
-/**
- * Compare stat information for file with reference info.
- *
- * This function updates the file stamp to current data for the given path
- * and returns 0 if the file is up-to-date relative to the prior setting,
- * 1 if the file has been changed, or GIT_ENOTFOUND if the file doesn't
- * exist.  This will not call git_error_set, so you must set the error if you
- * plan to return an error.
- *
- * @param stamp File stamp to be checked
- * @param path Path to stat and check if changed
- * @return 0 if up-to-date, 1 if out-of-date, GIT_ENOTFOUND if cannot stat
- */
-extern int git_futils_filestamp_check(
-	git_futils_filestamp *stamp, const char *path);
-
-/**
- * Set or reset file stamp data
- *
- * This writes the target file stamp.  If the source is NULL, this will set
- * the target stamp to values that will definitely be out of date.  If the
- * source is not NULL, this copies the source values to the target.
- *
- * @param tgt File stamp to write to
- * @param src File stamp to copy from or NULL to clear the target
- */
-extern void git_futils_filestamp_set(
-	git_futils_filestamp *tgt, const git_futils_filestamp *src);
-
-/**
- * Set file stamp data from stat structure
- */
-extern void git_futils_filestamp_set_from_stat(
-	git_futils_filestamp *stamp, struct stat *st);
-
-/**
- * `fsync` the parent directory of the given path, if `fsync` is
- * supported for directories on this platform.
- *
- * @param path Path of the directory to sync.
- * @return 0 on success, -1 on error
- */
-extern int git_futils_fsync_dir(const char *path);
-
-/**
- * `fsync` the parent directory of the given path, if `fsync` is
- * supported for directories on this platform.
- *
- * @param path Path of the file whose parent directory should be synced.
- * @return 0 on success, -1 on error
- */
-extern int git_futils_fsync_parent(const char *path);
-
-#endif
diff --git a/src/filter.c b/src/filter.c
index 34e2dfa..6c929c0 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -8,7 +8,7 @@
 #include "filter.h"
 
 #include "common.h"
-#include "fileops.h"
+#include "futils.h"
 #include "hash.h"
 #include "repository.h"
 #include "global.h"
diff --git a/src/futils.c b/src/futils.c
new file mode 100644
index 0000000..e15c801
--- /dev/null
+++ b/src/futils.c
@@ -0,0 +1,1183 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+
+#include "futils.h"
+
+#include "global.h"
+#include "strmap.h"
+#include <ctype.h>
+#if GIT_WIN32
+#include "win32/findfile.h"
+#endif
+
+int git_futils_mkpath2file(const char *file_path, const mode_t mode)
+{
+	return git_futils_mkdir(
+		file_path, mode,
+		GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR);
+}
+
+int git_futils_mktmp(git_buf *path_out, const char *filename, mode_t mode)
+{
+	int fd;
+	mode_t mask;
+
+	p_umask(mask = p_umask(0));
+
+	git_buf_sets(path_out, filename);
+	git_buf_puts(path_out, "_git2_XXXXXX");
+
+	if (git_buf_oom(path_out))
+		return -1;
+
+	if ((fd = p_mkstemp(path_out->ptr)) < 0) {
+		git_error_set(GIT_ERROR_OS,
+			"failed to create temporary file '%s'", path_out->ptr);
+		return -1;
+	}
+
+	if (p_chmod(path_out->ptr, (mode & ~mask))) {
+		git_error_set(GIT_ERROR_OS,
+			"failed to set permissions on file '%s'", path_out->ptr);
+		return -1;
+	}
+
+	return fd;
+}
+
+int git_futils_creat_withpath(const char *path, const mode_t dirmode, const mode_t mode)
+{
+	int fd;
+
+	if (git_futils_mkpath2file(path, dirmode) < 0)
+		return -1;
+
+	fd = p_creat(path, mode);
+	if (fd < 0) {
+		git_error_set(GIT_ERROR_OS, "failed to create file '%s'", path);
+		return -1;
+	}
+
+	return fd;
+}
+
+int git_futils_creat_locked(const char *path, const mode_t mode)
+{
+	int fd = p_open(path, O_WRONLY | O_CREAT | O_EXCL | O_BINARY | O_CLOEXEC,
+		mode);
+
+	if (fd < 0) {
+		int error = errno;
+		git_error_set(GIT_ERROR_OS, "failed to create locked file '%s'", path);
+		switch (error) {
+		case EEXIST:
+			return GIT_ELOCKED;
+		case ENOENT:
+			return GIT_ENOTFOUND;
+		default:
+			return -1;
+		}
+	}
+
+	return fd;
+}
+
+int git_futils_creat_locked_withpath(const char *path, const mode_t dirmode, const mode_t mode)
+{
+	if (git_futils_mkpath2file(path, dirmode) < 0)
+		return -1;
+
+	return git_futils_creat_locked(path, mode);
+}
+
+int git_futils_open_ro(const char *path)
+{
+	int fd = p_open(path, O_RDONLY);
+	if (fd < 0)
+		return git_path_set_error(errno, path, "open");
+	return fd;
+}
+
+int git_futils_truncate(const char *path, int mode)
+{
+	int fd = p_open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, mode);
+	if (fd < 0)
+		return git_path_set_error(errno, path, "open");
+
+	close(fd);
+	return 0;
+}
+
+git_off_t git_futils_filesize(git_file fd)
+{
+	struct stat sb;
+
+	if (p_fstat(fd, &sb)) {
+		git_error_set(GIT_ERROR_OS, "failed to stat file descriptor");
+		return -1;
+	}
+
+	return sb.st_size;
+}
+
+mode_t git_futils_canonical_mode(mode_t raw_mode)
+{
+	if (S_ISREG(raw_mode))
+		return S_IFREG | GIT_PERMS_CANONICAL(raw_mode);
+	else if (S_ISLNK(raw_mode))
+		return S_IFLNK;
+	else if (S_ISGITLINK(raw_mode))
+		return S_IFGITLINK;
+	else if (S_ISDIR(raw_mode))
+		return S_IFDIR;
+	else
+		return 0;
+}
+
+int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
+{
+	ssize_t read_size = 0;
+	size_t alloc_len;
+
+	git_buf_clear(buf);
+
+	if (!git__is_ssizet(len)) {
+		git_error_set(GIT_ERROR_INVALID, "read too large");
+		return -1;
+	}
+
+	GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, len, 1);
+	if (git_buf_grow(buf, alloc_len) < 0)
+		return -1;
+
+	/* p_read loops internally to read len bytes */
+	read_size = p_read(fd, buf->ptr, len);
+
+	if (read_size != (ssize_t)len) {
+		git_error_set(GIT_ERROR_OS, "failed to read descriptor");
+		git_buf_dispose(buf);
+		return -1;
+	}
+
+	buf->ptr[read_size] = '\0';
+	buf->size = read_size;
+
+	return 0;
+}
+
+int git_futils_readbuffer_updated(
+	git_buf *out, const char *path, git_oid *checksum, int *updated)
+{
+	int error;
+	git_file fd;
+	struct stat st;
+	git_buf buf = GIT_BUF_INIT;
+	git_oid checksum_new;
+
+	assert(out && path && *path);
+
+	if (updated != NULL)
+		*updated = 0;
+
+	if (p_stat(path, &st) < 0)
+		return git_path_set_error(errno, path, "stat");
+
+
+	if (S_ISDIR(st.st_mode)) {
+		git_error_set(GIT_ERROR_INVALID, "requested file is a directory");
+		return GIT_ENOTFOUND;
+	}
+
+	if (!git__is_sizet(st.st_size+1)) {
+		git_error_set(GIT_ERROR_OS, "invalid regular file stat for '%s'", path);
+		return -1;
+	}
+
+	if ((fd = git_futils_open_ro(path)) < 0)
+		return fd;
+
+	if (git_futils_readbuffer_fd(&buf, fd, (size_t)st.st_size) < 0) {
+		p_close(fd);
+		return -1;
+	}
+
+	p_close(fd);
+
+	if (checksum) {
+		if ((error = git_hash_buf(&checksum_new, buf.ptr, buf.size)) < 0) {
+			git_buf_dispose(&buf);
+			return error;
+		}
+
+		/*
+		 * If we were given a checksum, we only want to use it if it's different
+		 */
+		if (!git_oid__cmp(checksum, &checksum_new)) {
+			git_buf_dispose(&buf);
+			if (updated)
+				*updated = 0;
+
+			return 0;
+		}
+
+		git_oid_cpy(checksum, &checksum_new);
+	}
+
+	/*
+	 * If we're here, the file did change, or the user didn't have an old version
+	 */
+	if (updated != NULL)
+		*updated = 1;
+
+	git_buf_swap(out, &buf);
+	git_buf_dispose(&buf);
+
+	return 0;
+}
+
+int git_futils_readbuffer(git_buf *buf, const char *path)
+{
+	return git_futils_readbuffer_updated(buf, path, NULL, NULL);
+}
+
+int git_futils_writebuffer(
+	const git_buf *buf,	const char *path, int flags, mode_t mode)
+{
+	int fd, do_fsync = 0, error = 0;
+
+	if (!flags)
+		flags = O_CREAT | O_TRUNC | O_WRONLY;
+
+	if ((flags & O_FSYNC) != 0)
+		do_fsync = 1;
+
+	flags &= ~O_FSYNC;
+
+	if (!mode)
+		mode = GIT_FILEMODE_BLOB;
+
+	if ((fd = p_open(path, flags, mode)) < 0) {
+		git_error_set(GIT_ERROR_OS, "could not open '%s' for writing", path);
+		return fd;
+	}
+
+	if ((error = p_write(fd, git_buf_cstr(buf), git_buf_len(buf))) < 0) {
+		git_error_set(GIT_ERROR_OS, "could not write to '%s'", path);
+		(void)p_close(fd);
+		return error;
+	}
+
+	if (do_fsync && (error = p_fsync(fd)) < 0) {
+		git_error_set(GIT_ERROR_OS, "could not fsync '%s'", path);
+		p_close(fd);
+		return error;
+	}
+
+	if ((error = p_close(fd)) < 0) {
+		git_error_set(GIT_ERROR_OS, "error while closing '%s'", path);
+		return error;
+	}
+
+	if (do_fsync && (flags & O_CREAT))
+		error = git_futils_fsync_parent(path);
+
+	return error;
+}
+
+int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmode)
+{
+	if (git_futils_mkpath2file(to, dirmode) < 0)
+		return -1;
+
+	if (p_rename(from, to) < 0) {
+		git_error_set(GIT_ERROR_OS, "failed to rename '%s' to '%s'", from, to);
+		return -1;
+	}
+
+	return 0;
+}
+
+int git_futils_mmap_ro(git_map *out, git_file fd, git_off_t begin, size_t len)
+{
+	return p_mmap(out, len, GIT_PROT_READ, GIT_MAP_SHARED, fd, begin);
+}
+
+int git_futils_mmap_ro_file(git_map *out, const char *path)
+{
+	git_file fd = git_futils_open_ro(path);
+	git_off_t len;
+	int result;
+
+	if (fd < 0)
+		return fd;
+
+	if ((len = git_futils_filesize(fd)) < 0) {
+		result = -1;
+		goto out;
+	}
+
+	if (!git__is_sizet(len)) {
+		git_error_set(GIT_ERROR_OS, "file `%s` too large to mmap", path);
+		result = -1;
+		goto out;
+	}
+
+	result = git_futils_mmap_ro(out, fd, 0, (size_t)len);
+out:
+	p_close(fd);
+	return result;
+}
+
+void git_futils_mmap_free(git_map *out)
+{
+	p_munmap(out);
+}
+
+GIT_INLINE(int) mkdir_validate_dir(
+	const char *path,
+	struct stat *st,
+	mode_t mode,
+	uint32_t flags,
+	struct git_futils_mkdir_options *opts)
+{
+	/* with exclusive create, existing dir is an error */
+	if ((flags & GIT_MKDIR_EXCL) != 0) {
+		git_error_set(GIT_ERROR_FILESYSTEM,
+			"failed to make directory '%s': directory exists", path);
+		return GIT_EEXISTS;
+	}
+
+	if ((S_ISREG(st->st_mode) && (flags & GIT_MKDIR_REMOVE_FILES)) ||
+		(S_ISLNK(st->st_mode) && (flags & GIT_MKDIR_REMOVE_SYMLINKS))) {
+		if (p_unlink(path) < 0) {
+			git_error_set(GIT_ERROR_OS, "failed to remove %s '%s'",
+				S_ISLNK(st->st_mode) ? "symlink" : "file", path);
+			return GIT_EEXISTS;
+		}
+
+		opts->perfdata.mkdir_calls++;
+
+		if (p_mkdir(path, mode) < 0) {
+			git_error_set(GIT_ERROR_OS, "failed to make directory '%s'", path);
+			return GIT_EEXISTS;
+		}
+	}
+
+	else if (S_ISLNK(st->st_mode)) {
+		/* Re-stat the target, make sure it's a directory */
+		opts->perfdata.stat_calls++;
+
+		if (p_stat(path, st) < 0) {
+			git_error_set(GIT_ERROR_OS, "failed to make directory '%s'", path);
+			return GIT_EEXISTS;
+		}
+	}
+
+	else if (!S_ISDIR(st->st_mode)) {
+		git_error_set(GIT_ERROR_FILESYSTEM,
+			"failed to make directory '%s': directory exists", path);
+		return GIT_EEXISTS;
+	}
+
+	return 0;
+}
+
+GIT_INLINE(int) mkdir_validate_mode(
+	const char *path,
+	struct stat *st,
+	bool terminal_path,
+	mode_t mode,
+	uint32_t flags,
+	struct git_futils_mkdir_options *opts)
+{
+	if (((terminal_path && (flags & GIT_MKDIR_CHMOD) != 0) ||
+		(flags & GIT_MKDIR_CHMOD_PATH) != 0) && st->st_mode != mode) {
+
+		opts->perfdata.chmod_calls++;
+
+		if (p_chmod(path, mode) < 0) {
+			git_error_set(GIT_ERROR_OS, "failed to set permissions on '%s'", path);
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
+GIT_INLINE(int) mkdir_canonicalize(
+	git_buf *path,
+	uint32_t flags)
+{
+	ssize_t root_len;
+
+	if (path->size == 0) {
+		git_error_set(GIT_ERROR_OS, "attempt to create empty path");
+		return -1;
+	}
+
+	/* Trim trailing slashes (except the root) */
+	if ((root_len = git_path_root(path->ptr)) < 0)
+		root_len = 0;
+	else
+		root_len++;
+
+	while (path->size > (size_t)root_len && path->ptr[path->size - 1] == '/')
+		path->ptr[--path->size] = '\0';
+
+	/* if we are not supposed to made the last element, truncate it */
+	if ((flags & GIT_MKDIR_SKIP_LAST2) != 0) {
+		git_path_dirname_r(path, path->ptr);
+		flags |= GIT_MKDIR_SKIP_LAST;
+	}
+	if ((flags & GIT_MKDIR_SKIP_LAST) != 0) {
+		git_path_dirname_r(path, path->ptr);
+	}
+
+	/* We were either given the root path (or trimmed it to
+	* the root), we don't have anything to do.
+	*/
+	if (path->size <= (size_t)root_len)
+		git_buf_clear(path);
+
+	return 0;
+}
+
+int git_futils_mkdir(
+	const char *path,
+	mode_t mode,
+	uint32_t flags)
+{
+	git_buf make_path = GIT_BUF_INIT, parent_path = GIT_BUF_INIT;
+	const char *relative;
+	struct git_futils_mkdir_options opts = { 0 };
+	struct stat st;
+	size_t depth = 0;
+	int len = 0, root_len, error;
+
+	if ((error = git_buf_puts(&make_path, path)) < 0 ||
+		(error = mkdir_canonicalize(&make_path, flags)) < 0 ||
+		(error = git_buf_puts(&parent_path, make_path.ptr)) < 0 ||
+		make_path.size == 0)
+		goto done;
+
+	root_len = git_path_root(make_path.ptr);
+
+	/* find the first parent directory that exists.  this will be used
+	 * as the base to dirname_relative.
+	 */
+	for (relative = make_path.ptr; parent_path.size; ) {
+		error = p_lstat(parent_path.ptr, &st);
+
+		if (error == 0) {
+			break;
+		} else if (errno != ENOENT) {
+			git_error_set(GIT_ERROR_OS, "failed to stat '%s'", parent_path.ptr);
+			goto done;
+		}
+
+		depth++;
+
+		/* examine the parent of the current path */
+		if ((len = git_path_dirname_r(&parent_path, parent_path.ptr)) < 0) {
+			error = len;
+			goto done;
+		}
+
+		assert(len);
+
+		/*
+		 * We've walked all the given path's parents and it's either relative
+		 * (the parent is simply '.') or rooted (the length is less than or
+		 * equal to length of the root path).  The path may be less than the
+		 * root path length on Windows, where `C:` == `C:/`.
+		 */
+		if ((len == 1 && parent_path.ptr[0] == '.') ||
+		    (len == 1 && parent_path.ptr[0] == '/') ||
+		    len <= root_len) {
+			relative = make_path.ptr;
+			break;
+		}
+
+		relative = make_path.ptr + len + 1;
+
+		/* not recursive? just make this directory relative to its parent. */
+		if ((flags & GIT_MKDIR_PATH) == 0)
+			break;
+	}
+
+	/* we found an item at the location we're trying to create,
+	 * validate it.
+	 */
+	if (depth == 0) {
+		error = mkdir_validate_dir(make_path.ptr, &st, mode, flags, &opts);
+
+		if (!error)
+			error = mkdir_validate_mode(
+				make_path.ptr, &st, true, mode, flags, &opts);
+
+		goto done;
+	}
+
+	/* we already took `SKIP_LAST` and `SKIP_LAST2` into account when
+	 * canonicalizing `make_path`.
+	 */
+	flags &= ~(GIT_MKDIR_SKIP_LAST2 | GIT_MKDIR_SKIP_LAST);
+
+	error = git_futils_mkdir_relative(relative,
+		parent_path.size ? parent_path.ptr : NULL, mode, flags, &opts);
+
+done:
+	git_buf_dispose(&make_path);
+	git_buf_dispose(&parent_path);
+	return error;
+}
+
+int git_futils_mkdir_r(const char *path, const mode_t mode)
+{
+	return git_futils_mkdir(path, mode, GIT_MKDIR_PATH);
+}
+
+int git_futils_mkdir_relative(
+	const char *relative_path,
+	const char *base,
+	mode_t mode,
+	uint32_t flags,
+	struct git_futils_mkdir_options *opts)
+{
+	git_buf make_path = GIT_BUF_INIT;
+	ssize_t root = 0, min_root_len;
+	char lastch = '/', *tail;
+	struct stat st;
+	struct git_futils_mkdir_options empty_opts = {0};
+	int error;
+
+	if (!opts)
+		opts = &empty_opts;
+
+	/* build path and find "root" where we should start calling mkdir */
+	if (git_path_join_unrooted(&make_path, relative_path, base, &root) < 0)
+		return -1;
+
+	if ((error = mkdir_canonicalize(&make_path, flags)) < 0 ||
+		make_path.size == 0)
+		goto done;
+
+	/* if we are not supposed to make the whole path, reset root */
+	if ((flags & GIT_MKDIR_PATH) == 0)
+		root = git_buf_rfind(&make_path, '/');
+
+	/* advance root past drive name or network mount prefix */
+	min_root_len = git_path_root(make_path.ptr);
+	if (root < min_root_len)
+		root = min_root_len;
+	while (root >= 0 && make_path.ptr[root] == '/')
+		++root;
+
+	/* clip root to make_path length */
+	if (root > (ssize_t)make_path.size)
+		root = (ssize_t)make_path.size; /* i.e. NUL byte of string */
+	if (root < 0)
+		root = 0;
+
+	/* walk down tail of path making each directory */
+	for (tail = &make_path.ptr[root]; *tail; *tail = lastch) {
+		bool mkdir_attempted = false;
+
+		/* advance tail to include next path component */
+		while (*tail == '/')
+			tail++;
+		while (*tail && *tail != '/')
+			tail++;
+
+		/* truncate path at next component */
+		lastch = *tail;
+		*tail = '\0';
+		st.st_mode = 0;
+
+		if (opts->dir_map && git_strmap_exists(opts->dir_map, make_path.ptr))
+			continue;
+
+		/* See what's going on with this path component */
+		opts->perfdata.stat_calls++;
+
+retry_lstat:
+		if (p_lstat(make_path.ptr, &st) < 0) {
+			if (mkdir_attempted || errno != ENOENT) {
+				git_error_set(GIT_ERROR_OS, "cannot access component in path '%s'", make_path.ptr);
+				error = -1;
+				goto done;
+			}
+
+			git_error_clear();
+			opts->perfdata.mkdir_calls++;
+			mkdir_attempted = true;
+			if (p_mkdir(make_path.ptr, mode) < 0) {
+				if (errno == EEXIST)
+					goto retry_lstat;
+				git_error_set(GIT_ERROR_OS, "failed to make directory '%s'", make_path.ptr);
+				error = -1;
+				goto done;
+			}
+		} else {
+			if ((error = mkdir_validate_dir(
+				make_path.ptr, &st, mode, flags, opts)) < 0)
+				goto done;
+		}
+
+		/* chmod if requested and necessary */
+		if ((error = mkdir_validate_mode(
+			make_path.ptr, &st, (lastch == '\0'), mode, flags, opts)) < 0)
+			goto done;
+
+		if (opts->dir_map && opts->pool) {
+			char *cache_path;
+			size_t alloc_size;
+
+			GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, make_path.size, 1);
+			cache_path = git_pool_malloc(opts->pool, alloc_size);
+			GIT_ERROR_CHECK_ALLOC(cache_path);
+
+			memcpy(cache_path, make_path.ptr, make_path.size + 1);
+
+			if ((error = git_strmap_set(opts->dir_map, cache_path, cache_path)) < 0)
+				goto done;
+		}
+	}
+
+	error = 0;
+
+	/* check that full path really is a directory if requested & needed */
+	if ((flags & GIT_MKDIR_VERIFY_DIR) != 0 &&
+		lastch != '\0') {
+		opts->perfdata.stat_calls++;
+
+		if (p_stat(make_path.ptr, &st) < 0 || !S_ISDIR(st.st_mode)) {
+			git_error_set(GIT_ERROR_OS, "path is not a directory '%s'",
+				make_path.ptr);
+			error = GIT_ENOTFOUND;
+		}
+	}
+
+done:
+	git_buf_dispose(&make_path);
+	return error;
+}
+
+typedef struct {
+	const char *base;
+	size_t baselen;
+	uint32_t flags;
+	int depth;
+} futils__rmdir_data;
+
+#define FUTILS_MAX_DEPTH 100
+
+static int futils__error_cannot_rmdir(const char *path, const char *filemsg)
+{
+	if (filemsg)
+		git_error_set(GIT_ERROR_OS, "could not remove directory '%s': %s",
+				   path, filemsg);
+	else
+		git_error_set(GIT_ERROR_OS, "could not remove directory '%s'", path);
+
+	return -1;
+}
+
+static int futils__rm_first_parent(git_buf *path, const char *ceiling)
+{
+	int error = GIT_ENOTFOUND;
+	struct stat st;
+
+	while (error == GIT_ENOTFOUND) {
+		git_buf_rtruncate_at_char(path, '/');
+
+		if (!path->size || git__prefixcmp(path->ptr, ceiling) != 0)
+			error = 0;
+		else if (p_lstat_posixly(path->ptr, &st) == 0) {
+			if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))
+				error = p_unlink(path->ptr);
+			else if (!S_ISDIR(st.st_mode))
+				error = -1; /* fail to remove non-regular file */
+		} else if (errno != ENOTDIR)
+			error = -1;
+	}
+
+	if (error)
+		futils__error_cannot_rmdir(path->ptr, "cannot remove parent");
+
+	return error;
+}
+
+static int futils__rmdir_recurs_foreach(void *opaque, git_buf *path)
+{
+	int error = 0;
+	futils__rmdir_data *data = opaque;
+	struct stat st;
+
+	if (data->depth > FUTILS_MAX_DEPTH)
+		error = futils__error_cannot_rmdir(
+			path->ptr, "directory nesting too deep");
+
+	else if ((error = p_lstat_posixly(path->ptr, &st)) < 0) {
+		if (errno == ENOENT)
+			error = 0;
+		else if (errno == ENOTDIR) {
+			/* asked to remove a/b/c/d/e and a/b is a normal file */
+			if ((data->flags & GIT_RMDIR_REMOVE_BLOCKERS) != 0)
+				error = futils__rm_first_parent(path, data->base);
+			else
+				futils__error_cannot_rmdir(
+					path->ptr, "parent is not directory");
+		}
+		else
+			error = git_path_set_error(errno, path->ptr, "rmdir");
+	}
+
+	else if (S_ISDIR(st.st_mode)) {
+		data->depth++;
+
+		error = git_path_direach(path, 0, futils__rmdir_recurs_foreach, data);
+
+		data->depth--;
+
+		if (error < 0)
+			return error;
+
+		if (data->depth == 0 && (data->flags & GIT_RMDIR_SKIP_ROOT) != 0)
+			return error;
+
+		if ((error = p_rmdir(path->ptr)) < 0) {
+			if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) != 0 &&
+				(errno == ENOTEMPTY || errno == EEXIST || errno == EBUSY))
+				error = 0;
+			else
+				error = git_path_set_error(errno, path->ptr, "rmdir");
+		}
+	}
+
+	else if ((data->flags & GIT_RMDIR_REMOVE_FILES) != 0) {
+		if (p_unlink(path->ptr) < 0)
+			error = git_path_set_error(errno, path->ptr, "remove");
+	}
+
+	else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0)
+		error = futils__error_cannot_rmdir(path->ptr, "still present");
+
+	return error;
+}
+
+static int futils__rmdir_empty_parent(void *opaque, const char *path)
+{
+	futils__rmdir_data *data = opaque;
+	int error = 0;
+
+	if (strlen(path) <= data->baselen)
+		error = GIT_ITEROVER;
+
+	else if (p_rmdir(path) < 0) {
+		int en = errno;
+
+		if (en == ENOENT || en == ENOTDIR) {
+			/* do nothing */
+		} else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0 &&
+			en == EBUSY) {
+			error = git_path_set_error(errno, path, "rmdir");
+		} else if (en == ENOTEMPTY || en == EEXIST || en == EBUSY) {
+			error = GIT_ITEROVER;
+		} else {
+			error = git_path_set_error(errno, path, "rmdir");
+		}
+	}
+
+	return error;
+}
+
+int git_futils_rmdir_r(
+	const char *path, const char *base, uint32_t flags)
+{
+	int error;
+	git_buf fullpath = GIT_BUF_INIT;
+	futils__rmdir_data data;
+
+	/* build path and find "root" where we should start calling mkdir */
+	if (git_path_join_unrooted(&fullpath, path, base, NULL) < 0)
+		return -1;
+
+	memset(&data, 0, sizeof(data));
+	data.base    = base ? base : "";
+	data.baselen = base ? strlen(base) : 0;
+	data.flags   = flags;
+
+	error = futils__rmdir_recurs_foreach(&data, &fullpath);
+
+	/* remove now-empty parents if requested */
+	if (!error && (flags & GIT_RMDIR_EMPTY_PARENTS) != 0)
+		error = git_path_walk_up(
+			&fullpath, base, futils__rmdir_empty_parent, &data);
+
+	if (error == GIT_ITEROVER) {
+		git_error_clear();
+		error = 0;
+	}
+
+	git_buf_dispose(&fullpath);
+
+	return error;
+}
+
+int git_futils_fake_symlink(const char *old, const char *new)
+{
+	int retcode = GIT_ERROR;
+	int fd = git_futils_creat_withpath(new, 0755, 0644);
+	if (fd >= 0) {
+		retcode = p_write(fd, old, strlen(old));
+		p_close(fd);
+	}
+	return retcode;
+}
+
+static int cp_by_fd(int ifd, int ofd, bool close_fd_when_done)
+{
+	int error = 0;
+	char buffer[FILEIO_BUFSIZE];
+	ssize_t len = 0;
+
+	while (!error && (len = p_read(ifd, buffer, sizeof(buffer))) > 0)
+		/* p_write() does not have the same semantics as write().  It loops
+		 * internally and will return 0 when it has completed writing.
+		 */
+		error = p_write(ofd, buffer, len);
+
+	if (len < 0) {
+		git_error_set(GIT_ERROR_OS, "read error while copying file");
+		error = (int)len;
+	}
+
+	if (error < 0)
+		git_error_set(GIT_ERROR_OS, "write error while copying file");
+
+	if (close_fd_when_done) {
+		p_close(ifd);
+		p_close(ofd);
+	}
+
+	return error;
+}
+
+int git_futils_cp(const char *from, const char *to, mode_t filemode)
+{
+	int ifd, ofd;
+
+	if ((ifd = git_futils_open_ro(from)) < 0)
+		return ifd;
+
+	if ((ofd = p_open(to, O_WRONLY | O_CREAT | O_EXCL, filemode)) < 0) {
+		p_close(ifd);
+		return git_path_set_error(errno, to, "open for writing");
+	}
+
+	return cp_by_fd(ifd, ofd, true);
+}
+
+int git_futils_touch(const char *path, time_t *when)
+{
+	struct p_timeval times[2];
+	int ret;
+
+	times[0].tv_sec =  times[1].tv_sec  = when ? *when : time(NULL);
+	times[0].tv_usec = times[1].tv_usec = 0;
+
+	ret = p_utimes(path, times);
+
+	return (ret < 0) ? git_path_set_error(errno, path, "touch") : 0;
+}
+
+static int cp_link(const char *from, const char *to, size_t link_size)
+{
+	int error = 0;
+	ssize_t read_len;
+	char *link_data;
+	size_t alloc_size;
+
+	GIT_ERROR_CHECK_ALLOC_ADD(&alloc_size, link_size, 1);
+	link_data = git__malloc(alloc_size);
+	GIT_ERROR_CHECK_ALLOC(link_data);
+
+	read_len = p_readlink(from, link_data, link_size);
+	if (read_len != (ssize_t)link_size) {
+		git_error_set(GIT_ERROR_OS, "failed to read symlink data for '%s'", from);
+		error = -1;
+	}
+	else {
+		link_data[read_len] = '\0';
+
+		if (p_symlink(link_data, to) < 0) {
+			git_error_set(GIT_ERROR_OS, "could not symlink '%s' as '%s'",
+				link_data, to);
+			error = -1;
+		}
+	}
+
+	git__free(link_data);
+	return error;
+}
+
+typedef struct {
+	const char *to_root;
+	git_buf to;
+	ssize_t from_prefix;
+	uint32_t flags;
+	uint32_t mkdir_flags;
+	mode_t dirmode;
+} cp_r_info;
+
+#define GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT (1u << 10)
+
+static int _cp_r_mkdir(cp_r_info *info, git_buf *from)
+{
+	int error = 0;
+
+	/* create root directory the first time we need to create a directory */
+	if ((info->flags & GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT) == 0) {
+		error = git_futils_mkdir(
+			info->to_root, info->dirmode,
+			(info->flags & GIT_CPDIR_CHMOD_DIRS) ? GIT_MKDIR_CHMOD : 0);
+
+		info->flags |= GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT;
+	}
+
+	/* create directory with root as base to prevent excess chmods */
+	if (!error)
+		error = git_futils_mkdir_relative(
+			from->ptr + info->from_prefix, info->to_root,
+			info->dirmode, info->mkdir_flags, NULL);
+
+	return error;
+}
+
+static int _cp_r_callback(void *ref, git_buf *from)
+{
+	int error = 0;
+	cp_r_info *info = ref;
+	struct stat from_st, to_st;
+	bool exists = false;
+
+	if ((info->flags & GIT_CPDIR_COPY_DOTFILES) == 0 &&
+		from->ptr[git_path_basename_offset(from)] == '.')
+		return 0;
+
+	if ((error = git_buf_joinpath(
+			&info->to, info->to_root, from->ptr + info->from_prefix)) < 0)
+		return error;
+
+	if (!(error = git_path_lstat(info->to.ptr, &to_st)))
+		exists = true;
+	else if (error != GIT_ENOTFOUND)
+		return error;
+	else {
+		git_error_clear();
+		error = 0;
+	}
+
+	if ((error = git_path_lstat(from->ptr, &from_st)) < 0)
+		return error;
+
+	if (S_ISDIR(from_st.st_mode)) {
+		mode_t oldmode = info->dirmode;
+
+		/* if we are not chmod'ing, then overwrite dirmode */
+		if ((info->flags & GIT_CPDIR_CHMOD_DIRS) == 0)
+			info->dirmode = from_st.st_mode;
+
+		/* make directory now if CREATE_EMPTY_DIRS is requested and needed */
+		if (!exists && (info->flags & GIT_CPDIR_CREATE_EMPTY_DIRS) != 0)
+			error = _cp_r_mkdir(info, from);
+
+		/* recurse onto target directory */
+		if (!error && (!exists || S_ISDIR(to_st.st_mode)))
+			error = git_path_direach(from, 0, _cp_r_callback, info);
+
+		if (oldmode != 0)
+			info->dirmode = oldmode;
+
+		return error;
+	}
+
+	if (exists) {
+		if ((info->flags & GIT_CPDIR_OVERWRITE) == 0)
+			return 0;
+
+		if (p_unlink(info->to.ptr) < 0) {
+			git_error_set(GIT_ERROR_OS, "cannot overwrite existing file '%s'",
+				info->to.ptr);
+			return GIT_EEXISTS;
+		}
+	}
+
+	/* Done if this isn't a regular file or a symlink */
+	if (!S_ISREG(from_st.st_mode) &&
+		(!S_ISLNK(from_st.st_mode) ||
+		 (info->flags & GIT_CPDIR_COPY_SYMLINKS) == 0))
+		return 0;
+
+	/* Make container directory on demand if needed */
+	if ((info->flags & GIT_CPDIR_CREATE_EMPTY_DIRS) == 0 &&
+		(error = _cp_r_mkdir(info, from)) < 0)
+		return error;
+
+	/* make symlink or regular file */
+	if (info->flags & GIT_CPDIR_LINK_FILES) {
+		if ((error = p_link(from->ptr, info->to.ptr)) < 0)
+			git_error_set(GIT_ERROR_OS, "failed to link '%s'", from->ptr);
+	} else if (S_ISLNK(from_st.st_mode)) {
+		error = cp_link(from->ptr, info->to.ptr, (size_t)from_st.st_size);
+	} else {
+		mode_t usemode = from_st.st_mode;
+
+		if ((info->flags & GIT_CPDIR_SIMPLE_TO_MODE) != 0)
+			usemode = GIT_PERMS_FOR_WRITE(usemode);
+
+		error = git_futils_cp(from->ptr, info->to.ptr, usemode);
+	}
+
+	return error;
+}
+
+int git_futils_cp_r(
+	const char *from,
+	const char *to,
+	uint32_t flags,
+	mode_t dirmode)
+{
+	int error;
+	git_buf path = GIT_BUF_INIT;
+	cp_r_info info;
+
+	if (git_buf_joinpath(&path, from, "") < 0) /* ensure trailing slash */
+		return -1;
+
+	memset(&info, 0, sizeof(info));
+	info.to_root = to;
+	info.flags   = flags;
+	info.dirmode = dirmode;
+	info.from_prefix = path.size;
+	git_buf_init(&info.to, 0);
+
+	/* precalculate mkdir flags */
+	if ((flags & GIT_CPDIR_CREATE_EMPTY_DIRS) == 0) {
+		/* if not creating empty dirs, then use mkdir to create the path on
+		 * demand right before files are copied.
+		 */
+		info.mkdir_flags = GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST;
+		if ((flags & GIT_CPDIR_CHMOD_DIRS) != 0)
+			info.mkdir_flags |= GIT_MKDIR_CHMOD_PATH;
+	} else {
+		/* otherwise, we will do simple mkdir as directories are encountered */
+		info.mkdir_flags =
+			((flags & GIT_CPDIR_CHMOD_DIRS) != 0) ? GIT_MKDIR_CHMOD : 0;
+	}
+
+	error = _cp_r_callback(&info, &path);
+
+	git_buf_dispose(&path);
+	git_buf_dispose(&info.to);
+
+	return error;
+}
+
+int git_futils_filestamp_check(
+	git_futils_filestamp *stamp, const char *path)
+{
+	struct stat st;
+
+	/* if the stamp is NULL, then always reload */
+	if (stamp == NULL)
+		return 1;
+
+	if (p_stat(path, &st) < 0)
+		return GIT_ENOTFOUND;
+
+	if (stamp->mtime.tv_sec == st.st_mtime &&
+#if defined(GIT_USE_NSEC)
+		stamp->mtime.tv_nsec == st.st_mtime_nsec &&
+#endif
+		stamp->size  == (git_off_t)st.st_size   &&
+		stamp->ino   == (unsigned int)st.st_ino)
+		return 0;
+
+	stamp->mtime.tv_sec = st.st_mtime;
+#if defined(GIT_USE_NSEC)
+	stamp->mtime.tv_nsec = st.st_mtime_nsec;
+#endif
+	stamp->size  = (git_off_t)st.st_size;
+	stamp->ino   = (unsigned int)st.st_ino;
+
+	return 1;
+}
+
+void git_futils_filestamp_set(
+	git_futils_filestamp *target, const git_futils_filestamp *source)
+{
+	assert(target);
+
+	if (source)
+		memcpy(target, source, sizeof(*target));
+	else
+		memset(target, 0, sizeof(*target));
+}
+
+
+void git_futils_filestamp_set_from_stat(
+	git_futils_filestamp *stamp, struct stat *st)
+{
+	if (st) {
+		stamp->mtime.tv_sec = st->st_mtime;
+#if defined(GIT_USE_NSEC)
+		stamp->mtime.tv_nsec = st->st_mtime_nsec;
+#else
+		stamp->mtime.tv_nsec = 0;
+#endif
+		stamp->size  = (git_off_t)st->st_size;
+		stamp->ino   = (unsigned int)st->st_ino;
+	} else {
+		memset(stamp, 0, sizeof(*stamp));
+	}
+}
+
+int git_futils_fsync_dir(const char *path)
+{
+#ifdef GIT_WIN32
+	GIT_UNUSED(path);
+	return 0;
+#else
+	int fd, error = -1;
+
+	if ((fd = p_open(path, O_RDONLY)) < 0) {
+		git_error_set(GIT_ERROR_OS, "failed to open directory '%s' for fsync", path);
+		return -1;
+	}
+
+	if ((error = p_fsync(fd)) < 0)
+		git_error_set(GIT_ERROR_OS, "failed to fsync directory '%s'", path);
+
+	p_close(fd);
+	return error;
+#endif
+}
+
+int git_futils_fsync_parent(const char *path)
+{
+	char *parent;
+	int error;
+
+	if ((parent = git_path_dirname(path)) == NULL)
+		return -1;
+
+	error = git_futils_fsync_dir(parent);
+	git__free(parent);
+	return error;
+}
diff --git a/src/futils.h b/src/futils.h
new file mode 100644
index 0000000..1e2d3f9
--- /dev/null
+++ b/src/futils.h
@@ -0,0 +1,390 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_futils_h__
+#define INCLUDE_futils_h__
+
+#include "common.h"
+
+#include "map.h"
+#include "posix.h"
+#include "path.h"
+#include "pool.h"
+#include "strmap.h"
+#include "oid.h"
+
+/**
+ * Filebuffer methods
+ *
+ * Read whole files into an in-memory buffer for processing
+ */
+extern int git_futils_readbuffer(git_buf *obj, const char *path);
+extern int git_futils_readbuffer_updated(
+	git_buf *obj, const char *path, git_oid *checksum, int *updated);
+extern int git_futils_readbuffer_fd(git_buf *obj, git_file fd, size_t len);
+
+/* Additional constants for `git_futils_writebuffer`'s `open_flags`.  We
+ * support these internally and they will be removed before the `open` call.
+ */
+#ifndef O_FSYNC
+# define O_FSYNC (1 << 31)
+#endif
+
+extern int git_futils_writebuffer(
+	const git_buf *buf, const char *path, int open_flags, mode_t mode);
+
+/**
+ * File utils
+ *
+ * These are custom filesystem-related helper methods. They are
+ * rather high level, and wrap the underlying POSIX methods
+ *
+ * All these methods return 0 on success,
+ * or an error code on failure and an error message is set.
+ */
+
+/**
+ * Create and open a file, while also
+ * creating all the folders in its path
+ */
+extern int git_futils_creat_withpath(const char *path, const mode_t dirmode, const mode_t mode);
+
+/**
+ * Create and open a process-locked file
+ */
+extern int git_futils_creat_locked(const char *path, const mode_t mode);
+
+/**
+ * Create and open a process-locked file, while
+ * also creating all the folders in its path
+ */
+extern int git_futils_creat_locked_withpath(const char *path, const mode_t dirmode, const mode_t mode);
+
+/**
+ * Create a path recursively.
+ */
+extern int git_futils_mkdir_r(const char *path, const mode_t mode);
+
+/**
+ * Flags to pass to `git_futils_mkdir`.
+ *
+ * * GIT_MKDIR_EXCL is "exclusive" - i.e. generate an error if dir exists.
+ * * GIT_MKDIR_PATH says to make all components in the path.
+ * * GIT_MKDIR_CHMOD says to chmod the final directory entry after creation
+ * * GIT_MKDIR_CHMOD_PATH says to chmod each directory component in the path
+ * * GIT_MKDIR_SKIP_LAST says to leave off the last element of the path
+ * * GIT_MKDIR_SKIP_LAST2 says to leave off the last 2 elements of the path
+ * * GIT_MKDIR_VERIFY_DIR says confirm final item is a dir, not just EEXIST
+ * * GIT_MKDIR_REMOVE_FILES says to remove files and recreate dirs
+ * * GIT_MKDIR_REMOVE_SYMLINKS says to remove symlinks and recreate dirs
+ *
+ * Note that the chmod options will be executed even if the directory already
+ * exists, unless GIT_MKDIR_EXCL is given.
+ */
+typedef enum {
+	GIT_MKDIR_EXCL = 1,
+	GIT_MKDIR_PATH = 2,
+	GIT_MKDIR_CHMOD = 4,
+	GIT_MKDIR_CHMOD_PATH = 8,
+	GIT_MKDIR_SKIP_LAST = 16,
+	GIT_MKDIR_SKIP_LAST2 = 32,
+	GIT_MKDIR_VERIFY_DIR = 64,
+	GIT_MKDIR_REMOVE_FILES = 128,
+	GIT_MKDIR_REMOVE_SYMLINKS = 256,
+} git_futils_mkdir_flags;
+
+struct git_futils_mkdir_perfdata
+{
+	size_t stat_calls;
+	size_t mkdir_calls;
+	size_t chmod_calls;
+};
+
+struct git_futils_mkdir_options
+{
+	git_strmap *dir_map;
+	git_pool *pool;
+	struct git_futils_mkdir_perfdata perfdata;
+};
+
+/**
+ * Create a directory or entire path.
+ *
+ * This makes a directory (and the entire path leading up to it if requested),
+ * and optionally chmods the directory immediately after (or each part of the
+ * path if requested).
+ *
+ * @param path The path to create, relative to base.
+ * @param base Root for relative path.  These directories will never be made.
+ * @param mode The mode to use for created directories.
+ * @param flags Combination of the mkdir flags above.
+ * @param opts Extended options, or null.
+ * @return 0 on success, else error code
+ */
+extern int git_futils_mkdir_relative(const char *path, const char *base, mode_t mode, uint32_t flags, struct git_futils_mkdir_options *opts);
+
+/**
+ * Create a directory or entire path.  Similar to `git_futils_mkdir_relative`
+ * without performance data.
+ */
+extern int git_futils_mkdir(const char *path, mode_t mode, uint32_t flags);
+
+/**
+ * Create all the folders required to contain
+ * the full path of a file
+ */
+extern int git_futils_mkpath2file(const char *path, const mode_t mode);
+
+/**
+ * Flags to pass to `git_futils_rmdir_r`.
+ *
+ * * GIT_RMDIR_EMPTY_HIERARCHY - the default; remove hierarchy of empty
+ *       dirs and generate error if any files are found.
+ * * GIT_RMDIR_REMOVE_FILES    - attempt to remove files in the hierarchy.
+ * * GIT_RMDIR_SKIP_NONEMPTY   - skip non-empty directories with no error.
+ * * GIT_RMDIR_EMPTY_PARENTS   - remove containing directories up to base
+ *       if removing this item leaves them empty
+ * * GIT_RMDIR_REMOVE_BLOCKERS - remove blocking file that causes ENOTDIR
+ * * GIT_RMDIR_SKIP_ROOT       - don't remove root directory itself
+ */
+typedef enum {
+	GIT_RMDIR_EMPTY_HIERARCHY = 0,
+	GIT_RMDIR_REMOVE_FILES    = (1 << 0),
+	GIT_RMDIR_SKIP_NONEMPTY   = (1 << 1),
+	GIT_RMDIR_EMPTY_PARENTS   = (1 << 2),
+	GIT_RMDIR_REMOVE_BLOCKERS = (1 << 3),
+	GIT_RMDIR_SKIP_ROOT       = (1 << 4),
+} git_futils_rmdir_flags;
+
+/**
+ * Remove path and any files and directories beneath it.
+ *
+ * @param path Path to the top level directory to process.
+ * @param base Root for relative path.
+ * @param flags Combination of git_futils_rmdir_flags values
+ * @return 0 on success; -1 on error.
+ */
+extern int git_futils_rmdir_r(const char *path, const char *base, uint32_t flags);
+
+/**
+ * Create and open a temporary file with a `_git2_` suffix.
+ * Writes the filename into path_out.
+ * @return On success, an open file descriptor, else an error code < 0.
+ */
+extern int git_futils_mktmp(git_buf *path_out, const char *filename, mode_t mode);
+
+/**
+ * Move a file on the filesystem, create the
+ * destination path if it doesn't exist
+ */
+extern int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmode);
+
+/**
+ * Copy a file
+ *
+ * The filemode will be used for the newly created file.
+ */
+extern int git_futils_cp(
+	const char *from,
+	const char *to,
+	mode_t filemode);
+
+/**
+ * Set the files atime and mtime to the given time, or the current time
+ * if `ts` is NULL.
+ */
+extern int git_futils_touch(const char *path, time_t *when);
+
+/**
+ * Flags that can be passed to `git_futils_cp_r`.
+ *
+ * - GIT_CPDIR_CREATE_EMPTY_DIRS: create directories even if there are no
+ *   files under them (otherwise directories will only be created lazily
+ *   when a file inside them is copied).
+ * - GIT_CPDIR_COPY_SYMLINKS: copy symlinks, otherwise they are ignored.
+ * - GIT_CPDIR_COPY_DOTFILES: copy files with leading '.', otherwise ignored.
+ * - GIT_CPDIR_OVERWRITE: overwrite pre-existing files with source content,
+ *   otherwise they are silently skipped.
+ * - GIT_CPDIR_CHMOD_DIRS: explicitly chmod directories to `dirmode`
+ * - GIT_CPDIR_SIMPLE_TO_MODE: default tries to replicate the mode of the
+ *   source file to the target; with this flag, always use 0666 (or 0777 if
+ *   source has exec bits set) for target.
+ * - GIT_CPDIR_LINK_FILES will try to use hardlinks for the files
+ */
+typedef enum {
+	GIT_CPDIR_CREATE_EMPTY_DIRS = (1u << 0),
+	GIT_CPDIR_COPY_SYMLINKS     = (1u << 1),
+	GIT_CPDIR_COPY_DOTFILES     = (1u << 2),
+	GIT_CPDIR_OVERWRITE         = (1u << 3),
+	GIT_CPDIR_CHMOD_DIRS        = (1u << 4),
+	GIT_CPDIR_SIMPLE_TO_MODE    = (1u << 5),
+	GIT_CPDIR_LINK_FILES        = (1u << 6),
+} git_futils_cpdir_flags;
+
+/**
+ * Copy a directory tree.
+ *
+ * This copies directories and files from one root to another.  You can
+ * pass a combinationof GIT_CPDIR flags as defined above.
+ *
+ * If you pass the CHMOD flag, then the dirmode will be applied to all
+ * directories that are created during the copy, overiding the natural
+ * permissions.  If you do not pass the CHMOD flag, then the dirmode
+ * will actually be copied from the source files and the `dirmode` arg
+ * will be ignored.
+ */
+extern int git_futils_cp_r(
+	const char *from,
+	const char *to,
+	uint32_t flags,
+	mode_t dirmode);
+
+/**
+ * Open a file readonly and set error if needed.
+ */
+extern int git_futils_open_ro(const char *path);
+
+/**
+ * Truncate a file, creating it if it doesn't exist.
+ */
+extern int git_futils_truncate(const char *path, int mode);
+
+/**
+ * Get the filesize in bytes of a file
+ */
+extern git_off_t git_futils_filesize(git_file fd);
+
+#define GIT_PERMS_IS_EXEC(MODE)		(((MODE) & 0111) != 0)
+#define GIT_PERMS_CANONICAL(MODE)	(GIT_PERMS_IS_EXEC(MODE) ? 0755 : 0644)
+#define GIT_PERMS_FOR_WRITE(MODE)   (GIT_PERMS_IS_EXEC(MODE) ? 0777 : 0666)
+
+#define GIT_MODE_PERMS_MASK			0777
+#define GIT_MODE_TYPE_MASK			0170000
+#define GIT_MODE_TYPE(MODE)			((MODE) & GIT_MODE_TYPE_MASK)
+#define GIT_MODE_ISBLOB(MODE)		(GIT_MODE_TYPE(MODE) == GIT_MODE_TYPE(GIT_FILEMODE_BLOB))
+
+/**
+ * Convert a mode_t from the OS to a legal git mode_t value.
+ */
+extern mode_t git_futils_canonical_mode(mode_t raw_mode);
+
+
+/**
+ * Read-only map all or part of a file into memory.
+ * When possible this function should favor a virtual memory
+ * style mapping over some form of malloc()+read(), as the
+ * data access will be random and is not likely to touch the
+ * majority of the region requested.
+ *
+ * @param out buffer to populate with the mapping information.
+ * @param fd open descriptor to configure the mapping from.
+ * @param begin first byte to map, this should be page aligned.
+ * @param len number of bytes to map.
+ * @return
+ * - 0 on success;
+ * - -1 on error.
+ */
+extern int git_futils_mmap_ro(
+	git_map *out,
+	git_file fd,
+	git_off_t begin,
+	size_t len);
+
+/**
+ * Read-only map an entire file.
+ *
+ * @param out buffer to populate with the mapping information.
+ * @param path path to file to be opened.
+ * @return
+ * - 0 on success;
+ * - GIT_ENOTFOUND if not found;
+ * - -1 on an unspecified OS related error.
+ */
+extern int git_futils_mmap_ro_file(
+	git_map *out,
+	const char *path);
+
+/**
+ * Release the memory associated with a previous memory mapping.
+ * @param map the mapping description previously configured.
+ */
+extern void git_futils_mmap_free(git_map *map);
+
+/**
+ * Create a "fake" symlink (text file containing the target path).
+ *
+ * @param new symlink file to be created
+ * @param old original symlink target
+ * @return 0 on success, -1 on error
+ */
+extern int git_futils_fake_symlink(const char *new, const char *old);
+
+/**
+ * A file stamp represents a snapshot of information about a file that can
+ * be used to test if the file changes.  This portable implementation is
+ * based on stat data about that file, but it is possible that OS specific
+ * versions could be implemented in the future.
+ */
+typedef struct {
+	struct timespec mtime;
+	git_off_t  size;
+	unsigned int ino;
+} git_futils_filestamp;
+
+/**
+ * Compare stat information for file with reference info.
+ *
+ * This function updates the file stamp to current data for the given path
+ * and returns 0 if the file is up-to-date relative to the prior setting,
+ * 1 if the file has been changed, or GIT_ENOTFOUND if the file doesn't
+ * exist.  This will not call git_error_set, so you must set the error if you
+ * plan to return an error.
+ *
+ * @param stamp File stamp to be checked
+ * @param path Path to stat and check if changed
+ * @return 0 if up-to-date, 1 if out-of-date, GIT_ENOTFOUND if cannot stat
+ */
+extern int git_futils_filestamp_check(
+	git_futils_filestamp *stamp, const char *path);
+
+/**
+ * Set or reset file stamp data
+ *
+ * This writes the target file stamp.  If the source is NULL, this will set
+ * the target stamp to values that will definitely be out of date.  If the
+ * source is not NULL, this copies the source values to the target.
+ *
+ * @param tgt File stamp to write to
+ * @param src File stamp to copy from or NULL to clear the target
+ */
+extern void git_futils_filestamp_set(
+	git_futils_filestamp *tgt, const git_futils_filestamp *src);
+
+/**
+ * Set file stamp data from stat structure
+ */
+extern void git_futils_filestamp_set_from_stat(
+	git_futils_filestamp *stamp, struct stat *st);
+
+/**
+ * `fsync` the parent directory of the given path, if `fsync` is
+ * supported for directories on this platform.
+ *
+ * @param path Path of the directory to sync.
+ * @return 0 on success, -1 on error
+ */
+extern int git_futils_fsync_dir(const char *path);
+
+/**
+ * `fsync` the parent directory of the given path, if `fsync` is
+ * supported for directories on this platform.
+ *
+ * @param path Path of the file whose parent directory should be synced.
+ * @return 0 on success, -1 on error
+ */
+extern int git_futils_fsync_parent(const char *path);
+
+#endif
diff --git a/src/hashsig.c b/src/hashsig.c
index abebd7a..14ec34b 100644
--- a/src/hashsig.c
+++ b/src/hashsig.c
@@ -8,7 +8,7 @@
 #include "common.h"
 
 #include "git2/sys/hashsig.h"
-#include "fileops.h"
+#include "futils.h"
 #include "util.h"
 
 typedef uint32_t hashsig_t;
diff --git a/src/index.h b/src/index.h
index 982afed..54402f5 100644
--- a/src/index.h
+++ b/src/index.h
@@ -9,7 +9,7 @@
 
 #include "common.h"
 
-#include "fileops.h"
+#include "futils.h"
 #include "filebuf.h"
 #include "vector.h"
 #include "idxmap.h"
diff --git a/src/merge_file.c b/src/merge_file.c
index 0647a5d..23daa84 100644
--- a/src/merge_file.c
+++ b/src/merge_file.c
@@ -9,7 +9,7 @@
 
 #include "repository.h"
 #include "posix.h"
-#include "fileops.h"
+#include "futils.h"
 #include "index.h"
 #include "diff_xdiff.h"
 #include "merge.h"
diff --git a/src/mwindow.c b/src/mwindow.c
index 949e5fa..e834f76 100644
--- a/src/mwindow.c
+++ b/src/mwindow.c
@@ -8,7 +8,7 @@
 #include "mwindow.h"
 
 #include "vector.h"
-#include "fileops.h"
+#include "futils.h"
 #include "map.h"
 #include "global.h"
 #include "strmap.h"
diff --git a/src/odb.c b/src/odb.c
index 24befad..06e4930 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -10,7 +10,7 @@
 #include <zlib.h>
 #include "git2/object.h"
 #include "git2/sys/odb_backend.h"
-#include "fileops.h"
+#include "futils.h"
 #include "hash.h"
 #include "delta.h"
 #include "filter.h"
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 4b249b6..04b8165 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -10,7 +10,7 @@
 #include <zlib.h>
 #include "git2/object.h"
 #include "git2/sys/odb_backend.h"
-#include "fileops.h"
+#include "futils.h"
 #include "hash.h"
 #include "odb.h"
 #include "delta.h"
diff --git a/src/odb_mempack.c b/src/odb_mempack.c
index fc23023..6728c6c 100644
--- a/src/odb_mempack.c
+++ b/src/odb_mempack.c
@@ -10,7 +10,7 @@
 #include "git2/object.h"
 #include "git2/sys/odb_backend.h"
 #include "git2/sys/mempack.h"
-#include "fileops.h"
+#include "futils.h"
 #include "hash.h"
 #include "odb.h"
 #include "array.h"
diff --git a/src/odb_pack.c b/src/odb_pack.c
index bd760db..c93d07c 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -11,7 +11,7 @@
 #include "git2/repository.h"
 #include "git2/indexer.h"
 #include "git2/sys/odb_backend.h"
-#include "fileops.h"
+#include "futils.h"
 #include "hash.h"
 #include "odb.h"
 #include "delta.h"
diff --git a/src/pack.c b/src/pack.c
index c9d5602..68eeb7b 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -11,7 +11,7 @@
 #include "delta.h"
 #include "sha1_lookup.h"
 #include "mwindow.h"
-#include "fileops.h"
+#include "futils.h"
 #include "oid.h"
 
 #include <zlib.h>
diff --git a/src/patch_generate.c b/src/patch_generate.c
index 5023bfe..18256d0 100644
--- a/src/patch_generate.c
+++ b/src/patch_generate.c
@@ -15,7 +15,7 @@
 #include "diff_xdiff.h"
 #include "delta.h"
 #include "zstream.h"
-#include "fileops.h"
+#include "futils.h"
 
 static void diff_output_init(
 	git_patch_generated_output *, const git_diff_options *, git_diff_file_cb,
diff --git a/src/path.c b/src/path.c
index df6b623..41232c2 100644
--- a/src/path.c
+++ b/src/path.c
@@ -1924,3 +1924,25 @@ extern int git_path_is_gitfile(const char *path, size_t pathlen, git_path_gitfil
 		return -1;
 	}
 }
+
+bool git_path_supports_symlinks(const char *dir)
+{
+	git_buf path = GIT_BUF_INIT;
+	bool supported = false;
+	struct stat st;
+	int fd;
+
+	if ((fd = git_futils_mktmp(&path, dir, 0666)) < 0 ||
+	    p_close(fd) < 0 ||
+	    p_unlink(path.ptr) < 0 ||
+	    p_symlink("testing", path.ptr) < 0 ||
+	    p_lstat(path.ptr, &st) < 0)
+		goto done;
+
+	supported = (S_ISLNK(st.st_mode) != 0);
+done:
+	if (path.size)
+		(void)p_unlink(path.ptr);
+	git_buf_dispose(&path);
+	return supported;
+}
diff --git a/src/path.h b/src/path.h
index e29a7f6..624ca03 100644
--- a/src/path.h
+++ b/src/path.h
@@ -647,4 +647,6 @@ extern bool git_path_isvalid(
  */
 int git_path_normalize_slashes(git_buf *out, const char *path);
 
+bool git_path_supports_symlinks(const char *dir);
+
 #endif
diff --git a/src/reader.c b/src/reader.c
index 1a48446..2d87251 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -7,7 +7,7 @@
 
 #include "reader.h"
 
-#include "fileops.h"
+#include "futils.h"
 #include "blob.h"
 
 #include "git2/tree.h"
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 09ec719..a20f1eb 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -10,7 +10,7 @@
 #include "refs.h"
 #include "hash.h"
 #include "repository.h"
-#include "fileops.h"
+#include "futils.h"
 #include "filebuf.h"
 #include "pack.h"
 #include "reflog.h"
diff --git a/src/refs.c b/src/refs.c
index fd407b3..0778430 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -9,7 +9,7 @@
 
 #include "hash.h"
 #include "repository.h"
-#include "fileops.h"
+#include "futils.h"
 #include "filebuf.h"
 #include "pack.h"
 #include "reflog.h"
diff --git a/src/repository.c b/src/repository.c
index 002e84f..f9c4ef4 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -16,7 +16,7 @@
 #include "commit.h"
 #include "tag.h"
 #include "blob.h"
-#include "fileops.h"
+#include "futils.h"
 #include "sysdir.h"
 #include "filebuf.h"
 #include "index.h"
@@ -1419,9 +1419,6 @@ static bool are_symlinks_supported(const char *wd_path)
 	git_buf xdg_buf = GIT_BUF_INIT;
 	git_buf system_buf = GIT_BUF_INIT;
 	git_buf programdata_buf = GIT_BUF_INIT;
-	git_buf path = GIT_BUF_INIT;
-	int fd;
-	struct stat st;
 	int symlinks = 0;
 
 	/*
@@ -1448,23 +1445,14 @@ static bool are_symlinks_supported(const char *wd_path)
 		goto done;
 #endif
 
-	if ((fd = git_futils_mktmp(&path, wd_path, 0666)) < 0 ||
-	    p_close(fd) < 0 ||
-	    p_unlink(path.ptr) < 0 ||
-	    p_symlink("testing", path.ptr) < 0 ||
-	    p_lstat(path.ptr, &st) < 0)
+	if (!(symlinks = git_path_supports_symlinks(wd_path)))
 		goto done;
 
-	symlinks = (S_ISLNK(st.st_mode) != 0);
-
-	(void)p_unlink(path.ptr);
-
 done:
 	git_buf_dispose(&global_buf);
 	git_buf_dispose(&xdg_buf);
 	git_buf_dispose(&system_buf);
 	git_buf_dispose(&programdata_buf);
-	git_buf_dispose(&path);
 	git_config_free(config);
 	return symlinks != 0;
 }
diff --git a/src/sortedcache.h b/src/sortedcache.h
index a53ff48..e553d01 100644
--- a/src/sortedcache.h
+++ b/src/sortedcache.h
@@ -10,7 +10,7 @@
 #include "common.h"
 
 #include "util.h"
-#include "fileops.h"
+#include "futils.h"
 #include "vector.h"
 #include "thread-utils.h"
 #include "pool.h"
diff --git a/src/status.c b/src/status.c
index 754fe08..42c98f6 100644
--- a/src/status.c
+++ b/src/status.c
@@ -8,7 +8,7 @@
 #include "status.h"
 
 #include "git2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "hash.h"
 #include "vector.h"
 #include "tree.h"
diff --git a/src/submodule.h b/src/submodule.h
index 91a4e12..57d95c3 100644
--- a/src/submodule.h
+++ b/src/submodule.h
@@ -11,7 +11,7 @@
 
 #include "git2/submodule.h"
 #include "git2/repository.h"
-#include "fileops.h"
+#include "futils.h"
 
 /* Notes:
  *
diff --git a/src/tree.c b/src/tree.c
index 3799cab..cd6ab9b 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -10,7 +10,7 @@
 #include "commit.h"
 #include "git2/repository.h"
 #include "git2/object.h"
-#include "fileops.h"
+#include "futils.h"
 #include "tree-cache.h"
 #include "index.h"
 
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 91e1643..078b509 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -8,7 +8,7 @@
 #include "common.h"
 
 #include "../posix.h"
-#include "../fileops.h"
+#include "../futils.h"
 #include "path.h"
 #include "path_w32.h"
 #include "utf-conv.h"
@@ -251,9 +251,25 @@ int p_link(const char *old, const char *new)
 
 GIT_INLINE(int) unlink_once(const wchar_t *path)
 {
+	DWORD error;
+
 	if (DeleteFileW(path))
 		return 0;
 
+	if ((error = GetLastError()) == ERROR_ACCESS_DENIED) {
+		WIN32_FILE_ATTRIBUTE_DATA fdata;
+		if (!GetFileAttributesExW(path, GetFileExInfoStandard, &fdata) ||
+		    !(fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) ||
+		    !(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
+			goto out;
+
+		if (RemoveDirectoryW(path))
+			return 0;
+	}
+
+out:
+	SetLastError(error);
+
 	if (last_error_retryable())
 		return GIT_RETRY;
 
@@ -398,18 +414,37 @@ int p_readlink(const char *path, char *buf, size_t bufsiz)
 	return (int)bufsiz;
 }
 
+static bool target_is_dir(const char *target, const char *path)
+{
+	git_buf resolved = GIT_BUF_INIT;
+	git_win32_path resolved_w;
+	bool isdir = true;
+
+	if (git_path_is_absolute(target))
+		git_win32_path_from_utf8(resolved_w, target);
+	else if (git_path_dirname_r(&resolved, path) < 0 ||
+		 git_path_apply_relative(&resolved, target) < 0 ||
+		 git_win32_path_from_utf8(resolved_w, resolved.ptr) < 0)
+		goto out;
+
+	isdir = GetFileAttributesW(resolved_w) & FILE_ATTRIBUTE_DIRECTORY;
+
+out:
+	git_buf_dispose(&resolved);
+	return isdir;
+}
+
 int p_symlink(const char *target, const char *path)
 {
 	git_win32_path target_w, path_w;
 	DWORD dwFlags;
 
 	if (git_win32_path_from_utf8(path_w, path) < 0 ||
-		git__utf8_to_16(target_w, MAX_PATH, target) < 0)
+	    git__utf8_to_16(target_w, MAX_PATH, target) < 0)
 		return -1;
 
 	dwFlags = SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE;
-
-	if (GetFileAttributesW(target_w) & FILE_ATTRIBUTE_DIRECTORY)
+	if (target_is_dir(target, path))
 		dwFlags |= SYMBOLIC_LINK_FLAG_DIRECTORY;
 
 	if (!CreateSymbolicLinkW(path_w, target_w, dwFlags))
diff --git a/tests/attr/repo.c b/tests/attr/repo.c
index 93d61b1..36beeb0 100644
--- a/tests/attr/repo.c
+++ b/tests/attr/repo.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "git2/attr.h"
 #include "attr.h"
 #include "sysdir.h"
diff --git a/tests/checkout/binaryunicode.c b/tests/checkout/binaryunicode.c
index 5ba7921..edb5cfa 100644
--- a/tests/checkout/binaryunicode.c
+++ b/tests/checkout/binaryunicode.c
@@ -2,7 +2,7 @@
 #include "refs.h"
 #include "repo/repo_helpers.h"
 #include "path.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *g_repo;
 
diff --git a/tests/checkout/checkout_helpers.c b/tests/checkout/checkout_helpers.c
index 8256644..95af5d3 100644
--- a/tests/checkout/checkout_helpers.c
+++ b/tests/checkout/checkout_helpers.c
@@ -1,7 +1,7 @@
 #include "clar_libgit2.h"
 #include "checkout_helpers.h"
 #include "refs.h"
-#include "fileops.h"
+#include "futils.h"
 #include "index.h"
 
 void assert_on_branch(git_repository *repo, const char *branch)
diff --git a/tests/checkout/conflict.c b/tests/checkout/conflict.c
index 3ad830f..dae3f29 100644
--- a/tests/checkout/conflict.c
+++ b/tests/checkout/conflict.c
@@ -1,7 +1,7 @@
 #include "clar_libgit2.h"
 #include "git2/repository.h"
 #include "git2/sys/index.h"
-#include "fileops.h"
+#include "futils.h"
 #include "repository.h"
 
 static git_repository *g_repo;
diff --git a/tests/checkout/crlf.c b/tests/checkout/crlf.c
index ff3a2dc..65e13a6 100644
--- a/tests/checkout/crlf.c
+++ b/tests/checkout/crlf.c
@@ -1,7 +1,7 @@
 #include "clar_libgit2.h"
 #include "checkout_helpers.h"
 #include "../filter/crlf.h"
-#include "fileops.h"
+#include "futils.h"
 
 #include "git2/checkout.h"
 #include "repository.h"
diff --git a/tests/checkout/head.c b/tests/checkout/head.c
index 9906146..7991230 100644
--- a/tests/checkout/head.c
+++ b/tests/checkout/head.c
@@ -2,7 +2,7 @@
 #include "refs.h"
 #include "repo/repo_helpers.h"
 #include "path.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *g_repo;
 
diff --git a/tests/checkout/index.c b/tests/checkout/index.c
index 9aa41cc..a76c471 100644
--- a/tests/checkout/index.c
+++ b/tests/checkout/index.c
@@ -2,7 +2,7 @@
 #include "checkout_helpers.h"
 
 #include "git2/checkout.h"
-#include "fileops.h"
+#include "futils.h"
 #include "repository.h"
 #include "remote.h"
 #include "repo/repo_helpers.h"
@@ -181,7 +181,7 @@ void test_checkout_index__honor_coresymlinks_default_true(void)
 
 	cl_must_pass(p_mkdir("symlink", 0777));
 
-	if (!filesystem_supports_symlinks("symlink/test"))
+	if (!git_path_supports_symlinks("symlink/test"))
 		cl_skip();
 
 #ifdef GIT_WIN32
@@ -214,7 +214,7 @@ void test_checkout_index__honor_coresymlinks_default_false(void)
 	 * supports symlinks.  Bail entirely on POSIX platforms that
 	 * do support symlinks.
 	 */
-	if (filesystem_supports_symlinks("symlink/test"))
+	if (git_path_supports_symlinks("symlink/test"))
 		cl_skip();
 #endif
 
@@ -226,7 +226,7 @@ void test_checkout_index__coresymlinks_set_to_true_fails_when_unsupported(void)
 {
 	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
 
-	if (filesystem_supports_symlinks("testrepo/test")) {
+	if (git_path_supports_symlinks("testrepo/test")) {
 		cl_skip();
 	}
 
@@ -242,7 +242,7 @@ void test_checkout_index__honor_coresymlinks_setting_set_to_true(void)
 	char link_data[GIT_PATH_MAX];
 	size_t link_size = GIT_PATH_MAX;
 
-	if (!filesystem_supports_symlinks("testrepo/test")) {
+	if (!git_path_supports_symlinks("testrepo/test")) {
 		cl_skip();
 	}
 
diff --git a/tests/checkout/nasty.c b/tests/checkout/nasty.c
index 042fbba..3897878 100644
--- a/tests/checkout/nasty.c
+++ b/tests/checkout/nasty.c
@@ -4,7 +4,7 @@
 #include "git2/checkout.h"
 #include "repository.h"
 #include "buffer.h"
-#include "fileops.h"
+#include "futils.h"
 
 static const char *repo_name = "nasty";
 static git_repository *repo;
diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c
index 47ded0f..380d251 100644
--- a/tests/checkout/tree.c
+++ b/tests/checkout/tree.c
@@ -4,7 +4,7 @@
 #include "git2/checkout.h"
 #include "repository.h"
 #include "buffer.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *g_repo;
 static git_checkout_options g_opts;
diff --git a/tests/checkout/typechange.c b/tests/checkout/typechange.c
index 708af59..db3f02a 100644
--- a/tests/checkout/typechange.c
+++ b/tests/checkout/typechange.c
@@ -3,7 +3,7 @@
 #include "git2/checkout.h"
 #include "path.h"
 #include "posix.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *g_repo = NULL;
 
diff --git a/tests/cherrypick/bare.c b/tests/cherrypick/bare.c
index 1353365..50e8d86 100644
--- a/tests/cherrypick/bare.c
+++ b/tests/cherrypick/bare.c
@@ -2,7 +2,7 @@
 #include "clar_libgit2.h"
 
 #include "buffer.h"
-#include "fileops.h"
+#include "futils.h"
 #include "git2/cherrypick.h"
 
 #include "../merge/merge_helpers.h"
diff --git a/tests/cherrypick/workdir.c b/tests/cherrypick/workdir.c
index 8f66449..10e8c2d 100644
--- a/tests/cherrypick/workdir.c
+++ b/tests/cherrypick/workdir.c
@@ -2,7 +2,7 @@
 #include "clar_libgit2.h"
 
 #include "buffer.h"
-#include "fileops.h"
+#include "futils.h"
 #include "git2/cherrypick.h"
 
 #include "../merge/merge_helpers.h"
diff --git a/tests/clone/local.c b/tests/clone/local.c
index 9416918..b90ff31 100644
--- a/tests/clone/local.c
+++ b/tests/clone/local.c
@@ -5,7 +5,7 @@
 #include "buffer.h"
 #include "path.h"
 #include "posix.h"
-#include "fileops.h"
+#include "futils.h"
 
 static int file_url(git_buf *buf, const char *host, const char *path)
 {
diff --git a/tests/clone/nonetwork.c b/tests/clone/nonetwork.c
index 73528e5..2b8081f 100644
--- a/tests/clone/nonetwork.c
+++ b/tests/clone/nonetwork.c
@@ -4,7 +4,7 @@
 #include "git2/sys/commit.h"
 #include "../submodule/submodule_helpers.h"
 #include "remote.h"
-#include "fileops.h"
+#include "futils.h"
 #include "repository.h"
 
 #define LIVE_REPO_URL "git://github.com/libgit2/TestGitRepository"
diff --git a/tests/clone/transport.c b/tests/clone/transport.c
index cccaae2..fa4f653 100644
--- a/tests/clone/transport.c
+++ b/tests/clone/transport.c
@@ -3,7 +3,7 @@
 #include "git2/clone.h"
 #include "git2/transport.h"
 #include "git2/sys/transport.h"
-#include "fileops.h"
+#include "futils.h"
 
 static int custom_transport(
 	git_transport **out,
diff --git a/tests/config/conditionals.c b/tests/config/conditionals.c
index 8b9c0e6..0e629e4 100644
--- a/tests/config/conditionals.c
+++ b/tests/config/conditionals.c
@@ -1,6 +1,6 @@
 #include "clar_libgit2.h"
 #include "buffer.h"
-#include "fileops.h"
+#include "futils.h"
 
 #ifdef GIT_WIN32
 # define ROOT_PREFIX "C:"
diff --git a/tests/config/global.c b/tests/config/global.c
index 4517cae..b64b716 100644
--- a/tests/config/global.c
+++ b/tests/config/global.c
@@ -1,6 +1,6 @@
 #include "clar_libgit2.h"
 #include "buffer.h"
-#include "fileops.h"
+#include "futils.h"
 
 void test_config_global__initialize(void)
 {
diff --git a/tests/config/include.c b/tests/config/include.c
index 4454693..48261dd 100644
--- a/tests/config/include.c
+++ b/tests/config/include.c
@@ -1,6 +1,6 @@
 #include "clar_libgit2.h"
 #include "buffer.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_config *cfg;
 static git_buf buf;
diff --git a/tests/config/new.c b/tests/config/new.c
index bb3a2d9..2f5d83d 100644
--- a/tests/config/new.c
+++ b/tests/config/new.c
@@ -1,7 +1,7 @@
 #include "clar_libgit2.h"
 
 #include "filebuf.h"
-#include "fileops.h"
+#include "futils.h"
 #include "posix.h"
 
 #define TEST_CONFIG "git-new-config"
diff --git a/tests/config/stress.c b/tests/config/stress.c
index ad09c87..4fb0f3b 100644
--- a/tests/config/stress.c
+++ b/tests/config/stress.c
@@ -1,7 +1,7 @@
 #include "clar_libgit2.h"
 
 #include "filebuf.h"
-#include "fileops.h"
+#include "futils.h"
 #include "posix.h"
 
 #define TEST_CONFIG "git-test-config"
diff --git a/tests/config/write.c b/tests/config/write.c
index bd0f5b2..78ed7f1 100644
--- a/tests/config/write.c
+++ b/tests/config/write.c
@@ -1,6 +1,6 @@
 #include "clar_libgit2.h"
 #include "buffer.h"
-#include "fileops.h"
+#include "futils.h"
 #include "git2/sys/config.h"
 #include "config.h"
 
diff --git a/tests/core/buffer.c b/tests/core/buffer.c
index b8a76b3..58c98cb 100644
--- a/tests/core/buffer.c
+++ b/tests/core/buffer.c
@@ -2,7 +2,7 @@
 #include "buffer.h"
 #include "buf_text.h"
 #include "git2/sys/hashsig.h"
-#include "fileops.h"
+#include "futils.h"
 
 #define TESTSTR "Have you seen that? Have you seeeen that??"
 const char *test_string = TESTSTR;
diff --git a/tests/core/copy.c b/tests/core/copy.c
index 967748c..d312748 100644
--- a/tests/core/copy.c
+++ b/tests/core/copy.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "path.h"
 #include "posix.h"
 
diff --git a/tests/core/dirent.c b/tests/core/dirent.c
index a2448b4..08e0b11 100644
--- a/tests/core/dirent.c
+++ b/tests/core/dirent.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 
 typedef struct name_data {
 	int count; /* return count */
diff --git a/tests/core/env.c b/tests/core/env.c
index 7e7b327..3c34b2c 100644
--- a/tests/core/env.c
+++ b/tests/core/env.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "sysdir.h"
 #include "path.h"
 
diff --git a/tests/core/filebuf.c b/tests/core/filebuf.c
index 8d1952f..e527ce9 100644
--- a/tests/core/filebuf.c
+++ b/tests/core/filebuf.c
@@ -157,9 +157,8 @@ void test_core_filebuf__symlink_follow(void)
 	git_filebuf file = GIT_FILEBUF_INIT;
 	const char *dir = "linkdir", *source = "linkdir/link";
 
-#ifdef GIT_WIN32
-	cl_skip();
-#endif
+	if (!git_path_supports_symlinks(clar_sandbox_path()))
+		cl_skip();
 
 	cl_git_pass(p_mkdir(dir, 0777));
 	cl_git_pass(p_symlink("target", source));
@@ -192,9 +191,8 @@ void test_core_filebuf__symlink_follow_absolute_paths(void)
 	git_filebuf file = GIT_FILEBUF_INIT;
 	git_buf source = GIT_BUF_INIT, target = GIT_BUF_INIT;
 
-#ifdef GIT_WIN32
-	cl_skip();
-#endif
+	if (!git_path_supports_symlinks(clar_sandbox_path()))
+		cl_skip();
 
 	cl_git_pass(git_buf_joinpath(&source, clar_sandbox_path(), "linkdir/link"));
 	cl_git_pass(git_buf_joinpath(&target, clar_sandbox_path(), "linkdir/target"));
@@ -221,9 +219,8 @@ void test_core_filebuf__symlink_depth(void)
 	git_filebuf file = GIT_FILEBUF_INIT;
 	const char *dir = "linkdir", *source = "linkdir/link";
 
-#ifdef GIT_WIN32
-	cl_skip();
-#endif
+	if (!git_path_supports_symlinks(clar_sandbox_path()))
+		cl_skip();
 
 	cl_git_pass(p_mkdir(dir, 0777));
 	/* Endless loop */
diff --git a/tests/core/futils.c b/tests/core/futils.c
index fce4848..2c8294c 100644
--- a/tests/core/futils.c
+++ b/tests/core/futils.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 
 /* Fixture setup and teardown */
 void test_core_futils__initialize(void)
@@ -66,3 +66,24 @@ void test_core_futils__write_hidden_file(void)
 #endif
 }
 
+void test_core_futils__recursive_rmdir_keeps_symlink_targets(void)
+{
+	if (!git_path_supports_symlinks(clar_sandbox_path()))
+		cl_skip();
+
+	cl_git_pass(git_futils_mkdir_r("a/b", 0777));
+	cl_git_pass(git_futils_mkdir_r("dir-target", 0777));
+	cl_git_mkfile("dir-target/file", "Contents");
+	cl_git_mkfile("file-target", "Contents");
+	cl_must_pass(p_symlink("dir-target", "a/symlink"));
+	cl_must_pass(p_symlink("file-target", "a/b/symlink"));
+
+	cl_git_pass(git_futils_rmdir_r("a", NULL, GIT_RMDIR_REMOVE_FILES));
+
+	cl_assert(git_path_exists("dir-target"));
+	cl_assert(git_path_exists("file-target"));
+
+	cl_must_pass(p_unlink("dir-target/file"));
+	cl_must_pass(p_rmdir("dir-target"));
+	cl_must_pass(p_unlink("file-target"));
+}
diff --git a/tests/core/mkdir.c b/tests/core/mkdir.c
index 8e52efb..ce11953 100644
--- a/tests/core/mkdir.c
+++ b/tests/core/mkdir.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "path.h"
 #include "posix.h"
 
diff --git a/tests/core/path.c b/tests/core/path.c
index 058a710..2e5a4ab 100644
--- a/tests/core/path.c
+++ b/tests/core/path.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 
 static void
 check_dirname(const char *A, const char *B)
diff --git a/tests/core/posix.c b/tests/core/posix.c
index a459b26..dcc619f 100644
--- a/tests/core/posix.c
+++ b/tests/core/posix.c
@@ -12,6 +12,7 @@
 #include <locale.h>
 
 #include "clar_libgit2.h"
+#include "futils.h"
 #include "posix.h"
 #include "userdiff.h"
 
@@ -122,7 +123,7 @@ void test_core_posix__utimes(void)
 	cl_git_mkfile("foo", "Dummy file.");
 	cl_must_pass(p_utimes("foo", times));
 
-	p_stat("foo", &st);
+	cl_must_pass(p_stat("foo", &st));
 	cl_assert_equal_i(1234567890, st.st_atime);
 	cl_assert_equal_i(1234567890, st.st_mtime);
 
@@ -135,9 +136,9 @@ void test_core_posix__utimes(void)
 
 	cl_must_pass(fd = p_open("foo", O_RDWR));
 	cl_must_pass(p_futimes(fd, times));
-	p_close(fd);
+	cl_must_pass(p_close(fd));
 
-	p_stat("foo", &st);
+	cl_must_pass(p_stat("foo", &st));
 	cl_assert_equal_i(1414141414, st.st_atime);
 	cl_assert_equal_i(1414141414, st.st_mtime);
 
@@ -148,11 +149,11 @@ void test_core_posix__utimes(void)
 	cl_must_pass(p_utimes("foo", NULL));
 
 	curtime = time(NULL);
-	p_stat("foo", &st);
+	cl_must_pass(p_stat("foo", &st));
 	cl_assert((st.st_atime - curtime) < 5);
 	cl_assert((st.st_mtime - curtime) < 5);
 
-	p_unlink("foo");
+	cl_must_pass(p_unlink("foo"));
 }
 
 static void try_set_locale(int category)
@@ -263,3 +264,48 @@ void test_core_posix__p_regcomp_compile_userdiff_regexps(void)
 		cl_assert(!error);
 	}
 }
+
+void test_core_posix__unlink_removes_symlink(void)
+{
+	if (!git_path_supports_symlinks(clar_sandbox_path()))
+		clar__skip();
+
+	cl_git_mkfile("file", "Dummy file.");
+	cl_git_pass(git_futils_mkdir("dir", 0777, 0));
+
+	cl_must_pass(p_symlink("file", "file-symlink"));
+	cl_must_pass(p_symlink("dir", "dir-symlink"));
+
+	cl_must_pass(p_unlink("file-symlink"));
+	cl_must_pass(p_unlink("dir-symlink"));
+
+	cl_assert(git_path_exists("file"));
+	cl_assert(git_path_exists("dir"));
+
+	cl_must_pass(p_unlink("file"));
+	cl_must_pass(p_rmdir("dir"));
+}
+
+void test_core_posix__symlink_resolves_to_correct_type(void)
+{
+	git_buf contents = GIT_BUF_INIT;
+
+	if (!git_path_supports_symlinks(clar_sandbox_path()))
+		clar__skip();
+
+	cl_must_pass(git_futils_mkdir("dir", 0777, 0));
+	cl_must_pass(git_futils_mkdir("file", 0777, 0));
+	cl_git_mkfile("dir/file", "symlink target");
+
+	cl_git_pass(p_symlink("file", "dir/link"));
+
+	cl_git_pass(git_futils_readbuffer(&contents, "dir/file"));
+	cl_assert_equal_s(contents.ptr, "symlink target");
+
+	cl_must_pass(p_unlink("dir/link"));
+	cl_must_pass(p_unlink("dir/file"));
+	cl_must_pass(p_rmdir("dir"));
+	cl_must_pass(p_rmdir("file"));
+
+	git_buf_dispose(&contents);
+}
diff --git a/tests/core/rmdir.c b/tests/core/rmdir.c
index e00ec5c..b436b97 100644
--- a/tests/core/rmdir.c
+++ b/tests/core/rmdir.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 
 static const char *empty_tmp_dir = "test_gitfo_rmdir_recurs_test";
 
diff --git a/tests/core/stat.c b/tests/core/stat.c
index 59a1346..7f5d667 100644
--- a/tests/core/stat.c
+++ b/tests/core/stat.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "path.h"
 #include "posix.h"
 
diff --git a/tests/diff/diff_helpers.h b/tests/diff/diff_helpers.h
index 520b654..af855ce 100644
--- a/tests/diff/diff_helpers.h
+++ b/tests/diff/diff_helpers.h
@@ -1,4 +1,4 @@
-#include "fileops.h"
+#include "futils.h"
 #include "git2/diff.h"
 
 extern git_tree *resolve_commit_oid_to_tree(
diff --git a/tests/fetchhead/nonetwork.c b/tests/fetchhead/nonetwork.c
index 6589432..c236223 100644
--- a/tests/fetchhead/nonetwork.c
+++ b/tests/fetchhead/nonetwork.c
@@ -1,6 +1,6 @@
 #include "clar_libgit2.h"
 
-#include "fileops.h"
+#include "futils.h"
 #include "fetchhead.h"
 
 #include "fetchhead_data.h"
diff --git a/tests/ignore/path.c b/tests/ignore/path.c
index 5daf329..864fba4 100644
--- a/tests/ignore/path.c
+++ b/tests/ignore/path.c
@@ -1,7 +1,7 @@
 #include "clar_libgit2.h"
 #include "posix.h"
 #include "path.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *g_repo = NULL;
 
diff --git a/tests/ignore/status.c b/tests/ignore/status.c
index 2c32f44..6082a81 100644
--- a/tests/ignore/status.c
+++ b/tests/ignore/status.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "git2/attr.h"
 #include "ignore.h"
 #include "attr.h"
diff --git a/tests/index/addall.c b/tests/index/addall.c
index 992cd87..c62c3cf 100644
--- a/tests/index/addall.c
+++ b/tests/index/addall.c
@@ -1,7 +1,7 @@
 #include "clar_libgit2.h"
 #include "../status/status_helpers.h"
 #include "posix.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *g_repo = NULL;
 #define TEST_DIR "addall"
diff --git a/tests/iterator/index.c b/tests/iterator/index.c
index 8c7efb2..25d8c29 100644
--- a/tests/iterator/index.c
+++ b/tests/iterator/index.c
@@ -1,7 +1,7 @@
 #include "clar_libgit2.h"
 #include "iterator.h"
 #include "repository.h"
-#include "fileops.h"
+#include "futils.h"
 #include "iterator_helpers.h"
 #include "../submodule/submodule_helpers.h"
 #include <stdarg.h>
diff --git a/tests/iterator/iterator_helpers.c b/tests/iterator/iterator_helpers.c
index 68d5741..b210dbb 100644
--- a/tests/iterator/iterator_helpers.c
+++ b/tests/iterator/iterator_helpers.c
@@ -1,7 +1,7 @@
 #include "clar_libgit2.h"
 #include "iterator.h"
 #include "repository.h"
-#include "fileops.h"
+#include "futils.h"
 #include "iterator_helpers.h"
 #include <stdarg.h>
 
diff --git a/tests/iterator/tree.c b/tests/iterator/tree.c
index 08df909..f7fb9a7 100644
--- a/tests/iterator/tree.c
+++ b/tests/iterator/tree.c
@@ -1,7 +1,7 @@
 #include "clar_libgit2.h"
 #include "iterator.h"
 #include "repository.h"
-#include "fileops.h"
+#include "futils.h"
 #include "tree.h"
 #include "../submodule/submodule_helpers.h"
 #include "../diff/diff_helpers.h"
diff --git a/tests/iterator/workdir.c b/tests/iterator/workdir.c
index 9d3b543..926cc6a 100644
--- a/tests/iterator/workdir.c
+++ b/tests/iterator/workdir.c
@@ -1,7 +1,7 @@
 #include "clar_libgit2.h"
 #include "iterator.h"
 #include "repository.h"
-#include "fileops.h"
+#include "futils.h"
 #include "../submodule/submodule_helpers.h"
 #include "../merge/merge_helpers.h"
 #include "iterator_helpers.h"
diff --git a/tests/merge/files.c b/tests/merge/files.c
index 27c9636..6877f98 100644
--- a/tests/merge/files.c
+++ b/tests/merge/files.c
@@ -6,7 +6,7 @@
 #include "merge_helpers.h"
 #include "conflict_data.h"
 #include "refs.h"
-#include "fileops.h"
+#include "futils.h"
 #include "diff_xdiff.h"
 
 #define TEST_REPO_PATH "merge-resolve"
diff --git a/tests/merge/merge_helpers.c b/tests/merge/merge_helpers.c
index cddb411..27f355f 100644
--- a/tests/merge/merge_helpers.c
+++ b/tests/merge/merge_helpers.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "refs.h"
 #include "tree.h"
 #include "merge_helpers.h"
diff --git a/tests/merge/trees/automerge.c b/tests/merge/trees/automerge.c
index e4efba5..dd26464 100644
--- a/tests/merge/trees/automerge.c
+++ b/tests/merge/trees/automerge.c
@@ -3,7 +3,7 @@
 #include "git2/merge.h"
 #include "buffer.h"
 #include "merge.h"
-#include "fileops.h"
+#include "futils.h"
 #include "../merge_helpers.h"
 #include "../conflict_data.h"
 
diff --git a/tests/merge/trees/modeconflict.c b/tests/merge/trees/modeconflict.c
index e85e340..32866ea 100644
--- a/tests/merge/trees/modeconflict.c
+++ b/tests/merge/trees/modeconflict.c
@@ -4,7 +4,7 @@
 #include "buffer.h"
 #include "merge.h"
 #include "../merge_helpers.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *repo;
 
diff --git a/tests/merge/trees/renames.c b/tests/merge/trees/renames.c
index fbcfd2d..e0b12af 100644
--- a/tests/merge/trees/renames.c
+++ b/tests/merge/trees/renames.c
@@ -4,7 +4,7 @@
 #include "buffer.h"
 #include "merge.h"
 #include "../merge_helpers.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *repo;
 
diff --git a/tests/merge/trees/trivial.c b/tests/merge/trees/trivial.c
index 4a82556..ac4f09f 100644
--- a/tests/merge/trees/trivial.c
+++ b/tests/merge/trees/trivial.c
@@ -4,7 +4,7 @@
 #include "merge.h"
 #include "../merge_helpers.h"
 #include "refs.h"
-#include "fileops.h"
+#include "futils.h"
 #include "git2/sys/index.h"
 
 static git_repository *repo;
diff --git a/tests/merge/trees/whitespace.c b/tests/merge/trees/whitespace.c
index fdb1125..ce77034 100644
--- a/tests/merge/trees/whitespace.c
+++ b/tests/merge/trees/whitespace.c
@@ -4,7 +4,7 @@
 #include "buffer.h"
 #include "merge.h"
 #include "../merge_helpers.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *repo;
 
diff --git a/tests/merge/workdir/renames.c b/tests/merge/workdir/renames.c
index a8ee59a..e8cd333 100644
--- a/tests/merge/workdir/renames.c
+++ b/tests/merge/workdir/renames.c
@@ -4,7 +4,7 @@
 #include "buffer.h"
 #include "merge.h"
 #include "../merge_helpers.h"
-#include "fileops.h"
+#include "futils.h"
 #include "refs.h"
 
 static git_repository *repo;
diff --git a/tests/merge/workdir/setup.c b/tests/merge/workdir/setup.c
index 3a8f9d9..ad29fcd 100644
--- a/tests/merge/workdir/setup.c
+++ b/tests/merge/workdir/setup.c
@@ -3,7 +3,7 @@
 #include "git2/merge.h"
 #include "merge.h"
 #include "refs.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *repo;
 static git_index *repo_index;
diff --git a/tests/merge/workdir/simple.c b/tests/merge/workdir/simple.c
index a8d5d0b..6b4e174 100644
--- a/tests/merge/workdir/simple.c
+++ b/tests/merge/workdir/simple.c
@@ -6,7 +6,7 @@
 #include "../merge_helpers.h"
 #include "../conflict_data.h"
 #include "refs.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *repo;
 static git_index *repo_index;
diff --git a/tests/merge/workdir/trivial.c b/tests/merge/workdir/trivial.c
index 39d1ddc..c5bb703 100644
--- a/tests/merge/workdir/trivial.c
+++ b/tests/merge/workdir/trivial.c
@@ -5,7 +5,7 @@
 #include "merge.h"
 #include "../merge_helpers.h"
 #include "refs.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *repo;
 static git_index *repo_index;
diff --git a/tests/object/blob/fromstream.c b/tests/object/blob/fromstream.c
index 416b452..df229f9 100644
--- a/tests/object/blob/fromstream.c
+++ b/tests/object/blob/fromstream.c
@@ -2,7 +2,7 @@
 #include "buffer.h"
 #include "posix.h"
 #include "path.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *repo;
 static char textual_content[] = "libgit2\n\r\n\0";
diff --git a/tests/object/blob/write.c b/tests/object/blob/write.c
index e6b67fb..9a18d7c 100644
--- a/tests/object/blob/write.c
+++ b/tests/object/blob/write.c
@@ -2,7 +2,7 @@
 #include "buffer.h"
 #include "posix.h"
 #include "path.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *repo;
 
diff --git a/tests/object/raw/write.c b/tests/object/raw/write.c
index a360f04..9bc1276 100644
--- a/tests/object/raw/write.c
+++ b/tests/object/raw/write.c
@@ -1,7 +1,7 @@
 #include "clar_libgit2.h"
 #include "git2/odb_backend.h"
 
-#include "fileops.h"
+#include "futils.h"
 #include "odb.h"
 
 typedef struct object_data {
diff --git a/tests/online/clone.c b/tests/online/clone.c
index b7042f3..60aaeeb 100644
--- a/tests/online/clone.c
+++ b/tests/online/clone.c
@@ -3,7 +3,7 @@
 #include "git2/clone.h"
 #include "git2/cred_helpers.h"
 #include "remote.h"
-#include "fileops.h"
+#include "futils.h"
 #include "refs.h"
 
 #define LIVE_REPO_URL "http://github.com/libgit2/TestGitRepository"
diff --git a/tests/online/fetchhead.c b/tests/online/fetchhead.c
index 7e9ca7e..4f7be7e 100644
--- a/tests/online/fetchhead.c
+++ b/tests/online/fetchhead.c
@@ -1,6 +1,6 @@
 #include "clar_libgit2.h"
 
-#include "fileops.h"
+#include "futils.h"
 #include "fetchhead.h"
 #include "../fetchhead/fetchhead_data.h"
 #include "git2/clone.h"
diff --git a/tests/pack/indexer.c b/tests/pack/indexer.c
index 08247ae..422c3de 100644
--- a/tests/pack/indexer.c
+++ b/tests/pack/indexer.c
@@ -1,6 +1,6 @@
 #include "clar_libgit2.h"
 #include <git2.h>
-#include "fileops.h"
+#include "futils.h"
 #include "hash.h"
 #include "iterator.h"
 #include "vector.h"
diff --git a/tests/pack/packbuilder.c b/tests/pack/packbuilder.c
index 397d32e..59eb3da 100644
--- a/tests/pack/packbuilder.c
+++ b/tests/pack/packbuilder.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "pack.h"
 #include "hash.h"
 #include "iterator.h"
diff --git a/tests/refs/branches/delete.c b/tests/refs/branches/delete.c
index 553d800..6093c78 100644
--- a/tests/refs/branches/delete.c
+++ b/tests/refs/branches/delete.c
@@ -2,7 +2,7 @@
 #include "refs.h"
 #include "repo/repo_helpers.h"
 #include "config/config_helpers.h"
-#include "fileops.h"
+#include "futils.h"
 #include "reflog.h"
 
 static git_repository *repo;
diff --git a/tests/refs/delete.c b/tests/refs/delete.c
index 4cc78aa..a334496 100644
--- a/tests/refs/delete.c
+++ b/tests/refs/delete.c
@@ -1,6 +1,6 @@
 #include "clar_libgit2.h"
 
-#include "fileops.h"
+#include "futils.h"
 #include "git2/reflog.h"
 #include "git2/refdb.h"
 #include "reflog.h"
diff --git a/tests/refs/pack.c b/tests/refs/pack.c
index 92312e2..676fb17 100644
--- a/tests/refs/pack.c
+++ b/tests/refs/pack.c
@@ -1,6 +1,6 @@
 #include "clar_libgit2.h"
 
-#include "fileops.h"
+#include "futils.h"
 #include "git2/reflog.h"
 #include "git2/refdb.h"
 #include "reflog.h"
diff --git a/tests/refs/reflog/messages.c b/tests/refs/reflog/messages.c
index 5ca9ab3..f8acd23 100644
--- a/tests/refs/reflog/messages.c
+++ b/tests/refs/reflog/messages.c
@@ -1,6 +1,6 @@
 #include "clar_libgit2.h"
 
-#include "fileops.h"
+#include "futils.h"
 #include "git2/reflog.h"
 #include "reflog.h"
 #include "refs.h"
diff --git a/tests/refs/reflog/reflog.c b/tests/refs/reflog/reflog.c
index cf8c5c2..7e4b1ef 100644
--- a/tests/refs/reflog/reflog.c
+++ b/tests/refs/reflog/reflog.c
@@ -1,6 +1,6 @@
 #include "clar_libgit2.h"
 
-#include "fileops.h"
+#include "futils.h"
 #include "git2/reflog.h"
 #include "reflog.h"
 
diff --git a/tests/refs/rename.c b/tests/refs/rename.c
index 9933bee..b1b75cd 100644
--- a/tests/refs/rename.c
+++ b/tests/refs/rename.c
@@ -1,6 +1,6 @@
 #include "clar_libgit2.h"
 
-#include "fileops.h"
+#include "futils.h"
 #include "git2/reflog.h"
 #include "reflog.h"
 #include "refs.h"
diff --git a/tests/repo/config.c b/tests/repo/config.c
index a397ee5..6ca31f5 100644
--- a/tests/repo/config.c
+++ b/tests/repo/config.c
@@ -1,6 +1,6 @@
 #include "clar_libgit2.h"
 #include "sysdir.h"
-#include "fileops.h"
+#include "futils.h"
 #include <ctype.h>
 
 static git_buf path = GIT_BUF_INIT;
diff --git a/tests/repo/discover.c b/tests/repo/discover.c
index cc61c71..c026eef 100644
--- a/tests/repo/discover.c
+++ b/tests/repo/discover.c
@@ -1,7 +1,7 @@
 #include "clar_libgit2.h"
 
 #include "odb.h"
-#include "fileops.h"
+#include "futils.h"
 #include "repository.h"
 
 #define TEMP_REPO_FOLDER "temprepo/"
diff --git a/tests/repo/env.c b/tests/repo/env.c
index 9dafda1..0246616 100644
--- a/tests/repo/env.c
+++ b/tests/repo/env.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "sysdir.h"
 #include <ctype.h>
 
diff --git a/tests/repo/init.c b/tests/repo/init.c
index 9879ef1..5a95229 100644
--- a/tests/repo/init.c
+++ b/tests/repo/init.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "repository.h"
 #include "config.h"
 #include "path.h"
@@ -253,7 +253,7 @@ void test_repo_init__symlinks_win32_enabled_by_global_config(void)
 	git_config *config, *repo_config;
 	int val;
 
-	if (!filesystem_supports_symlinks("link"))
+	if (!git_path_supports_symlinks("link"))
 		cl_skip();
 
 	create_tmp_global_config("tmp_global_config", "core.symlinks", "true");
@@ -296,7 +296,7 @@ void test_repo_init__symlinks_posix_detected(void)
 	cl_skip();
 #else
 	assert_config_entry_on_init(
-	    "core.symlinks", filesystem_supports_symlinks("link") ? GIT_ENOTFOUND : false);
+	    "core.symlinks", git_path_supports_symlinks("link") ? GIT_ENOTFOUND : false);
 #endif
 }
 
diff --git a/tests/repo/open.c b/tests/repo/open.c
index 5c08a38..edcf93f 100644
--- a/tests/repo/open.c
+++ b/tests/repo/open.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "sysdir.h"
 #include <ctype.h>
 
diff --git a/tests/repo/repo_helpers.c b/tests/repo/repo_helpers.c
index 4256314..b22f3f6 100644
--- a/tests/repo/repo_helpers.c
+++ b/tests/repo/repo_helpers.c
@@ -21,21 +21,6 @@ void delete_head(git_repository* repo)
 	git_buf_dispose(&head_path);
 }
 
-int filesystem_supports_symlinks(const char *path)
-{
-	struct stat st;
-	bool support = 0;
-
-	if (p_symlink("target", path) == 0) {
-		if (p_lstat(path, &st) == 0 && S_ISLNK(st.st_mode))
-			support = 1;
-
-		p_unlink(path);
-	}
-
-	return support;
-}
-
 void create_tmp_global_config(const char *dirname, const char *key, const char *val)
 {
 	git_buf path = GIT_BUF_INIT;
diff --git a/tests/repo/repo_helpers.h b/tests/repo/repo_helpers.h
index 2c9aeab..a93bf36 100644
--- a/tests/repo/repo_helpers.h
+++ b/tests/repo/repo_helpers.h
@@ -4,5 +4,4 @@
 
 extern void make_head_unborn(git_repository* repo, const char *target);
 extern void delete_head(git_repository* repo);
-extern int filesystem_supports_symlinks(const char *path);
 extern void create_tmp_global_config(const char *path, const char *key, const char *val);
diff --git a/tests/repo/setters.c b/tests/repo/setters.c
index ea6ef12..1fac627 100644
--- a/tests/repo/setters.c
+++ b/tests/repo/setters.c
@@ -5,7 +5,7 @@
 #include "posix.h"
 #include "util.h"
 #include "path.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *repo;
 
diff --git a/tests/repo/shallow.c b/tests/repo/shallow.c
index b9a7b81..adb7a9e 100644
--- a/tests/repo/shallow.c
+++ b/tests/repo/shallow.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *g_repo;
 
diff --git a/tests/repo/state.c b/tests/repo/state.c
index fb89497..afb3617 100644
--- a/tests/repo/state.c
+++ b/tests/repo/state.c
@@ -2,7 +2,7 @@
 #include "buffer.h"
 #include "refs.h"
 #include "posix.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *_repo;
 static git_buf _path;
diff --git a/tests/repo/template.c b/tests/repo/template.c
index 7ccd935..3513190 100644
--- a/tests/repo/template.c
+++ b/tests/repo/template.c
@@ -1,6 +1,6 @@
 #include "clar_libgit2.h"
 
-#include "fileops.h"
+#include "futils.h"
 #include "repo/repo_helpers.h"
 
 #define CLEAR_FOR_CORE_FILEMODE(M) ((M) &= ~0177)
diff --git a/tests/reset/hard.c b/tests/reset/hard.c
index b6e9139..1ea1d13 100644
--- a/tests/reset/hard.c
+++ b/tests/reset/hard.c
@@ -2,7 +2,7 @@
 #include "posix.h"
 #include "reset_helpers.h"
 #include "path.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *repo;
 static git_object *target;
diff --git a/tests/revert/bare.c b/tests/revert/bare.c
index fc7d030..03cffbf 100644
--- a/tests/revert/bare.c
+++ b/tests/revert/bare.c
@@ -2,7 +2,7 @@
 #include "clar_libgit2.h"
 
 #include "buffer.h"
-#include "fileops.h"
+#include "futils.h"
 #include "git2/revert.h"
 
 #include "../merge/merge_helpers.h"
diff --git a/tests/revert/workdir.c b/tests/revert/workdir.c
index 9acf20d..2ad059d 100644
--- a/tests/revert/workdir.c
+++ b/tests/revert/workdir.c
@@ -2,7 +2,7 @@
 #include "clar_libgit2.h"
 
 #include "buffer.h"
-#include "fileops.h"
+#include "futils.h"
 #include "git2/revert.h"
 
 #include "../merge/merge_helpers.h"
diff --git a/tests/stash/apply.c b/tests/stash/apply.c
index 063223a..5eb5954 100644
--- a/tests/stash/apply.c
+++ b/tests/stash/apply.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "stash_helpers.h"
 
 static git_signature *signature;
diff --git a/tests/stash/drop.c b/tests/stash/drop.c
index 89a0ade..6b0895b 100644
--- a/tests/stash/drop.c
+++ b/tests/stash/drop.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "stash_helpers.h"
 #include "refs.h"
 
diff --git a/tests/stash/foreach.c b/tests/stash/foreach.c
index 57dc8ee..fa3a9c9 100644
--- a/tests/stash/foreach.c
+++ b/tests/stash/foreach.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "stash_helpers.h"
 
 struct callback_data
diff --git a/tests/stash/save.c b/tests/stash/save.c
index c38ef82..362c704 100644
--- a/tests/stash/save.c
+++ b/tests/stash/save.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "stash_helpers.h"
 
 static git_repository *repo;
diff --git a/tests/stash/stash_helpers.c b/tests/stash/stash_helpers.c
index 0398757..cd0cfbd 100644
--- a/tests/stash/stash_helpers.c
+++ b/tests/stash/stash_helpers.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "stash_helpers.h"
 
 void setup_stash(git_repository *repo, git_signature *signature)
diff --git a/tests/status/submodules.c b/tests/status/submodules.c
index 33c9e5a..12edce2 100644
--- a/tests/status/submodules.c
+++ b/tests/status/submodules.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "status_helpers.h"
 #include "../submodule/submodule_helpers.h"
 
diff --git a/tests/status/worktree.c b/tests/status/worktree.c
index 4c37a33..7711b2d 100644
--- a/tests/status/worktree.c
+++ b/tests/status/worktree.c
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "ignore.h"
 #include "status_data.h"
 #include "posix.h"
diff --git a/tests/status/worktree_init.c b/tests/status/worktree_init.c
index 9d5cfa5..40f1b2a 100644
--- a/tests/status/worktree_init.c
+++ b/tests/status/worktree_init.c
@@ -1,7 +1,7 @@
 #include "clar_libgit2.h"
 #include "git2/sys/repository.h"
 
-#include "fileops.h"
+#include "futils.h"
 #include "ignore.h"
 #include "status_helpers.h"
 #include "posix.h"
diff --git a/tests/submodule/add.c b/tests/submodule/add.c
index d588677..b251b33 100644
--- a/tests/submodule/add.c
+++ b/tests/submodule/add.c
@@ -3,7 +3,7 @@
 #include "path.h"
 #include "submodule_helpers.h"
 #include "config/config_helpers.h"
-#include "fileops.h"
+#include "futils.h"
 #include "repository.h"
 
 static git_repository *g_repo = NULL;
diff --git a/tests/submodule/escape.c b/tests/submodule/escape.c
index c368742..08eb768 100644
--- a/tests/submodule/escape.c
+++ b/tests/submodule/escape.c
@@ -2,7 +2,7 @@
 #include "posix.h"
 #include "path.h"
 #include "submodule_helpers.h"
-#include "fileops.h"
+#include "futils.h"
 #include "repository.h"
 
 static git_repository *g_repo = NULL;
diff --git a/tests/submodule/init.c b/tests/submodule/init.c
index 84143e1..a1d870b 100644
--- a/tests/submodule/init.c
+++ b/tests/submodule/init.c
@@ -2,7 +2,7 @@
 #include "posix.h"
 #include "path.h"
 #include "submodule_helpers.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *g_repo = NULL;
 
diff --git a/tests/submodule/inject_option.c b/tests/submodule/inject_option.c
index 182f088..cfc02ac 100644
--- a/tests/submodule/inject_option.c
+++ b/tests/submodule/inject_option.c
@@ -2,7 +2,7 @@
 #include "posix.h"
 #include "path.h"
 #include "submodule_helpers.h"
-#include "fileops.h"
+#include "futils.h"
 #include "repository.h"
 
 static git_repository *g_repo = NULL;
diff --git a/tests/submodule/lookup.c b/tests/submodule/lookup.c
index 8bab1b9..6f7506d 100644
--- a/tests/submodule/lookup.c
+++ b/tests/submodule/lookup.c
@@ -2,7 +2,7 @@
 #include "submodule_helpers.h"
 #include "git2/sys/repository.h"
 #include "repository.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *g_repo = NULL;
 
diff --git a/tests/submodule/nosubs.c b/tests/submodule/nosubs.c
index ca2d1d6..e47ee39 100644
--- a/tests/submodule/nosubs.c
+++ b/tests/submodule/nosubs.c
@@ -2,7 +2,7 @@
 
 #include "clar_libgit2.h"
 #include "posix.h"
-#include "fileops.h"
+#include "futils.h"
 
 void test_submodule_nosubs__cleanup(void)
 {
diff --git a/tests/submodule/repository_init.c b/tests/submodule/repository_init.c
index 7dd97ba..9962af3 100644
--- a/tests/submodule/repository_init.c
+++ b/tests/submodule/repository_init.c
@@ -3,7 +3,7 @@
 #include "path.h"
 #include "submodule_helpers.h"
 #include "config/config_helpers.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *g_repo = NULL;
 
diff --git a/tests/submodule/status.c b/tests/submodule/status.c
index 41fc173..06595cc 100644
--- a/tests/submodule/status.c
+++ b/tests/submodule/status.c
@@ -2,7 +2,7 @@
 #include "posix.h"
 #include "path.h"
 #include "submodule_helpers.h"
-#include "fileops.h"
+#include "futils.h"
 #include "iterator.h"
 
 static git_repository *g_repo = NULL;
diff --git a/tests/submodule/update.c b/tests/submodule/update.c
index 08a279a..79353e5 100644
--- a/tests/submodule/update.c
+++ b/tests/submodule/update.c
@@ -2,7 +2,7 @@
 #include "posix.h"
 #include "path.h"
 #include "submodule_helpers.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_repository *g_repo = NULL;
 
diff --git a/tests/win32/longpath.c b/tests/win32/longpath.c
index bf5aac7..80ae08d 100644
--- a/tests/win32/longpath.c
+++ b/tests/win32/longpath.c
@@ -3,7 +3,7 @@
 #include "git2/clone.h"
 #include "clone.h"
 #include "buffer.h"
-#include "fileops.h"
+#include "futils.h"
 
 static git_buf path = GIT_BUF_INIT;