Compare commits
1196 Commits
v2.0.2-rc
...
cf0589f6b3
Author | SHA1 | Date | |
---|---|---|---|
cf0589f6b3 | |||
a72746d491 | |||
a0f6ff6f7d | |||
ca6f919664 | |||
d2a8aef843 | |||
f14b1c7168 | |||
0a08914a01 | |||
031e8e3495 | |||
62489245cb | |||
00844cb89c | |||
c943c1ecd7 | |||
74f9364196 | |||
4fd1e7507a | |||
edb57903bc | |||
c8f4af7455 | |||
7a6a7421cd | |||
cfa96f2476 | |||
1c2759f2d7 | |||
2e858bdd5a | |||
2c8950d5b4 | |||
895464f50d | |||
7a69989275 | |||
a6bfd2306c | |||
447f9a886d | |||
fc2af3f935 | |||
12db0a3753 | |||
a3991e7c76 | |||
ce0e1358fc | |||
ce2bf344f9 | |||
ebb9f59196 | |||
b03060a00f | |||
39996b2dc8 | |||
3fcb846eca | |||
d66c818c1e | |||
0348492f6c | |||
ead3bcde1a | |||
2ca277ddf7 | |||
274471a066 | |||
001f586a24 | |||
e2efb78385 | |||
5018a192d7 | |||
bd821d0a63 | |||
c5e463c366 | |||
c46334b046 | |||
146d301002 | |||
e6ad15889e | |||
7fb2889c74 | |||
f750a52f75 | |||
cf0ff8cf62 | |||
b7f79c4192 | |||
ad4e950005 | |||
18929038fb | |||
890b3e12dc | |||
0a45b51760 | |||
c0a6bde9e5 | |||
e4289295e8 | |||
60b06790a3 | |||
c421e84854 | |||
ba5f6a62c8 | |||
65b7428bdf | |||
f68917c8cc | |||
80fd52625e | |||
9961cb700e | |||
bb983594d5 | |||
eeea09f65a | |||
95b9464c9f | |||
f1ab604fe9 | |||
d9740445dc | |||
69d44c27cc | |||
f8ded1ecd1 | |||
3cae30eedd | |||
e34f0efc79 | |||
c9ac60a2fc | |||
8c8d7b3bf9 | |||
7fa51e906c | |||
a0d653fff7 | |||
2df67abffb | |||
c944039759 | |||
73d1d993d7 | |||
efa5e07549 | |||
72fe3613d3 | |||
a936603e37 | |||
f5c9fb3842 | |||
68e76285fe | |||
f23f214cfc | |||
bfd698fd56 | |||
f6bd64159f | |||
c22594c6ab | |||
5f1d65f1f2 | |||
db0b209ca6 | |||
2017897ad6 | |||
0d7e6284bc | |||
77d985a483 | |||
f68de677c6 | |||
9d00a87851 | |||
4aebc2502d | |||
f1ca91faf1 | |||
fd1ec1c853 | |||
575dbcd7f1 | |||
c420ff1c81 | |||
9af77225f2 | |||
dbf4a58807 | |||
6b58a0e0f7 | |||
7f044442bc | |||
35e6993629 | |||
f82fbf9b55 | |||
5fcb182cb8 | |||
6fc0085292 | |||
3cee38bf92 | |||
f85d0bd333 | |||
bf66bff7b4 | |||
f5668c82a7 | |||
595d638ee0 | |||
e3bf579fd3 | |||
fd137cad90 | |||
6a9acb20dc | |||
29c0a98f01 | |||
b0670976ff | |||
317325aeb8 | |||
13ad145811 | |||
12a373324e | |||
45a444eb29 | |||
fe75412dfe | |||
85136c9af2 | |||
5187f32346 | |||
3a62c389ef | |||
48ed06a255 | |||
7d5d52afe3 | |||
bb9892cc84 | |||
f0c774de5a | |||
555824d913 | |||
cc1000e73b | |||
0d979459a4 | |||
78d7949347 | |||
2fe468826d | |||
8128ac09b3 | |||
3a52dfc4ea | |||
b8b364f292 | |||
a995afa6eb | |||
7415f562ff | |||
3425619773 | |||
1e8a351f67 | |||
2ff18fe98d | |||
06380ccc58 | |||
d93204bfe6 | |||
3b87050dcb | |||
6da907910c | |||
2493a16828 | |||
1bbe5fbef4 | |||
8c9c7254b4 | |||
55a88e7576 | |||
9c9c7cdf8b | |||
fa72388a8b | |||
9eb6a377fd | |||
7567e3289c | |||
f276356172 | |||
7d39fc0667 | |||
56350c8704 | |||
7bd31b1c0a | |||
cf5bb87b6c | |||
31df328be7 | |||
ff8d037474 | |||
031682051f | |||
0e8824a8d2 | |||
f0ddbe7a8c | |||
18c5948e3f | |||
660bc28f0c | |||
9c5166b921 | |||
4a7c76cc1c | |||
1e2fd53b86 | |||
ab09407c3d | |||
9b2310a3e7 | |||
56a56e57c8 | |||
7908e7e982 | |||
92b32b838c | |||
65efa8590f | |||
d70aa968d6 | |||
591cd0ad2d | |||
1bdc78e5e0 | |||
7100708dfd | |||
08379ea622 | |||
161208a1fd | |||
3959067f22 | |||
65096f60b1 | |||
4b32664e46 | |||
cf1ee8db02 | |||
89d4b4245d | |||
1d7d221da1 | |||
b4621f6a4e | |||
c6b895ced2 | |||
5f51a9384e | |||
88736fc58a | |||
be96d79281 | |||
2a28eed7e8 | |||
443aaff217 | |||
b4d3bb083d | |||
b9ce21853f | |||
31e20e9af0 | |||
cfb7a74841 | |||
c8f2485ff0 | |||
62857e1372 | |||
ae3b592cf6 | |||
3365363d23 | |||
f480720665 | |||
d0a8f9df58 | |||
28dc153822 | |||
b265dcf73f | |||
4b9b095104 | |||
ea8eb53a34 | |||
412b807d3f | |||
14cbde2586 | |||
429751e1fc | |||
04f50f7453 | |||
3814b9797d | |||
44d810c398 | |||
c982972ee8 | |||
cfba3d3082 | |||
587527e418 | |||
bb4a3bc6cb | |||
29615d61eb | |||
86f910c865 | |||
2f6a691f65 | |||
ea59ce6dc3 | |||
3cbe39784f | |||
cb2089ccfe | |||
c2bdb884c2 | |||
7daec9d0f5 | |||
a05c642f5e | |||
4c70641d8f | |||
e1939d4d11 | |||
6da5d9f4f0 | |||
401344ac5a | |||
329ba1d5e4 | |||
7faf648919 | |||
8b5369d120 | |||
8af198f7a4 | |||
b1735ab0af | |||
1ab36272f6 | |||
86e5f0359d | |||
ff007bca7f | |||
d03e6e8201 | |||
d481aeae66 | |||
c832d4ce21 | |||
a5a0e690ce | |||
74496016f0 | |||
bb8ff0de59 | |||
c66369f302 | |||
de800f79e9 | |||
c0111d83ae | |||
596b171c2c | |||
99785c0b41 | |||
f2eafe0f14 | |||
5ea9f27645 | |||
6300270a21 | |||
2e587fd897 | |||
f022be6fb9 | |||
8ebf66a686 | |||
ee695eb738 | |||
80d8d6f32f | |||
0b7a9c6a56 | |||
54b70f99cc | |||
fe0fef2f21 | |||
1eec19c583 | |||
6b40658eac | |||
bd836b9ecb | |||
074a026d64 | |||
60864649c0 | |||
d2a26f0c09 | |||
74546807f4 | |||
d7d9199f8e | |||
77299455f9 | |||
0d5ac30e49 | |||
2c55e243f5 | |||
cb2362432e | |||
9c3e464ce4 | |||
4e8e188d24 | |||
e476b4f0c6 | |||
eec286845e | |||
c276cb8979 | |||
58107e6ed8 | |||
eb4c8c6cc0 | |||
0f7dfc6ce7 | |||
a4693f8acc | |||
fc7c6b9705 | |||
43ce2d13ec | |||
6f6f8d4d52 | |||
54fdcf6d80 | |||
fd46d3ef96 | |||
2a15d6b4a3 | |||
acdc165102 | |||
bb4e3c26f4 | |||
8e4a8f0f4b | |||
2fd6f68c97 | |||
f7ca4f8fa3 | |||
4c3d759837 | |||
04daf393d7 | |||
e62477a38e | |||
3338fcf91f | |||
136f76c575 | |||
b94c124869 | |||
1fe7b68f0e | |||
3d9ed2dfe8 | |||
c8cc0feae5 | |||
1d53cd8e8b | |||
73ec7f2252 | |||
5450ffc280 | |||
a9125196ce | |||
ab9765582a | |||
060b2b70dc | |||
739a31538f | |||
67595b4d45 | |||
c5003e0ee6 | |||
984657a5dd | |||
2930933f19 | |||
72a6f5ae08 | |||
7a96a8cbf3 | |||
0b4befd823 | |||
151b6775b0 | |||
47a6bdbcd2 | |||
20ab95380a | |||
73afdaedb9 | |||
a231c2afaf | |||
74109d1195 | |||
2bd847b833 | |||
2d74fb30de | |||
af339e6086 | |||
ae5c4a11a8 | |||
4ce7d76500 | |||
a031f9d867 | |||
2f6fa792df | |||
be0f977dc7 | |||
73efae7c2f | |||
6b67cd676d | |||
2db38a87e3 | |||
213511a77d | |||
a38a033143 | |||
619d5939b3 | |||
68a26d2bc6 | |||
2661885cf2 | |||
6a820837cc | |||
02b74402f4 | |||
3535a61844 | |||
eb4fe4ff60 | |||
793ec5b4a5 | |||
c14b637536 | |||
489d9b1960 | |||
2f60890d29 | |||
19d4b0a247 | |||
69d190e485 | |||
2df84f53ed | |||
876a1e9cd8 | |||
2945793de9 | |||
0de0e511ee | |||
c16d9f9712 | |||
0903d4b83e | |||
0bd1f72017 | |||
7bc1440b8b | |||
9562ac2c62 | |||
9da78b82f3 | |||
8018ce51a0 | |||
3871e44732 | |||
beb1058a51 | |||
259efff707 | |||
3c4a4d8976 | |||
e3ad402853 | |||
470e7b0b07 | |||
cda89d0588 | |||
f5993d472c | |||
0d01862441 | |||
ec2ff87ac7 | |||
fd16a55745 | |||
f1f9e4547d | |||
3238b6d4de | |||
43f0a4b646 | |||
c760b7328b | |||
7d9db55d5d | |||
0741e307cc | |||
38f5374e49 | |||
db1320dd3a | |||
2f8f38b6a2 | |||
0303dcf16a | |||
4c4db56a82 | |||
11c58c4afb | |||
07d0eb0616 | |||
7d74d192f9 | |||
da60c39216 | |||
5ca67b28cf | |||
8247669d3b | |||
55762f9c92 | |||
2a1a48bc68 | |||
d5b47a803c | |||
695a7b0195 | |||
ff13142093 | |||
d6aace8c51 | |||
ec2b8e1854 | |||
884d2d6890 | |||
72899173a0 | |||
79c72d1aef | |||
ab0b1b645b | |||
7eb12d09f9 | |||
ed8ec257cc | |||
c7a28ae526 | |||
c22c68ef28 | |||
d07e1f9cce | |||
158cd55b1a | |||
5fcc59434b | |||
0650790c43 | |||
55debcb643 | |||
ded55057cc | |||
7cb78cab40 | |||
468aba1399 | |||
eba242de7f | |||
fa92540bb9 | |||
b508d98dd7 | |||
4b68e5e4b7 | |||
3f6121839a | |||
5e1745ebfb | |||
b20bc6c28a | |||
9a1483377c | |||
4c97f6b098 | |||
f9af43309d | |||
a77fd75687 | |||
f5b4928818 | |||
25d61b5cd4 | |||
e65e14f796 | |||
6aea801779 | |||
21fd9fe227 | |||
948b0fdd99 | |||
b5cf2de900 | |||
18d05ca635 | |||
b8cd42e235 | |||
4e8ff7815e | |||
57b007759e | |||
8692541e7f | |||
f5b827a039 | |||
3a79cee2f9 | |||
3b68543e32 | |||
7c2a245944 | |||
56e27e3184 | |||
b7c87bed82 | |||
3cfda97c05 | |||
52df12493b | |||
6e7b030afa | |||
afeeb97f05 | |||
5f925d3e71 | |||
26e1975edc | |||
2169456d6a | |||
cca53b2d26 | |||
2a6ecf61b2 | |||
18c53fad9a | |||
84fc05acc0 | |||
c960df8f70 | |||
9d0baf30b8 | |||
312e4bc0f1 | |||
1d7f5b7ef1 | |||
08e381a307 | |||
49e518ac19 | |||
8e2ebf05b8 | |||
924b79add2 | |||
857dcc5535 | |||
7c0d583435 | |||
2b6a88f8cb | |||
fbf31c77ed | |||
9c2aa62f1f | |||
b6456abf0d | |||
5138b0d1ab | |||
0f60a5a467 | |||
982e5357a5 | |||
0ad0ff508b | |||
b4d61649cb | |||
cdfbaa47b6 | |||
211805e460 | |||
841d57cf13 | |||
bd25904371 | |||
3c001c11ae | |||
1f6036ec18 | |||
104e101158 | |||
b281b4c105 | |||
cf6a370eea | |||
8feb244dc9 | |||
f9e2e72d84 | |||
32ef8ba3c3 | |||
2fb53e34af | |||
c72dec6369 | |||
c0b0c5d397 | |||
d34ccc424d | |||
663c89ac53 | |||
414f18a518 | |||
9bfdece859 | |||
ad79c5daf5 | |||
48a1bef1ae | |||
09cb5d8f19 | |||
c216df9b73 | |||
a0a5ca3390 | |||
ae0a921ba8 | |||
3ce03dabf5 | |||
4a530c4703 | |||
c9f9c2a24c | |||
cd538566d3 | |||
f0fe0a1962 | |||
68e3f6fc00 | |||
a23adf6db6 | |||
da5752e971 | |||
40682e37c0 | |||
cbd36efd91 | |||
96c712ae9c | |||
28065c2c8e | |||
9677ebb44e | |||
172ea8bc00 | |||
d2ec6f1f10 | |||
bc7a74e432 | |||
8561278539 | |||
f932799efa | |||
67dedc3fb5 | |||
7120856407 | |||
a1b138ccd1 | |||
d192904f8c | |||
0bd7070ec5 | |||
63ca3089da | |||
39d644e115 | |||
ac89796d5d | |||
4e1250a832 | |||
4049af94dc | |||
ab40037cb4 | |||
66305c3c86 | |||
989d14072d | |||
21d4f4b78d | |||
94b7950cf1 | |||
1fe3f62be4 | |||
43df4356b6 | |||
5440dd3dac | |||
88718de96e | |||
d8d86f3f0c | |||
1ff62fb2b5 | |||
284e2a3ead | |||
3c97c2d953 | |||
196aeae11f | |||
ba2850ea21 | |||
1f4872769d | |||
24c647966b | |||
d3f3048568 | |||
ea249723f9 | |||
52a2df2576 | |||
6645b322bd | |||
7a683a46a9 | |||
cb24252286 | |||
fff3dc4685 | |||
9c01d51334 | |||
9aafb62961 | |||
891040479b | |||
55bcf082ec | |||
67053645e1 | |||
854caffea8 | |||
36e952606b | |||
eba93484c1 | |||
d09d55951d | |||
b35e100bb2 | |||
27b37eb570 | |||
92295506a7 | |||
d20ed07066 | |||
3fa16fd846 | |||
481dfd5ff5 | |||
e5a99943a5 | |||
dbaf379f19 | |||
e1bd3bb8ec | |||
ca834dd119 | |||
163549098d | |||
4800db00d9 | |||
675707b46c | |||
14ebdab034 | |||
8541e292cd | |||
9adec02640 | |||
6a97ad664b | |||
8bb291bbd9 | |||
13a55bff61 | |||
d6efc19ba8 | |||
517e603539 | |||
d144101a7e | |||
b84202a689 | |||
572351067c | |||
9a3d6e725e | |||
d6ac8cfeca | |||
e697363574 | |||
8cc6868480 | |||
37d393c1f9 | |||
ec8b7783f3 | |||
7b375eb912 | |||
ffdea97de3 | |||
7c02d79a5c | |||
46bbc4bf92 | |||
08104c97f7 | |||
8cf169849c | |||
67ac6a6c6e | |||
ef270887fc | |||
d61cb3f0f3 | |||
12d3fbe9a7 | |||
bf9d6157f5 | |||
c4d7868381 | |||
de0a88e45b | |||
fed4f40cfb | |||
d1b4aab952 | |||
072a5356b6 | |||
781278df06 | |||
42a81b1c8e | |||
3e6ed45562 | |||
366fe60e2f | |||
be30230422 | |||
a523d1ca66 | |||
62a75bcddd | |||
bd754a7ee8 | |||
ae98d199e7 | |||
95ff5dd5eb | |||
3f3e9b5735 | |||
82a48fa3b4 | |||
97ce74b798 | |||
91704df08d | |||
4add037dc7 | |||
79314a11b5 | |||
0ff87a0ac3 | |||
1aef67368b | |||
ba2a669be6 | |||
fd721c5dc4 | |||
34070bba89 | |||
1b1fc0fc09 | |||
44a1547d2e | |||
439f9cce3d | |||
9aecec2d96 | |||
26fffdd3e8 | |||
7bf69ec350 | |||
49f884bb68 | |||
a58fcc7f14 | |||
113b5e7258 | |||
5b337d4c65 | |||
0b80e82721 | |||
7e45fa9708 | |||
aa92f3d401 | |||
692c92b0df | |||
51cb2c0b9a | |||
6e52474953 | |||
35db1cd0c4 | |||
739a1103f0 | |||
bb8cbb49f5 | |||
3be29f5b73 | |||
d944569fb2 | |||
3ca27ec566 | |||
779bfc762e | |||
54828600a8 | |||
d5410b88a3 | |||
e86d9fd29b | |||
cbebcfae82 | |||
3dc16db278 | |||
e81227e5f7 | |||
fd83c263e1 | |||
9ca857c98e | |||
afcba6b086 | |||
ef50acc867 | |||
f12833f36c | |||
b26788819e | |||
f905de7c42 | |||
8466a8850f | |||
af8e2cddcb | |||
0089866142 | |||
ca892c7f11 | |||
2a33000ace | |||
bd8da9b987 | |||
5bd780ef07 | |||
25c445b889 | |||
ca4111ac77 | |||
868e8ae124 | |||
51358c7110 | |||
ad97741e1e | |||
5d281e0fd0 | |||
c1a1242398 | |||
5000215973 | |||
ceda21830f | |||
b80b7b482c | |||
8e41f71e70 | |||
72286c865f | |||
2d435457e6 | |||
cef1ff7067 | |||
393dc07de8 | |||
49f0425e56 | |||
7973e523c3 | |||
c4326520cd | |||
dfb9d78448 | |||
26714a836c | |||
59e2986080 | |||
65fc484fa4 | |||
253978bc5f | |||
4aad60f69d | |||
72f7aaf9e4 | |||
d12b5f7b05 | |||
a7239558bd | |||
9d3e4b8767 | |||
cbb99c7b47 | |||
dca0752189 | |||
760a1e4322 | |||
56bc78f63c | |||
60b89c5c08 | |||
fa0f648a0b | |||
5592c663a4 | |||
c847353baf | |||
a140f59acb | |||
b2eae73fb0 | |||
a34dc8f1f8 | |||
92e2937a6b | |||
47757f69bd | |||
b642294193 | |||
8075af364f | |||
3d7285063a | |||
232420621a | |||
a0432be819 | |||
468093227d | |||
32facdc2ff | |||
3a719272cb | |||
9ce4c5a494 | |||
15cc7b0b87 | |||
6d152181d3 | |||
97082fa42c | |||
becd137cf5 | |||
89fc0fb372 | |||
68d79c73cf | |||
d0e9ed4181 | |||
535d2f85ca | |||
5ec20fbcbd | |||
0225fb8e5d | |||
035f830b71 | |||
7a1fb4a790 | |||
4939b05ca7 | |||
2e1f0c8f5f | |||
d8ac596687 | |||
1f43ab3bcc | |||
ef9fbf775c | |||
d6ff728a4d | |||
f6ea8f077b | |||
3e96764fc4 | |||
45b21ae0af | |||
490e49406f | |||
36e7d06b39 | |||
b26b52fd2d | |||
b35041f1f3 | |||
bf7ba3991f | |||
30806c6ebd | |||
29af6e5b7c | |||
cde0e92591 | |||
85b28f7ee3 | |||
df24b99303 | |||
d659a5e04d | |||
99c0246720 | |||
c0dba76ecd | |||
e37a375c18 | |||
6718eb374d | |||
bba7f10703 | |||
df947db055 | |||
256e873e7b | |||
34bc3b759e | |||
853aa2784c | |||
4011ab8080 | |||
07eaad7226 | |||
c743d3c341 | |||
05a5645f4c | |||
7aa71fb202 | |||
6410faa5b4 | |||
a3e578240b | |||
dd492ff52d | |||
e7b576bc45 | |||
7fcc40d0e1 | |||
e6fc6093b2 | |||
73ee70a862 | |||
b647053fb9 | |||
d518e55a67 | |||
fcd38db2ef | |||
89cd8c8fd0 | |||
88c7e7f192 | |||
a00e77d554 | |||
05d5bd9fe5 | |||
e14e7e96c7 | |||
4b8ac300c8 | |||
ee9c5fffad | |||
55caf049b1 | |||
4bdaeaa30d | |||
7c58d9c569 | |||
d6b2c1d81e | |||
4a2acf99a7 | |||
3567941139 | |||
50e7fb612c | |||
03dd9ee579 | |||
2a3c6f3522 | |||
2e46f2fead | |||
b00b72d70f | |||
7dbaf9b8d9 | |||
6b463adbb9 | |||
cb819d7da6 | |||
841ba37841 | |||
7cfefbc512 | |||
9ebba7252c | |||
835c56330a | |||
3e5c70e6b4 | |||
95b88b6ac6 | |||
c1f39afaa3 | |||
1893f7204e | |||
4a062abfde | |||
fb26aa04b6 | |||
7c538b471d | |||
c4c1941fc8 | |||
0ce2be24a3 | |||
3cf60d0d26 | |||
7d33ee80d0 | |||
52ba2de51f | |||
a1b8b57d34 | |||
cf9e0a356c | |||
e66b783df8 | |||
b695200123 | |||
a383fb405e | |||
1cebaf83e1 | |||
4976825bd6 | |||
098d172f40 | |||
f4a3c52428 | |||
2d60b637ec | |||
79b16d9a34 | |||
d69f2fd321 | |||
4015c1bb6e | |||
9f76f20ea8 | |||
b399ff3291 | |||
4fafc17b90 | |||
f1bb88624b | |||
f950e3192f | |||
bef2f078e0 | |||
218053a2be | |||
baca904079 | |||
b5175cb82b | |||
39888a1ebc | |||
ffea22c71b | |||
dd15bb2205 | |||
4b53b5544f | |||
24ca2d3531 | |||
5587e3430b | |||
0c36669fef | |||
bbce86cb9d | |||
ed3a45bfc6 | |||
144fd59c1c | |||
bdc54d7115 | |||
aa04371663 | |||
78ef412516 | |||
28f7f5cb14 | |||
624b92bc97 | |||
ca799298f4 | |||
42b67a7b61 | |||
4de4386142 | |||
509eeca760 | |||
1cb9663776 | |||
26667fdcd6 | |||
681a3eec53 | |||
2a5df890f7 | |||
ae0059591c | |||
8655becf1e | |||
2a3a0aa689 | |||
ce417ec7c8 | |||
4e848a998e | |||
d89f35775e | |||
88ebf72003 | |||
9437b175a2 | |||
302d73a078 | |||
ba7c36e30e | |||
b4da43c87f | |||
f5e078ea3d | |||
8aba39c955 | |||
68a5f90715 | |||
f3dfadddfa | |||
f1ec1fd4a6 | |||
cf59db9cee | |||
e21fbe84ba | |||
1e4d675f76 | |||
e02fe870e9 | |||
9ef9250c18 | |||
2e4b9d3787 | |||
fd2b3c3239 | |||
6640394bd3 | |||
84cc726c4f | |||
5d99d21915 | |||
3b8636544a | |||
14ce60ab65 | |||
7506431b34 | |||
8621209eb3 | |||
d1fe317fb9 | |||
a5c47d3f22 | |||
267c272ce5 | |||
7a8ae32b85 | |||
921d404a5a | |||
de6a7beb5e | |||
5a928208fd | |||
92fc163341 | |||
ca1e03f3ea | |||
de8c3ad603 | |||
f7d56bdd48 | |||
afc13b45f4 | |||
11d2c3c69e | |||
356521e176 | |||
468668e518 | |||
e53dec7bab | |||
26cd6de110 | |||
d1157ca261 | |||
0d49b49482 | |||
753820bd81 | |||
2a98e44a5c | |||
9650d3f56b | |||
aff308f67d | |||
be76d663b5 | |||
160863561f | |||
de02fdb812 | |||
1dda98e337 | |||
ccc6afdfa4 | |||
6b166551af | |||
90694f816f | |||
51636fbac3 | |||
3c7aa417a9 | |||
04d560739d | |||
2c1842f06c | |||
aba487277c | |||
1b95d5dfed | |||
7590fc4f45 | |||
a409408ac0 | |||
b121c9778f | |||
d452761ff9 | |||
dbc5725779 | |||
8b6536c55b | |||
c7318b0383 | |||
26fa85e421 | |||
939742a991 | |||
6ab7386a79 | |||
a750cdc3cb | |||
2f8af0fb08 | |||
7a9802ccb7 | |||
d356d04bf5 | |||
c99c4988ff | |||
6c564eb98b | |||
786d8634cf | |||
70b5204a9f | |||
1d70309a16 | |||
b2aba8c447 | |||
8757b47b35 | |||
b1a7632536 | |||
97c73d5358 | |||
bb3f05aef1 | |||
2001ffc27c | |||
bd2dd4035e | |||
7eb793f577 | |||
b05cedb509 | |||
cd484aa7bb | |||
fbfb528adc | |||
d9cba7f4cc | |||
7d5c5e18c6 | |||
2c0935a771 | |||
5312797b97 | |||
801af6b799 | |||
b42379b519 | |||
8b328b92b1 | |||
2e6ecf8ddb | |||
12c7c48b20 | |||
732a42a073 | |||
5638d5c010 | |||
6a984ac84c | |||
c1eb6b94ed | |||
85135b9267 | |||
670c5bac17 | |||
2dab1426b4 | |||
43004b19c3 | |||
4044d95aaa | |||
c6024c06ce | |||
e56bcb6489 | |||
d9e0164080 | |||
b588cd645e | |||
2c163d7219 | |||
39c53fe903 | |||
7b12d8f9e9 | |||
4649f66c00 | |||
9648abf4b9 | |||
cc1246d0f5 | |||
726aa43a95 | |||
224f983ca8 | |||
f962884341 | |||
6f35cc8bfa | |||
c08c9bc216 | |||
239652be7c | |||
68c9ec0f82 | |||
da07122997 | |||
5fb66dc6ee | |||
0c414fc8a6 | |||
097507a2d9 | |||
466b3fcead | |||
81dc6d1269 | |||
b6c020d35d | |||
dfbe97988f | |||
cd36679a1c | |||
4d555bce96 | |||
d96c6012c5 | |||
15793e714d | |||
437cb94dda | |||
544765e408 | |||
472b1f0da1 | |||
867b2eee40 | |||
5a30b15d1e | |||
0f2c507c30 | |||
c545916332 | |||
ac81f5f624 | |||
50ae7ab558 | |||
a5e29ed745 | |||
6d29170342 | |||
410314022f | |||
815e00d389 | |||
fbf5455f89 | |||
8925704555 | |||
462365dc97 | |||
e73dd52973 | |||
881eec4e02 | |||
bcdfc73767 | |||
0520aa3d40 | |||
c562d17b78 | |||
aee68520b3 | |||
88d8bf63f5 | |||
303887ea37 | |||
51d3d33175 | |||
cdb5ea279d | |||
311e1b318a | |||
31c5b6f1db | |||
a024f81e5d | |||
4089fca87c | |||
99533a9687 | |||
d175a38ad1 | |||
28e918be18 | |||
b4403ff959 | |||
8c548bad92 | |||
6ecad9af72 | |||
df73f9a18f | |||
9b453327a8 | |||
071552ffd5 | |||
33a0b4b295 | |||
21bcd0780c | |||
f6cdf2914c | |||
7698a62c1f | |||
2ae22cdb30 | |||
7705432820 | |||
f150832676 | |||
80c9375d65 | |||
48ddff9e85 | |||
6f64fe02d5 | |||
61ab4d8d58 | |||
3bb962a266 | |||
c286dc4f5c | |||
9d36ded2b3 | |||
71686405e0 | |||
34c4a9c508 | |||
effafd3e91 | |||
5a61bdf2b0 | |||
d21fcfd1c6 | |||
fff9a27362 | |||
ad7872a0e3 | |||
f3ea2ccc21 | |||
e959a9e795 | |||
3fe5eac56d | |||
67191be78d | |||
00cfb67b64 | |||
35aa8f5a94 | |||
f44972b8b3 | |||
94675a3011 | |||
7112fbee7e | |||
ff13633962 | |||
cb93e34de0 | |||
883968f53e | |||
d6d4b579c9 | |||
0e83d84360 | |||
63a6b3bdba | |||
aafa7e112a | |||
804eb7aa5a | |||
eeba641732 | |||
932ea6cb1d | |||
dd4724e374 | |||
e652c9956e | |||
d11767776e | |||
daefa58c0c | |||
7fe7299e7c | |||
0af9c6e8b0 | |||
b9c2113d43 | |||
4fd23de9b6 | |||
3b372ebe86 | |||
d14d149a3b | |||
44acf7dace | |||
da7efdb1a8 | |||
444f39f9ff | |||
fd9c26f016 | |||
7ef9f5cd65 | |||
d3321b3c57 | |||
bbe546008f | |||
5ec91e2d20 | |||
fbe4df0251 | |||
e5c690eb89 | |||
aeedd114a6 | |||
dfa5e0e005 | |||
5911d370e5 | |||
baf769c462 | |||
33e8e0890b | |||
e2e82edefb | |||
da1b5c6953 | |||
629725e262 | |||
6ba4c0091b | |||
99d5261aab | |||
97487cf0c4 | |||
8436f2e2bb | |||
310e436163 | |||
b64477fd7e | |||
782da43114 | |||
37854b693b | |||
7360b72c7b | |||
6f68f268c0 | |||
983587aeb7 | |||
ee415d2e4a | |||
0c075d7fe4 | |||
eec3653c6b | |||
5ac2a24611 | |||
144683d7b3 | |||
9c917a9119 | |||
dc48b84191 | |||
8555d31ddf | |||
cb0dde2a80 | |||
5f5b1f751b | |||
24c5dad929 | |||
f0046fcd57 | |||
3c3e415175 | |||
00d3355f43 | |||
907a14faff | |||
4348e89f99 | |||
7a24cc54f8 | |||
80f6e3c272 | |||
edb1297c4a | |||
1ee157f943 | |||
1b2981b06e | |||
7203fefd33 | |||
d808b2dd19 | |||
ee34a1e361 | |||
1766f91697 | |||
b3aa28d085 | |||
a605d7af11 | |||
19b1a33c48 | |||
04aa511448 | |||
8dc3d4466b | |||
0716a58ff0 | |||
60052081b4 | |||
f11d49b264 | |||
103dae6d08 | |||
821ed7b25e | |||
87f83b6f30 | |||
ace81d797e | |||
57ca2c7c6d | |||
8360d9e045 | |||
560ffbbb6a | |||
72314606f3 | |||
db009b69dd | |||
3ed99dc0ce | |||
762a7c99d5 | |||
4e62156b70 | |||
cc49536755 | |||
54b844dc3b | |||
1e8ba13f66 | |||
93011cee9c | |||
a474a5c73c | |||
17b98ca99d | |||
281eedb71e | |||
1ee533591c | |||
b87e1df140 | |||
f88239a13e | |||
68476cbc00 | |||
f2c1f64f02 | |||
a7209184c8 | |||
ba59e29499 | |||
f94196d865 | |||
bb5a9f9737 | |||
4bc5cf7c64 | |||
639d14452b | |||
e7413fb741 | |||
c0e720498d | |||
383c3b4be6 | |||
e9b202f5c8 | |||
bc3005a6a4 | |||
8cf19e0594 | |||
b137b57dbc | |||
5dff8927da | |||
197e79dd07 | |||
6262aca761 | |||
c156ae704b | |||
a67979ec40 | |||
54bfc11620 | |||
d33c2cd3a2 | |||
3a5f428fb6 | |||
0331152569 | |||
1b7e854f5f | |||
12a945d863 |
@ -161,7 +161,6 @@ openssldir
|
||||
pkgconfig
|
||||
plarge_integer
|
||||
plex
|
||||
println
|
||||
project_enable_fontconfig
|
||||
project_enable_gtkmm
|
||||
project_enable_libdsm
|
||||
|
@ -20,16 +20,14 @@
|
||||
* \#19 \[bug\] Rename file is broken for files that are existing
|
||||
* \#23 \[bug\] Incorrect file size displayed while upload is pending
|
||||
* \#24 RocksDB implementations should be transactional
|
||||
* \#25 Writes should block when maximum cache size is reached
|
||||
* \#26 Complete ring buffer and direct download support
|
||||
|
||||
### Changes from v2.0.1-rc
|
||||
|
||||
* Ability to choose between RocksDB and SQLite databases
|
||||
* Added direct reads and implemented download fallback
|
||||
* Corrected file times on S3 and Sia providers
|
||||
* Corrected handling of `chown()` and `chmod()`
|
||||
* Fixed erroneous download of chunks after resize
|
||||
* Comprehensive WinFSP and FUSE unit tests, including remote testing
|
||||
* Ability to choose between RocksDB and SQLite databases
|
||||
|
||||
## v2.0.1-rc
|
||||
|
||||
|
@ -22,9 +22,11 @@
|
||||
#ifndef REPERTORY_INCLUDE_APP_CONFIG_HPP_
|
||||
#define REPERTORY_INCLUDE_APP_CONFIG_HPP_
|
||||
|
||||
#include "events/event.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "types/remote.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config final {
|
||||
@ -71,6 +73,7 @@ private:
|
||||
std::atomic<database_type> db_type_{database_type::rocksdb};
|
||||
std::atomic<std::uint8_t> download_timeout_secs_;
|
||||
std::atomic<bool> enable_download_timeout_;
|
||||
std::atomic<bool> enable_comm_duration_events_;
|
||||
std::atomic<bool> enable_drive_events_;
|
||||
#if defined(_WIN32)
|
||||
std::atomic<bool> enable_mount_manager_;
|
||||
@ -85,7 +88,7 @@ private:
|
||||
std::atomic<std::uint16_t> med_freq_interval_secs_;
|
||||
std::atomic<std::uint16_t> online_check_retry_secs_;
|
||||
std::atomic<std::uint16_t> orphaned_file_retention_days_;
|
||||
std::atomic<download_type> preferred_download_type_;
|
||||
atomic<download_type> preferred_download_type_;
|
||||
std::atomic<std::uint16_t> retry_read_count_;
|
||||
std::atomic<std::uint16_t> ring_buffer_file_size_;
|
||||
std::atomic<std::uint16_t> task_wait_ms_;
|
||||
@ -112,7 +115,16 @@ private:
|
||||
[[nodiscard]] auto load() -> bool;
|
||||
|
||||
template <typename dest, typename source>
|
||||
auto set_value(dest &dst, const source &src) -> bool;
|
||||
auto set_value(dest &dst, const source &src) -> bool {
|
||||
if (dst.load() == src) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dst = src;
|
||||
config_changed_ = true;
|
||||
save();
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
[[nodiscard]] auto get_api_auth() const -> std::string;
|
||||
@ -131,6 +143,8 @@ public:
|
||||
|
||||
[[nodiscard]] auto get_download_timeout_secs() const -> std::uint8_t;
|
||||
|
||||
[[nodiscard]] auto get_enable_comm_duration_events() const -> bool;
|
||||
|
||||
[[nodiscard]] auto get_enable_download_timeout() const -> bool;
|
||||
|
||||
[[nodiscard]] auto get_enable_drive_events() const -> bool;
|
||||
@ -204,6 +218,8 @@ public:
|
||||
|
||||
void set_enable_download_timeout(bool value);
|
||||
|
||||
void set_enable_comm_duration_events(bool value);
|
||||
|
||||
void set_enable_drive_events(bool value);
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -44,7 +44,6 @@ private:
|
||||
std::unique_ptr<rocksdb::TransactionDB> db_{nullptr};
|
||||
rocksdb::ColumnFamilyHandle *directory_family_{};
|
||||
rocksdb::ColumnFamilyHandle *file_family_{};
|
||||
rocksdb::ColumnFamilyHandle *path_family_{};
|
||||
rocksdb::ColumnFamilyHandle *source_family_{};
|
||||
|
||||
private:
|
||||
@ -67,50 +66,50 @@ private:
|
||||
rocksdb::Transaction *txn) -> rocksdb::Status;
|
||||
|
||||
public:
|
||||
[[nodiscard]] auto
|
||||
add_directory(const std::string &api_path,
|
||||
const std::string &source_path) -> api_error override;
|
||||
[[nodiscard]] auto add_directory(const std::string &api_path,
|
||||
const std::string &source_path)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
add_or_update_file(const i_file_db::file_data &data) -> api_error override;
|
||||
[[nodiscard]] auto add_or_update_file(const i_file_db::file_data &data)
|
||||
-> api_error override;
|
||||
|
||||
void clear() override;
|
||||
|
||||
[[nodiscard]] auto count() const -> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_api_path(const std::string &source_path,
|
||||
std::string &api_path) const -> api_error override;
|
||||
[[nodiscard]] auto get_api_path(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_directory_api_path(const std::string &source_path,
|
||||
std::string &api_path) const -> api_error override;
|
||||
[[nodiscard]] auto get_directory_api_path(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_directory_source_path(const std::string &api_path,
|
||||
std::string &source_path) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_file_api_path(const std::string &source_path,
|
||||
std::string &api_path) const -> api_error override;
|
||||
[[nodiscard]] auto get_file_api_path(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_file_data(const std::string &api_path,
|
||||
i_file_db::file_data &data) const -> api_error override;
|
||||
[[nodiscard]] auto get_file_data(const std::string &api_path,
|
||||
i_file_db::file_data &data) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_file_source_path(const std::string &api_path,
|
||||
std::string &source_path) const -> api_error override;
|
||||
[[nodiscard]] auto get_file_source_path(const std::string &api_path,
|
||||
std::string &source_path) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_item_list() const -> std::vector<i_file_db::file_info> override;
|
||||
[[nodiscard]] auto get_item_list() const
|
||||
-> std::vector<i_file_db::file_info> override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_source_path(const std::string &api_path,
|
||||
std::string &source_path) const -> api_error override;
|
||||
[[nodiscard]] auto get_source_path(const std::string &api_path,
|
||||
std::string &source_path) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
remove_item(const std::string &api_path) -> api_error override;
|
||||
[[nodiscard]] auto remove_item(const std::string &api_path)
|
||||
-> api_error override;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
private:
|
||||
struct open_directory final {
|
||||
std::shared_ptr<directory_iterator> iterator;
|
||||
std::vector<std::uint64_t> handles;
|
||||
std::vector<std::uint64_t> handles{};
|
||||
std::chrono::system_clock::time_point last_update{
|
||||
std::chrono::system_clock::now()};
|
||||
};
|
||||
@ -60,8 +60,8 @@ public:
|
||||
void execute_action(const std::string &api_path,
|
||||
const execute_callback &execute);
|
||||
|
||||
[[nodiscard]] auto get_directory(std::uint64_t handle)
|
||||
-> std::shared_ptr<directory_iterator>;
|
||||
[[nodiscard]] auto
|
||||
get_directory(std::uint64_t handle) -> std::shared_ptr<directory_iterator>;
|
||||
|
||||
[[nodiscard]] auto remove_directory(const std::string &api_path)
|
||||
-> std::shared_ptr<directory_iterator>;
|
||||
|
@ -29,8 +29,6 @@
|
||||
#include "drives/fuse/remotefuse/i_remote_instance.hpp"
|
||||
#include "drives/remote/remote_open_file_table.hpp"
|
||||
#include "drives/winfsp/remotewinfsp/i_remote_instance.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "types/remote.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/base64.hpp"
|
||||
|
@ -44,7 +44,6 @@ using event_consumer = event_system::event_consumer;
|
||||
#define E_FROM_STRING(t) t
|
||||
#define E_FROM_UINT16(t) std::to_string(t)
|
||||
#define E_FROM_UINT64(t) std::to_string(t)
|
||||
#define E_FROM_DOWNLOAD_TYPE(t) download_type_to_string(t)
|
||||
|
||||
#define E_PROP(type, name, short_name, ts) \
|
||||
private: \
|
||||
|
@ -45,7 +45,7 @@ private:
|
||||
private:
|
||||
app_config *cfg_{nullptr};
|
||||
std::uint64_t cache_size_{0U};
|
||||
mutable std::mutex mtx_;
|
||||
std::mutex mtx_;
|
||||
std::condition_variable notify_;
|
||||
stop_type stop_requested_{false};
|
||||
|
||||
@ -58,8 +58,6 @@ public:
|
||||
|
||||
[[nodiscard]] auto shrink(std::uint64_t size) -> api_error;
|
||||
|
||||
[[nodiscard]] auto size() const -> std::uint64_t;
|
||||
|
||||
void stop();
|
||||
};
|
||||
} // namespace repertory
|
||||
|
@ -1,83 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef REPERTORY_INCLUDE_FILE_MANAGER_DIRECT_OPEN_FILE_HPP_
|
||||
#define REPERTORY_INCLUDE_FILE_MANAGER_DIRECT_OPEN_FILE_HPP_
|
||||
|
||||
#include "file_manager/ring_buffer_base.hpp"
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_provider;
|
||||
class i_upload_manager;
|
||||
|
||||
class direct_open_file final : public ring_buffer_base {
|
||||
public:
|
||||
direct_open_file(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi, i_provider &provider);
|
||||
|
||||
~direct_open_file() override;
|
||||
|
||||
public:
|
||||
direct_open_file() = delete;
|
||||
direct_open_file(const direct_open_file &) noexcept = delete;
|
||||
direct_open_file(direct_open_file &&) noexcept = delete;
|
||||
auto operator=(direct_open_file &&) noexcept -> direct_open_file & = delete;
|
||||
auto
|
||||
operator=(const direct_open_file &) noexcept -> direct_open_file & = delete;
|
||||
|
||||
private:
|
||||
std::array<data_buffer, min_ring_size> ring_data_;
|
||||
|
||||
protected:
|
||||
[[nodiscard]] auto on_check_start() -> bool override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
on_chunk_downloaded(std::size_t /* chunk */,
|
||||
const data_buffer & /* buffer */) -> api_error override {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto
|
||||
on_read_chunk(std::size_t chunk, std::size_t read_size,
|
||||
std::uint64_t read_offset, data_buffer &data,
|
||||
std::size_t &bytes_read) -> api_error override;
|
||||
|
||||
[[nodiscard]] auto use_buffer(std::size_t chunk,
|
||||
std::function<api_error(data_buffer &)> func)
|
||||
-> api_error override;
|
||||
|
||||
public:
|
||||
[[nodiscard]] auto native_operation(native_operation_callback /* callback */)
|
||||
-> api_error override {
|
||||
return api_error::not_supported;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto native_operation(std::uint64_t /* new_file_size */,
|
||||
native_operation_callback /* callback */)
|
||||
-> api_error override {
|
||||
return api_error::not_supported;
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_INCLUDE_FILE_MANAGER_DIRECT_OPEN_FILE_HPP_
|
@ -32,6 +32,23 @@ E_SIMPLE2(download_begin, info, true,
|
||||
std::string, dest_path, dest, E_FROM_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE5(download_chunk_begin, debug, true,
|
||||
std::string, api_path, ap, E_FROM_STRING,
|
||||
std::string, dest_path, dest, E_FROM_STRING,
|
||||
std::size_t, chunk, chunk, E_FROM_SIZE_T,
|
||||
std::size_t, total, total, E_FROM_SIZE_T,
|
||||
std::size_t, complete, complete, E_FROM_SIZE_T
|
||||
);
|
||||
|
||||
E_SIMPLE6(download_chunk_end, debug, true,
|
||||
std::string, api_path, ap, E_FROM_STRING,
|
||||
std::string, dest_path, dest, E_FROM_STRING,
|
||||
std::size_t, chunk, chunk, E_FROM_SIZE_T,
|
||||
std::size_t, total, total, E_FROM_SIZE_T,
|
||||
std::size_t, complete, complete, E_FROM_SIZE_T,
|
||||
api_error, result, result, E_FROM_API_FILE_ERROR
|
||||
);
|
||||
|
||||
E_SIMPLE3(download_end, info, true,
|
||||
std::string, api_path, ap, E_FROM_STRING,
|
||||
std::string, dest_path, dest, E_FROM_STRING,
|
||||
@ -74,12 +91,6 @@ E_SIMPLE2(download_resume_removed, debug, true,
|
||||
E_SIMPLE1(item_timeout, trace, true,
|
||||
std::string, api_path, ap, E_FROM_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE3(download_type_selected, debug, true,
|
||||
std::string, api_path, ap, E_FROM_STRING,
|
||||
std::string, source, src, E_FROM_STRING,
|
||||
download_type, download_type, type, E_FROM_DOWNLOAD_TYPE
|
||||
);
|
||||
// clang-format on
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -68,7 +68,7 @@ private:
|
||||
std::unique_ptr<std::thread> upload_thread_;
|
||||
|
||||
private:
|
||||
[[nodiscard]] auto close_all(const std::string &api_path) -> bool;
|
||||
void close_all(const std::string &api_path);
|
||||
|
||||
void close_timed_out_files();
|
||||
|
||||
@ -108,11 +108,6 @@ public:
|
||||
void remove_resume(const std::string &api_path,
|
||||
const std::string &source_path) override;
|
||||
|
||||
static auto remove_source_and_shrink_cache(const std::string &api_path,
|
||||
const std::string &source_path,
|
||||
std::uint64_t file_size,
|
||||
bool allocated) -> bool;
|
||||
|
||||
void remove_upload(const std::string &api_path) override;
|
||||
|
||||
void store_resume(const i_open_file &file) override;
|
||||
|
@ -62,12 +62,8 @@ public:
|
||||
|
||||
[[nodiscard]] virtual auto get_source_path() const -> std::string = 0;
|
||||
|
||||
[[nodiscard]] virtual auto is_complete() const -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto is_directory() const -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto is_write_supported() const -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto has_handle(std::uint64_t handle) const -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
@ -97,8 +93,6 @@ class i_closeable_open_file : public i_open_file {
|
||||
public:
|
||||
virtual void add(std::uint64_t handle, open_file_data ofd) = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_allocated() const -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto can_close() const -> bool = 0;
|
||||
|
||||
virtual auto close() -> bool = 0;
|
||||
@ -106,8 +100,12 @@ public:
|
||||
[[nodiscard]] virtual auto get_handles() const
|
||||
-> std::vector<std::uint64_t> = 0;
|
||||
|
||||
[[nodiscard]] virtual auto is_complete() const -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto is_modified() const -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto is_write_supported() const -> bool = 0;
|
||||
|
||||
virtual void remove(std::uint64_t handle) = 0;
|
||||
|
||||
virtual void remove_all() = 0;
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "file_manager/open_file_base.hpp"
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/types/file/i_file.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_provider;
|
||||
@ -68,55 +67,45 @@ private:
|
||||
i_upload_manager &mgr_;
|
||||
|
||||
private:
|
||||
bool allocated{false};
|
||||
std::unique_ptr<utils::file::i_file> nf_;
|
||||
bool notified_{false};
|
||||
bool notified_ = false;
|
||||
std::size_t read_chunk_{};
|
||||
boost::dynamic_bitset<> read_state_;
|
||||
std::unique_ptr<std::thread> reader_thread_;
|
||||
mutable std::recursive_mutex rw_mtx_;
|
||||
stop_type stop_requested_{false};
|
||||
std::unique_ptr<std::thread> download_thread_;
|
||||
stop_type stop_requested_ = false;
|
||||
|
||||
private:
|
||||
[[nodiscard]] auto adjust_cache_size(std::uint64_t file_size,
|
||||
bool shrink) -> api_error;
|
||||
|
||||
[[nodiscard]] auto check_start() -> api_error;
|
||||
|
||||
void download_chunk(std::size_t chunk, bool skip_active, bool should_reset);
|
||||
|
||||
void download_range(std::size_t begin_chunk, std::size_t end_chunk,
|
||||
void download_range(std::size_t start_chunk, std::size_t end_chunk,
|
||||
bool should_reset);
|
||||
|
||||
void set_modified();
|
||||
|
||||
void set_read_state(std::size_t chunk);
|
||||
void update_background_reader(std::size_t read_chunk);
|
||||
|
||||
void set_read_state(boost::dynamic_bitset<> read_state);
|
||||
|
||||
void update_reader(std::size_t chunk);
|
||||
protected:
|
||||
auto is_download_complete() const -> bool override {
|
||||
return read_state_.all();
|
||||
}
|
||||
|
||||
public:
|
||||
auto close() -> bool override;
|
||||
|
||||
[[nodiscard]] auto get_allocated() const -> bool override;
|
||||
|
||||
[[nodiscard]] auto get_read_state() const -> boost::dynamic_bitset<> override;
|
||||
|
||||
[[nodiscard]] auto get_read_state(std::size_t chunk) const -> bool override;
|
||||
|
||||
[[nodiscard]] auto is_complete() const -> bool override;
|
||||
|
||||
[[nodiscard]] auto is_write_supported() const -> bool override {
|
||||
return true;
|
||||
}
|
||||
auto is_write_supported() const -> bool override { return true; }
|
||||
|
||||
[[nodiscard]] auto
|
||||
native_operation(native_operation_callback callback) -> api_error override;
|
||||
[[nodiscard]] auto native_operation(native_operation_callback callback)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
native_operation(std::uint64_t new_file_size,
|
||||
native_operation_callback callback) -> api_error override;
|
||||
[[nodiscard]] auto native_operation(std::uint64_t new_file_size,
|
||||
native_operation_callback callback)
|
||||
-> api_error override;
|
||||
|
||||
void remove(std::uint64_t handle) override;
|
||||
|
||||
|
@ -24,18 +24,20 @@
|
||||
|
||||
#include "file_manager/i_open_file.hpp"
|
||||
|
||||
#include "utils/types/file/i_file.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_provider;
|
||||
|
||||
class open_file_base : public i_closeable_open_file {
|
||||
public:
|
||||
open_file_base(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi, i_provider &provider, bool disable_io);
|
||||
filesystem_item fsi, i_provider &provider);
|
||||
|
||||
open_file_base(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi,
|
||||
std::map<std::uint64_t, open_file_data> open_data,
|
||||
i_provider &provider, bool disable_io);
|
||||
i_provider &provider);
|
||||
|
||||
~open_file_base() override = default;
|
||||
|
||||
@ -96,7 +98,7 @@ public:
|
||||
[[nodiscard]] auto get_result() -> api_error;
|
||||
};
|
||||
|
||||
private:
|
||||
protected:
|
||||
std::uint64_t chunk_size_;
|
||||
std::uint8_t chunk_timeout_;
|
||||
filesystem_item fsi_;
|
||||
@ -105,19 +107,21 @@ private:
|
||||
i_provider &provider_;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::size_t, std::shared_ptr<download>> active_downloads_;
|
||||
api_error error_{api_error::success};
|
||||
mutable std::mutex error_mtx_;
|
||||
mutable std::recursive_mutex file_mtx_;
|
||||
stop_type io_stop_requested_{false};
|
||||
std::unique_ptr<std::thread> io_thread_;
|
||||
|
||||
protected:
|
||||
std::unordered_map<std::size_t, std::shared_ptr<download>> active_downloads_;
|
||||
mutable std::recursive_mutex file_mtx_;
|
||||
std::atomic<std::chrono::system_clock::time_point> last_access_{
|
||||
std::chrono::system_clock::now()};
|
||||
bool modified_{false};
|
||||
std::unique_ptr<utils::file::i_file> nf_;
|
||||
mutable std::mutex io_thread_mtx_;
|
||||
std::condition_variable io_thread_notify_;
|
||||
std::deque<std::shared_ptr<io_item>> io_thread_queue_;
|
||||
std::atomic<std::chrono::system_clock::time_point> last_access_{
|
||||
std::chrono::system_clock::now(),
|
||||
};
|
||||
bool modified_{false};
|
||||
bool removed_{false};
|
||||
|
||||
private:
|
||||
@ -126,42 +130,11 @@ private:
|
||||
protected:
|
||||
[[nodiscard]] auto do_io(std::function<api_error()> action) -> api_error;
|
||||
|
||||
[[nodiscard]] auto get_active_downloads()
|
||||
-> std::unordered_map<std::size_t, std::shared_ptr<download>> & {
|
||||
return active_downloads_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_mutex() const -> std::recursive_mutex & {
|
||||
return file_mtx_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_last_chunk_size() const -> std::size_t;
|
||||
|
||||
[[nodiscard]] auto get_provider() -> i_provider & { return provider_; }
|
||||
|
||||
[[nodiscard]] auto get_provider() const -> const i_provider & {
|
||||
return provider_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto is_removed() const -> bool;
|
||||
|
||||
void notify_io();
|
||||
virtual auto is_download_complete() const -> bool = 0;
|
||||
|
||||
void reset_timeout();
|
||||
|
||||
auto set_api_error(const api_error &err) -> api_error;
|
||||
|
||||
void set_file_size(std::uint64_t size);
|
||||
|
||||
void set_last_chunk_size(std::size_t size);
|
||||
|
||||
void set_modified(bool modified);
|
||||
|
||||
void set_removed(bool removed);
|
||||
|
||||
void set_source_path(std::string source_path);
|
||||
|
||||
void wait_for_io(stop_type &stop_requested);
|
||||
auto set_api_error(const api_error &e) -> api_error;
|
||||
|
||||
public:
|
||||
void add(std::uint64_t handle, open_file_data ofd) override;
|
||||
@ -170,8 +143,6 @@ public:
|
||||
|
||||
auto close() -> bool override;
|
||||
|
||||
[[nodiscard]] auto get_allocated() const -> bool override { return false; }
|
||||
|
||||
[[nodiscard]] auto get_api_error() const -> api_error;
|
||||
|
||||
[[nodiscard]] auto get_api_path() const -> std::string override;
|
||||
@ -186,23 +157,27 @@ public:
|
||||
|
||||
[[nodiscard]] auto get_handles() const -> std::vector<std::uint64_t> override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_open_data() -> std::map<std::uint64_t, open_file_data> & override;
|
||||
[[nodiscard]] auto get_open_data()
|
||||
-> std::map<std::uint64_t, open_file_data> & override;
|
||||
|
||||
[[nodiscard]] auto get_open_data() const
|
||||
-> const std::map<std::uint64_t, open_file_data> & override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_open_data(std::uint64_t handle) -> open_file_data & override;
|
||||
[[nodiscard]] auto get_open_data(std::uint64_t handle)
|
||||
-> open_file_data & override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_open_data(std::uint64_t handle) const -> const open_file_data & override;
|
||||
[[nodiscard]] auto get_open_data(std::uint64_t handle) const
|
||||
-> const open_file_data & override;
|
||||
|
||||
[[nodiscard]] auto get_open_file_count() const -> std::size_t override;
|
||||
|
||||
[[nodiscard]] auto get_source_path() const -> std::string override;
|
||||
[[nodiscard]] auto get_source_path() const -> std::string override {
|
||||
return fsi_.source_path;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto has_handle(std::uint64_t handle) const -> bool override;
|
||||
[[nodiscard]] auto has_handle(std::uint64_t handle) const -> bool override {
|
||||
return open_data_.find(handle) != open_data_.end();
|
||||
}
|
||||
|
||||
[[nodiscard]] auto is_directory() const -> bool override {
|
||||
return fsi_.directory;
|
||||
|
@ -1,150 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef REPERTORY_INCLUDE_FILE_MANAGER_RING_BUFFER_BASE_HPP_
|
||||
#define REPERTORY_INCLUDE_FILE_MANAGER_RING_BUFFER_BASE_HPP_
|
||||
|
||||
#include "file_manager/open_file_base.hpp"
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/file.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_provider;
|
||||
class i_upload_manager;
|
||||
|
||||
class ring_buffer_base : public open_file_base {
|
||||
public:
|
||||
ring_buffer_base(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi, i_provider &provider,
|
||||
std::size_t ring_size, bool disable_io);
|
||||
|
||||
~ring_buffer_base() override = default;
|
||||
|
||||
public:
|
||||
ring_buffer_base() = delete;
|
||||
ring_buffer_base(const ring_buffer_base &) noexcept = delete;
|
||||
ring_buffer_base(ring_buffer_base &&) noexcept = delete;
|
||||
auto operator=(ring_buffer_base &&) noexcept -> ring_buffer_base & = delete;
|
||||
auto
|
||||
operator=(const ring_buffer_base &) noexcept -> ring_buffer_base & = delete;
|
||||
|
||||
public:
|
||||
static constexpr const auto min_ring_size{5U};
|
||||
|
||||
private:
|
||||
boost::dynamic_bitset<> read_state_;
|
||||
std::size_t total_chunks_;
|
||||
|
||||
private:
|
||||
std::condition_variable chunk_notify_;
|
||||
mutable std::mutex chunk_mtx_;
|
||||
std::mutex read_mtx_;
|
||||
std::unique_ptr<std::thread> reader_thread_;
|
||||
std::size_t ring_begin_{};
|
||||
std::size_t ring_end_{};
|
||||
std::size_t ring_pos_{};
|
||||
stop_type stop_requested_{false};
|
||||
|
||||
private:
|
||||
[[nodiscard]] auto check_start() -> api_error;
|
||||
|
||||
auto download_chunk(std::size_t chunk, bool skip_active) -> api_error;
|
||||
|
||||
void reader_thread();
|
||||
|
||||
void update_position(std::size_t count, bool is_forward);
|
||||
|
||||
protected:
|
||||
[[nodiscard]] auto has_reader_thread() const -> bool {
|
||||
return reader_thread_ != nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_ring_size() const -> std::size_t {
|
||||
return read_state_.size();
|
||||
}
|
||||
|
||||
[[nodiscard]] virtual auto on_check_start() -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
on_chunk_downloaded(std::size_t chunk,
|
||||
const data_buffer &buffer) -> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
on_read_chunk(std::size_t chunk, std::size_t read_size,
|
||||
std::uint64_t read_offset, data_buffer &data,
|
||||
std::size_t &bytes_read) -> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
use_buffer(std::size_t chunk,
|
||||
std::function<api_error(data_buffer &)> func) -> api_error = 0;
|
||||
|
||||
public:
|
||||
auto close() -> bool override;
|
||||
|
||||
void forward(std::size_t count);
|
||||
|
||||
[[nodiscard]] auto get_current_chunk() const -> std::size_t {
|
||||
return ring_pos_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_first_chunk() const -> std::size_t {
|
||||
return ring_begin_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_last_chunk() const -> std::size_t { return ring_end_; }
|
||||
|
||||
[[nodiscard]] auto get_read_state() const -> boost::dynamic_bitset<> override;
|
||||
|
||||
[[nodiscard]] auto get_read_state(std::size_t chunk) const -> bool override;
|
||||
|
||||
[[nodiscard]] auto get_total_chunks() const -> std::size_t {
|
||||
return total_chunks_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto is_complete() const -> bool override { return false; }
|
||||
|
||||
[[nodiscard]] auto is_write_supported() const -> bool override {
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto read(std::size_t read_size, std::uint64_t read_offset,
|
||||
data_buffer &data) -> api_error override;
|
||||
|
||||
[[nodiscard]] auto resize(std::uint64_t /* size */) -> api_error override {
|
||||
return api_error::not_supported;
|
||||
}
|
||||
|
||||
void reverse(std::size_t count);
|
||||
|
||||
void set(std::size_t first_chunk, std::size_t current_chunk);
|
||||
|
||||
void set_api_path(const std::string &api_path) override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
write(std::uint64_t /* write_offset */, const data_buffer & /* data */,
|
||||
std::size_t & /* bytes_written */) -> api_error override {
|
||||
return api_error::not_supported;
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_INCLUDE_FILE_MANAGER_RING_BUFFER_BASE_HPP_
|
@ -22,17 +22,20 @@
|
||||
#ifndef REPERTORY_INCLUDE_FILE_MANAGER_RING_BUFFER_OPEN_FILE_HPP_
|
||||
#define REPERTORY_INCLUDE_FILE_MANAGER_RING_BUFFER_OPEN_FILE_HPP_
|
||||
|
||||
#include "file_manager/ring_buffer_base.hpp"
|
||||
#include "file_manager/open_file_base.hpp"
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/file.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_provider;
|
||||
class i_upload_manager;
|
||||
|
||||
class ring_buffer_open_file final : public ring_buffer_base {
|
||||
class ring_buffer_open_file final : public open_file_base {
|
||||
public:
|
||||
ring_buffer_open_file(std::string buffer_directory, std::uint64_t chunk_size,
|
||||
std::uint8_t chunk_timeout, filesystem_item fsi,
|
||||
i_provider &provider);
|
||||
|
||||
ring_buffer_open_file(std::string buffer_directory, std::uint64_t chunk_size,
|
||||
std::uint8_t chunk_timeout, filesystem_item fsi,
|
||||
i_provider &provider, std::size_t ring_size);
|
||||
@ -43,49 +46,85 @@ public:
|
||||
ring_buffer_open_file() = delete;
|
||||
ring_buffer_open_file(const ring_buffer_open_file &) noexcept = delete;
|
||||
ring_buffer_open_file(ring_buffer_open_file &&) noexcept = delete;
|
||||
auto operator=(ring_buffer_open_file &&) noexcept -> ring_buffer_open_file & =
|
||||
delete;
|
||||
auto operator=(ring_buffer_open_file &&) noexcept
|
||||
-> ring_buffer_open_file & = delete;
|
||||
auto operator=(const ring_buffer_open_file &) noexcept
|
||||
-> ring_buffer_open_file & = delete;
|
||||
|
||||
private:
|
||||
std::string source_path_;
|
||||
boost::dynamic_bitset<> ring_state_;
|
||||
std::size_t total_chunks_;
|
||||
|
||||
private:
|
||||
std::unique_ptr<utils::file::i_file> nf_;
|
||||
std::unique_ptr<std::thread> chunk_forward_thread_;
|
||||
std::unique_ptr<std::thread> chunk_reverse_thread_;
|
||||
std::condition_variable chunk_notify_;
|
||||
mutable std::mutex chunk_mtx_;
|
||||
std::size_t current_chunk_{};
|
||||
std::size_t first_chunk_{};
|
||||
std::size_t last_chunk_;
|
||||
|
||||
private:
|
||||
auto download_chunk(std::size_t chunk) -> api_error;
|
||||
|
||||
void forward_reader_thread(std::size_t count);
|
||||
|
||||
void reverse_reader_thread(std::size_t count);
|
||||
|
||||
protected:
|
||||
[[nodiscard]] auto on_check_start() -> bool override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
on_chunk_downloaded(std::size_t chunk,
|
||||
const data_buffer &buffer) -> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
on_read_chunk(std::size_t chunk, std::size_t read_size,
|
||||
std::uint64_t read_offset, data_buffer &data,
|
||||
std::size_t &bytes_read) -> api_error override;
|
||||
|
||||
[[nodiscard]] auto use_buffer(std::size_t chunk,
|
||||
std::function<api_error(data_buffer &)> func)
|
||||
-> api_error override;
|
||||
auto is_download_complete() const -> bool override;
|
||||
|
||||
public:
|
||||
[[nodiscard]] static auto can_handle_file(std::uint64_t file_size,
|
||||
std::size_t chunk_size,
|
||||
std::size_t ring_size) -> bool;
|
||||
void forward(std::size_t count);
|
||||
|
||||
[[nodiscard]] auto
|
||||
native_operation(native_operation_callback callback) -> api_error override;
|
||||
[[nodiscard]] auto get_current_chunk() const -> std::size_t {
|
||||
return current_chunk_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto native_operation(std::uint64_t /* new_file_size */,
|
||||
native_operation_callback /* callback */)
|
||||
[[nodiscard]] auto get_first_chunk() const -> std::size_t {
|
||||
return first_chunk_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_last_chunk() const -> std::size_t {
|
||||
return last_chunk_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_read_state() const -> boost::dynamic_bitset<> override;
|
||||
|
||||
[[nodiscard]] auto get_read_state(std::size_t chunk) const -> bool override;
|
||||
|
||||
[[nodiscard]] auto get_total_chunks() const -> std::size_t {
|
||||
return total_chunks_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto is_complete() const -> bool override { return true; }
|
||||
|
||||
auto is_write_supported() const -> bool override { return false; }
|
||||
|
||||
[[nodiscard]] auto native_operation(native_operation_callback callback)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto native_operation(std::uint64_t, native_operation_callback)
|
||||
-> api_error override {
|
||||
return api_error::not_supported;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_source_path() const -> std::string override {
|
||||
return source_path_;
|
||||
[[nodiscard]] auto read(std::size_t read_size, std::uint64_t read_offset,
|
||||
data_buffer &data) -> api_error override;
|
||||
|
||||
[[nodiscard]] auto resize(std::uint64_t) -> api_error override {
|
||||
return api_error::not_supported;
|
||||
}
|
||||
|
||||
void reverse(std::size_t count);
|
||||
|
||||
void set(std::size_t first_chunk, std::size_t current_chunk);
|
||||
|
||||
void set_api_path(const std::string &api_path) override;
|
||||
|
||||
[[nodiscard]] auto write(std::uint64_t, const data_buffer &, std::size_t &)
|
||||
-> api_error override {
|
||||
return api_error::not_supported;
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
@ -29,7 +29,7 @@ constexpr const auto default_eviction_delay_mins{1U};
|
||||
constexpr const auto default_high_freq_interval_secs{30U};
|
||||
constexpr const auto default_low_freq_interval_secs{0U * 60U};
|
||||
constexpr const auto default_max_cache_size_bytes{
|
||||
std::uint64_t(20UL * 1024UL * 1024UL * 1024UL),
|
||||
20UL * 1024UL * 1024UL * 1024UL,
|
||||
};
|
||||
constexpr const auto default_max_upload_count{5U};
|
||||
constexpr const auto default_med_freq_interval_secs{2U * 60U};
|
||||
@ -41,8 +41,7 @@ constexpr const auto default_task_wait_ms{100U};
|
||||
constexpr const auto default_timeout_ms{60000U};
|
||||
constexpr const auto max_orphaned_file_retention_days{std::uint16_t(31U)};
|
||||
constexpr const auto max_ring_buffer_file_size{std::uint16_t(1024U)};
|
||||
constexpr const auto min_cache_size_bytes{
|
||||
std::uint64_t(100UL * 1024UL * 1024UL)};
|
||||
constexpr const auto min_cache_size_bytes{100UL * 1024UL * 1024UL};
|
||||
constexpr const auto min_download_timeout_secs{std::uint8_t(5U)};
|
||||
constexpr const auto min_online_check_retry_secs{std::uint16_t(15U)};
|
||||
constexpr const auto min_orphaned_file_retention_days{std::uint16_t(1U)};
|
||||
@ -175,7 +174,6 @@ enum class api_error {
|
||||
bad_address,
|
||||
buffer_overflow,
|
||||
buffer_too_small,
|
||||
cache_not_initialized,
|
||||
comm_error,
|
||||
decryption_error,
|
||||
directory_end_of_files,
|
||||
@ -194,7 +192,6 @@ enum class api_error {
|
||||
invalid_handle,
|
||||
invalid_operation,
|
||||
invalid_ring_buffer_multiple,
|
||||
invalid_ring_buffer_position,
|
||||
invalid_ring_buffer_size,
|
||||
invalid_version,
|
||||
item_exists,
|
||||
@ -231,13 +228,13 @@ enum class database_type {
|
||||
database_type_to_string(const database_type &type) -> std::string;
|
||||
|
||||
enum class download_type {
|
||||
default_,
|
||||
direct,
|
||||
fallback,
|
||||
ring_buffer,
|
||||
};
|
||||
[[nodiscard]] auto download_type_from_string(
|
||||
std::string type,
|
||||
download_type default_type = download_type::default_) -> download_type;
|
||||
download_type default_type = download_type::fallback) -> download_type;
|
||||
|
||||
[[nodiscard]] auto
|
||||
download_type_to_string(const download_type &type) -> std::string;
|
||||
@ -445,6 +442,8 @@ inline constexpr const auto JSON_DATABASE_TYPE{"DatabaseType"};
|
||||
inline constexpr const auto JSON_DIRECTORY{"Directory"};
|
||||
inline constexpr const auto JSON_DOWNLOAD_TIMEOUT_SECS{
|
||||
"DownloadTimeoutSeconds"};
|
||||
inline constexpr const auto JSON_ENABLE_COMM_DURATION_EVENTS{
|
||||
"EnableCommDurationEvents"};
|
||||
inline constexpr const auto JSON_ENABLE_DRIVE_EVENTS{"EnableDriveEvents"};
|
||||
inline constexpr const auto JSON_ENABLE_DOWNLOAD_TIMEOUT{
|
||||
"EnableDownloadTimeout"};
|
||||
@ -618,38 +617,6 @@ template <> struct adl_serializer<std::atomic<repertory::database_type>> {
|
||||
value.store(repertory::database_type_from_string(data.get<std::string>()));
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct adl_serializer<std::atomic<repertory::download_type>> {
|
||||
static void to_json(json &data,
|
||||
const std::atomic<repertory::download_type> &value) {
|
||||
data = repertory::download_type_to_string(value.load());
|
||||
}
|
||||
|
||||
static void from_json(const json &data,
|
||||
std::atomic<repertory::download_type> &value) {
|
||||
value.store(repertory::download_type_from_string(data.get<std::string>()));
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct adl_serializer<repertory::database_type> {
|
||||
static void to_json(json &data, const repertory::database_type &value) {
|
||||
data = repertory::database_type_to_string(value);
|
||||
}
|
||||
|
||||
static void from_json(const json &data, repertory::database_type &value) {
|
||||
value = repertory::database_type_from_string(data.get<std::string>());
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct adl_serializer<repertory::download_type> {
|
||||
static void to_json(json &data, const repertory::download_type &value) {
|
||||
data = repertory::download_type_to_string(value);
|
||||
}
|
||||
|
||||
static void from_json(const json &data, repertory::download_type &value) {
|
||||
value = repertory::download_type_from_string(data.get<std::string>());
|
||||
}
|
||||
};
|
||||
NLOHMANN_JSON_NAMESPACE_END
|
||||
|
||||
#endif // REPERTORY_INCLUDE_TYPES_REPERTORY_HPP_
|
||||
|
@ -21,9 +21,6 @@
|
||||
*/
|
||||
#include "app_config.hpp"
|
||||
|
||||
#include "events/event_system.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "file_manager/cache_size_mgr.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "types/startup_exception.hpp"
|
||||
#include "utils/common.hpp"
|
||||
@ -66,6 +63,7 @@ app_config::app_config(const provider_type &prov,
|
||||
config_changed_(false),
|
||||
download_timeout_secs_(default_download_timeout_ces),
|
||||
enable_download_timeout_(true),
|
||||
enable_comm_duration_events_(false),
|
||||
enable_drive_events_(false),
|
||||
#if defined(_WIN32)
|
||||
enable_mount_manager_(false),
|
||||
@ -80,7 +78,7 @@ app_config::app_config(const provider_type &prov,
|
||||
med_freq_interval_secs_(default_med_freq_interval_secs),
|
||||
online_check_retry_secs_(default_online_check_retry_secs),
|
||||
orphaned_file_retention_days_(default_orphaned_file_retention_days),
|
||||
preferred_download_type_(download_type::default_),
|
||||
preferred_download_type_(download_type::fallback),
|
||||
retry_read_count_(default_retry_read_count),
|
||||
ring_buffer_file_size_(default_ring_buffer_file_size),
|
||||
task_wait_ms_(default_task_wait_ms) {
|
||||
@ -93,11 +91,7 @@ app_config::app_config(const provider_type &prov,
|
||||
auto host_cfg = get_host_config();
|
||||
host_cfg.agent_string = default_agent_name(prov_);
|
||||
host_cfg.api_port = default_api_port(prov_);
|
||||
host_config_ = host_cfg;
|
||||
|
||||
auto rm_cfg = get_remote_mount();
|
||||
rm_cfg.api_port = default_remote_api_port(prov);
|
||||
remote_mount_ = rm_cfg;
|
||||
set_host_config(host_cfg);
|
||||
|
||||
if (not utils::file::directory(data_directory_).create_directory()) {
|
||||
throw startup_exception(
|
||||
@ -126,6 +120,10 @@ app_config::app_config(const provider_type &prov,
|
||||
[this]() { return database_type_to_string(get_database_type()); }},
|
||||
{JSON_DOWNLOAD_TIMEOUT_SECS,
|
||||
[this]() { return std::to_string(get_download_timeout_secs()); }},
|
||||
{JSON_ENABLE_COMM_DURATION_EVENTS,
|
||||
[this]() {
|
||||
return utils::string::from_bool(get_enable_comm_duration_events());
|
||||
}},
|
||||
{JSON_ENABLE_DOWNLOAD_TIMEOUT,
|
||||
[this]() {
|
||||
return utils::string::from_bool(get_enable_download_timeout());
|
||||
@ -278,6 +276,13 @@ app_config::app_config(const provider_type &prov,
|
||||
return std::to_string(get_download_timeout_secs());
|
||||
},
|
||||
},
|
||||
{
|
||||
JSON_ENABLE_COMM_DURATION_EVENTS,
|
||||
[this](const std::string &value) {
|
||||
set_enable_comm_duration_events(utils::string::to_bool(value));
|
||||
return utils::string::from_bool(get_enable_comm_duration_events());
|
||||
},
|
||||
},
|
||||
{
|
||||
JSON_ENABLE_DOWNLOAD_TIMEOUT,
|
||||
[this](const std::string &value) {
|
||||
@ -748,6 +753,10 @@ auto app_config::get_download_timeout_secs() const -> std::uint8_t {
|
||||
return std::max(min_download_timeout_secs, download_timeout_secs_.load());
|
||||
}
|
||||
|
||||
auto app_config::get_enable_comm_duration_events() const -> bool {
|
||||
return enable_comm_duration_events_;
|
||||
}
|
||||
|
||||
auto app_config::get_enable_download_timeout() const -> bool {
|
||||
return enable_download_timeout_;
|
||||
}
|
||||
@ -791,6 +800,7 @@ auto app_config::get_json() const -> json {
|
||||
{JSON_DOWNLOAD_TIMEOUT_SECS, download_timeout_secs_},
|
||||
{JSON_DATABASE_TYPE, db_type_},
|
||||
{JSON_ENABLE_DOWNLOAD_TIMEOUT, enable_download_timeout_},
|
||||
{JSON_ENABLE_COMM_DURATION_EVENTS, enable_comm_duration_events_},
|
||||
{JSON_ENABLE_DRIVE_EVENTS, enable_drive_events_},
|
||||
#if defined(_WIN32)
|
||||
{JSON_ENABLE_MOUNT_MANAGER, enable_mount_manager_},
|
||||
@ -1023,6 +1033,8 @@ auto app_config::load() -> bool {
|
||||
found);
|
||||
get_value(json_document, JSON_ENABLE_DOWNLOAD_TIMEOUT,
|
||||
enable_download_timeout_, found);
|
||||
get_value(json_document, JSON_ENABLE_COMM_DURATION_EVENTS,
|
||||
enable_comm_duration_events_, found);
|
||||
get_value(json_document, JSON_ENABLE_DRIVE_EVENTS, enable_drive_events_,
|
||||
found);
|
||||
#if defined(_WIN32)
|
||||
@ -1089,7 +1101,7 @@ void app_config::save() {
|
||||
recur_mutex_lock lock(read_write_mutex_);
|
||||
|
||||
auto file_path = get_config_file_path();
|
||||
if (not config_changed_ && utils::file::file(file_path).exists()) {
|
||||
if (not(config_changed_ || utils::file::file(file_path).exists())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1129,6 +1141,10 @@ void app_config::set_enable_download_timeout(bool value) {
|
||||
set_value(enable_download_timeout_, value);
|
||||
}
|
||||
|
||||
void app_config::set_enable_comm_duration_events(bool value) {
|
||||
set_value(enable_comm_duration_events_, value);
|
||||
}
|
||||
|
||||
void app_config::set_enable_drive_events(bool value) {
|
||||
set_value(enable_drive_events_, value);
|
||||
}
|
||||
@ -1171,13 +1187,7 @@ void app_config::set_low_frequency_interval_secs(std::uint16_t value) {
|
||||
}
|
||||
|
||||
void app_config::set_max_cache_size_bytes(std::uint64_t value) {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
set_value(max_cache_size_bytes_, value);
|
||||
auto res = cache_size_mgr::instance().shrink(0U);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_error(function_name, res, "failed to shrink cache");
|
||||
}
|
||||
}
|
||||
|
||||
void app_config::set_max_upload_count(std::uint8_t value) {
|
||||
@ -1228,19 +1238,6 @@ void app_config::set_task_wait_ms(std::uint16_t value) {
|
||||
set_value(task_wait_ms_, value);
|
||||
}
|
||||
|
||||
template <typename dest, typename source>
|
||||
auto app_config::set_value(dest &dst, const source &src) -> bool {
|
||||
if (dst.load() == src) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dst = src;
|
||||
config_changed_ = true;
|
||||
save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
auto app_config::set_value_by_name(const std::string &name,
|
||||
const std::string &value) -> std::string {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
@ -44,7 +44,6 @@ void rdb_file_db::create_or_open(bool clear) {
|
||||
families.emplace_back(rocksdb::kDefaultColumnFamilyName,
|
||||
rocksdb::ColumnFamilyOptions());
|
||||
families.emplace_back("file", rocksdb::ColumnFamilyOptions());
|
||||
families.emplace_back("path", rocksdb::ColumnFamilyOptions());
|
||||
families.emplace_back("source", rocksdb::ColumnFamilyOptions());
|
||||
|
||||
auto handles = std::vector<rocksdb::ColumnFamilyHandle *>();
|
||||
@ -53,7 +52,6 @@ void rdb_file_db::create_or_open(bool clear) {
|
||||
std::size_t idx{};
|
||||
directory_family_ = handles.at(idx++);
|
||||
file_family_ = handles.at(idx++);
|
||||
path_family_ = handles.at(idx++);
|
||||
source_family_ = handles.at(idx++);
|
||||
}
|
||||
|
||||
@ -82,11 +80,6 @@ auto rdb_file_db::add_directory(const std::string &api_path,
|
||||
return res;
|
||||
}
|
||||
|
||||
res = txn->Put(path_family_, api_path, source_path);
|
||||
if (not res.ok()) {
|
||||
return res;
|
||||
}
|
||||
|
||||
return txn->Put(source_family_, source_path, api_path);
|
||||
});
|
||||
}
|
||||
@ -121,11 +114,6 @@ auto rdb_file_db::add_or_update_file(const i_file_db::file_data &data)
|
||||
return res;
|
||||
}
|
||||
|
||||
res = txn->Put(path_family_, data.api_path, data.source_path);
|
||||
if (not res.ok()) {
|
||||
return res;
|
||||
}
|
||||
|
||||
return txn->Put(source_family_, data.source_path, data.api_path);
|
||||
});
|
||||
}
|
||||
@ -159,8 +147,9 @@ auto rdb_file_db::get_api_path(const std::string &source_path,
|
||||
});
|
||||
}
|
||||
|
||||
auto rdb_file_db::get_directory_api_path(
|
||||
const std::string &source_path, std::string &api_path) const -> api_error {
|
||||
auto rdb_file_db::get_directory_api_path(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto result = perform_action(function_name, [&]() -> rocksdb::Status {
|
||||
@ -183,8 +172,9 @@ auto rdb_file_db::get_directory_api_path(
|
||||
: result;
|
||||
}
|
||||
|
||||
auto rdb_file_db::get_directory_source_path(
|
||||
const std::string &api_path, std::string &source_path) const -> api_error {
|
||||
auto rdb_file_db::get_directory_source_path(const std::string &api_path,
|
||||
std::string &source_path) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto result = perform_action(function_name, [&]() -> rocksdb::Status {
|
||||
@ -245,8 +235,9 @@ auto rdb_file_db::get_file_data(const std::string &api_path,
|
||||
return result;
|
||||
}
|
||||
|
||||
auto rdb_file_db::get_file_source_path(
|
||||
const std::string &api_path, std::string &source_path) const -> api_error {
|
||||
auto rdb_file_db::get_file_source_path(const std::string &api_path,
|
||||
std::string &source_path) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto result = perform_action(function_name, [&]() -> rocksdb::Status {
|
||||
@ -294,12 +285,17 @@ auto rdb_file_db::get_item_list() const -> std::vector<i_file_db::file_info> {
|
||||
|
||||
auto rdb_file_db::get_source_path(const std::string &api_path,
|
||||
std::string &source_path) const -> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
auto iter = create_iterator(source_family_);
|
||||
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
|
||||
if (iter->value().ToString() != api_path) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return perform_action(function_name, [&]() -> rocksdb::Status {
|
||||
return db_->Get(rocksdb::ReadOptions{}, path_family_, api_path,
|
||||
&source_path);
|
||||
});
|
||||
source_path = iter->key().ToString();
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
return api_error::item_not_found;
|
||||
}
|
||||
|
||||
auto rdb_file_db::perform_action(std::string_view function_name,
|
||||
@ -375,11 +371,6 @@ auto rdb_file_db::remove_item(const std::string &api_path,
|
||||
return res;
|
||||
}
|
||||
|
||||
res = txn->Delete(path_family_, api_path);
|
||||
if (not res.ok()) {
|
||||
return res;
|
||||
}
|
||||
|
||||
res = txn->Delete(directory_family_, api_path);
|
||||
if (not res.ok()) {
|
||||
return res;
|
||||
|
@ -241,8 +241,9 @@ auto rdb_file_mgr_db::remove_resume(const std::string &api_path) -> bool {
|
||||
});
|
||||
}
|
||||
|
||||
auto rdb_file_mgr_db::remove_resume(
|
||||
const std::string &api_path, rocksdb::Transaction *txn) -> rocksdb::Status {
|
||||
auto rdb_file_mgr_db::remove_resume(const std::string &api_path,
|
||||
rocksdb::Transaction *txn)
|
||||
-> rocksdb::Status {
|
||||
return txn->Delete(resume_family_, api_path);
|
||||
}
|
||||
|
||||
@ -283,25 +284,17 @@ auto rdb_file_mgr_db::rename_resume(const std::string &from_api_path,
|
||||
const std::string &to_api_path) -> bool {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
bool not_found{false};
|
||||
std::string value;
|
||||
auto res = perform_action(
|
||||
function_name,
|
||||
[this, &from_api_path, ¬_found, &value]() -> rocksdb::Status {
|
||||
auto result = db_->Get(rocksdb::ReadOptions{}, from_api_path, &value);
|
||||
not_found = result.IsNotFound();
|
||||
return result;
|
||||
function_name, [this, &from_api_path, &value]() -> rocksdb::Status {
|
||||
return db_->Get(rocksdb::ReadOptions{}, from_api_path, &value);
|
||||
});
|
||||
if (not_found) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (not res) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.empty()) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto data = json::parse(value);
|
||||
|
@ -279,12 +279,6 @@ void sqlite_meta_db::remove_api_path(const std::string &api_path) {
|
||||
|
||||
auto sqlite_meta_db::remove_item_meta(const std::string &api_path,
|
||||
const std::string &key) -> api_error {
|
||||
if (key == META_DIRECTORY || key == META_PINNED || key == META_SIZE ||
|
||||
key == META_SOURCE) {
|
||||
// TODO log warning for unsupported attributes
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
api_meta_map meta{};
|
||||
auto res = get_item_meta(api_path, meta);
|
||||
if (res != api_error::success) {
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/time.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
#include <spdlog/fmt/bundled/base.h>
|
||||
|
||||
namespace repertory {
|
||||
auto eviction::check_minimum_requirements(const std::string &file_path)
|
||||
@ -76,8 +75,8 @@ void eviction::service_function() {
|
||||
|
||||
try {
|
||||
std::string api_path;
|
||||
auto res = provider_.get_api_path_from_source(file_path, api_path);
|
||||
if (res != api_error::success) {
|
||||
if (provider_.get_api_path_from_source(file_path, api_path) !=
|
||||
api_error::success) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include "initialize.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "utils/collection.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
@ -81,8 +81,8 @@ auto fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid,
|
||||
struct fuse_file_info * /*file_info*/)
|
||||
-> api_error {
|
||||
#else
|
||||
auto fuse_drive::chown_impl(std::string api_path, uid_t uid,
|
||||
gid_t gid) -> api_error {
|
||||
auto fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid)
|
||||
-> api_error {
|
||||
#endif
|
||||
return check_and_perform(
|
||||
api_path, X_OK, [&](api_meta_map &meta) -> api_error {
|
||||
@ -481,8 +481,8 @@ auto fuse_drive::getattr_impl(std::string api_path, struct stat *unix_st,
|
||||
struct fuse_file_info * /*file_info*/)
|
||||
-> api_error {
|
||||
#else
|
||||
auto fuse_drive::getattr_impl(std::string api_path,
|
||||
struct stat *unix_st) -> api_error {
|
||||
auto fuse_drive::getattr_impl(std::string api_path, struct stat *unix_st)
|
||||
-> api_error {
|
||||
#endif
|
||||
auto parent = utils::path::get_parent_api_path(api_path);
|
||||
|
||||
@ -565,8 +565,8 @@ auto fuse_drive::getxtimes_impl(std::string api_path, struct timespec *bkuptime,
|
||||
#endif // __APPLE__
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto fuse_drive::init_impl(struct fuse_conn_info *conn,
|
||||
struct fuse_config *cfg) -> void * {
|
||||
auto fuse_drive::init_impl(struct fuse_conn_info *conn, struct fuse_config *cfg)
|
||||
-> void * {
|
||||
#else
|
||||
void *fuse_drive::init_impl(struct fuse_conn_info *conn) {
|
||||
#endif
|
||||
@ -800,8 +800,9 @@ auto fuse_drive::release_impl(std::string /*api_path*/,
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto fuse_drive::releasedir_impl(
|
||||
std::string /*api_path*/, struct fuse_file_info *file_info) -> api_error {
|
||||
auto fuse_drive::releasedir_impl(std::string /*api_path*/,
|
||||
struct fuse_file_info *file_info)
|
||||
-> api_error {
|
||||
auto iter = directory_cache_->get_directory(file_info->fh);
|
||||
if (iter == nullptr) {
|
||||
return api_error::invalid_handle;
|
||||
@ -819,8 +820,8 @@ auto fuse_drive::rename_directory(const std::string &from_api_path,
|
||||
}
|
||||
|
||||
auto fuse_drive::rename_file(const std::string &from_api_path,
|
||||
const std::string &to_api_path,
|
||||
bool overwrite) -> int {
|
||||
const std::string &to_api_path, bool overwrite)
|
||||
-> int {
|
||||
auto res = fm_->rename_file(from_api_path, to_api_path, overwrite);
|
||||
errno = std::abs(utils::from_api_error(res));
|
||||
return (res == api_error::success) ? 0 : -1;
|
||||
@ -830,8 +831,8 @@ auto fuse_drive::rename_file(const std::string &from_api_path,
|
||||
auto fuse_drive::rename_impl(std::string from_api_path, std::string to_api_path,
|
||||
unsigned int /*flags*/) -> api_error {
|
||||
#else
|
||||
auto fuse_drive::rename_impl(std::string from_api_path,
|
||||
std::string to_api_path) -> api_error {
|
||||
auto fuse_drive::rename_impl(std::string from_api_path, std::string to_api_path)
|
||||
-> api_error {
|
||||
#endif
|
||||
auto res = check_parent_access(to_api_path, W_OK | X_OK);
|
||||
if (res != api_error::success) {
|
||||
@ -945,15 +946,15 @@ auto fuse_drive::getxattr_impl(std::string api_path, const char *name,
|
||||
}
|
||||
#else // __APPLE__
|
||||
auto fuse_drive::getxattr_impl(std::string api_path, const char *name,
|
||||
char *value, size_t size,
|
||||
int &attribute_size) -> api_error {
|
||||
char *value, size_t size, int &attribute_size)
|
||||
-> api_error {
|
||||
return getxattr_common(api_path, name, value, size, attribute_size, nullptr);
|
||||
}
|
||||
#endif // __APPLE__
|
||||
|
||||
auto fuse_drive::listxattr_impl(std::string api_path, char *buffer, size_t size,
|
||||
int &required_size,
|
||||
bool &return_size) -> api_error {
|
||||
int &required_size, bool &return_size)
|
||||
-> api_error {
|
||||
auto check_size = (size == 0);
|
||||
|
||||
auto res = check_parent_access(api_path, X_OK);
|
||||
@ -993,8 +994,8 @@ auto fuse_drive::listxattr_impl(std::string api_path, char *buffer, size_t size,
|
||||
return res;
|
||||
}
|
||||
|
||||
auto fuse_drive::removexattr_impl(std::string api_path,
|
||||
const char *name) -> api_error {
|
||||
auto fuse_drive::removexattr_impl(std::string api_path, const char *name)
|
||||
-> api_error {
|
||||
std::string attribute_name;
|
||||
#if defined(__APPLE__)
|
||||
auto res = parse_xattr_parameters(name, 0, attribute_name, api_path);
|
||||
@ -1022,8 +1023,8 @@ auto fuse_drive::setxattr_impl(std::string api_path, const char *name,
|
||||
uint32_t position) -> api_error {
|
||||
#else // __APPLE__
|
||||
auto fuse_drive::setxattr_impl(std::string api_path, const char *name,
|
||||
const char *value, size_t size,
|
||||
int flags) -> api_error {
|
||||
const char *value, size_t size, int flags)
|
||||
-> api_error {
|
||||
#endif
|
||||
std::string attribute_name;
|
||||
#if defined(__APPLE__)
|
||||
@ -1101,8 +1102,8 @@ void fuse_drive::set_item_meta(const std::string &api_path,
|
||||
}
|
||||
|
||||
#if defined(__APPLE__)
|
||||
auto fuse_drive::setattr_x_impl(std::string api_path,
|
||||
struct setattr_x *attr) -> api_error {
|
||||
auto fuse_drive::setattr_x_impl(std::string api_path, struct setattr_x *attr)
|
||||
-> api_error {
|
||||
bool exists{};
|
||||
auto res = provider_.is_file(api_path, exists);
|
||||
if (res != api_error::success) {
|
||||
@ -1156,7 +1157,7 @@ auto fuse_drive::setattr_x_impl(std::string api_path,
|
||||
ts[0].tv_sec = attr->acctime.tv_sec;
|
||||
ts[0].tv_nsec = attr->acctime.tv_nsec;
|
||||
} else {
|
||||
struct timeval tv {};
|
||||
struct timeval tv{};
|
||||
gettimeofday(&tv, NULL);
|
||||
ts[0].tv_sec = tv.tv_sec;
|
||||
ts[0].tv_nsec = tv.tv_usec * 1000;
|
||||
@ -1201,8 +1202,9 @@ auto fuse_drive::setattr_x_impl(std::string api_path,
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto fuse_drive::setbkuptime_impl(
|
||||
std::string api_path, const struct timespec *bkuptime) -> api_error {
|
||||
auto fuse_drive::setbkuptime_impl(std::string api_path,
|
||||
const struct timespec *bkuptime)
|
||||
-> api_error {
|
||||
return check_and_perform(
|
||||
api_path, X_OK, [&](api_meta_map &meta) -> api_error {
|
||||
auto nanos = bkuptime->tv_nsec +
|
||||
@ -1238,8 +1240,8 @@ auto fuse_drive::setvolname_impl(const char * /*volname*/) -> api_error {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto fuse_drive::statfs_x_impl(std::string /*api_path*/,
|
||||
struct statfs *stbuf) -> api_error {
|
||||
auto fuse_drive::statfs_x_impl(std::string /*api_path*/, struct statfs *stbuf)
|
||||
-> api_error {
|
||||
if (statfs(&config_.get_cache_directory()[0], stbuf) != 0) {
|
||||
return api_error::os_error;
|
||||
}
|
||||
@ -1264,8 +1266,8 @@ auto fuse_drive::statfs_x_impl(std::string /*api_path*/,
|
||||
return api_error::success;
|
||||
}
|
||||
#else // __APPLE__
|
||||
auto fuse_drive::statfs_impl(std::string /*api_path*/,
|
||||
struct statvfs *stbuf) -> api_error {
|
||||
auto fuse_drive::statfs_impl(std::string /*api_path*/, struct statvfs *stbuf)
|
||||
-> api_error {
|
||||
if (statvfs(config_.get_cache_directory().data(), stbuf) != 0) {
|
||||
return api_error::os_error;
|
||||
}
|
||||
@ -1315,10 +1317,6 @@ auto fuse_drive::truncate_impl(std::string api_path, off_t size) -> api_error {
|
||||
return res;
|
||||
}
|
||||
|
||||
if (not fm_->get_open_file(handle, true, open_file)) {
|
||||
return api_error::invalid_handle;
|
||||
}
|
||||
|
||||
res = open_file->resize(static_cast<std::uint64_t>(size));
|
||||
}
|
||||
|
||||
@ -1349,8 +1347,8 @@ auto fuse_drive::utimens_impl(std::string api_path, const struct timespec tv[2],
|
||||
struct fuse_file_info * /*file_info*/)
|
||||
-> api_error {
|
||||
#else
|
||||
auto fuse_drive::utimens_impl(std::string api_path,
|
||||
const struct timespec tv[2]) -> api_error {
|
||||
auto fuse_drive::utimens_impl(std::string api_path, const struct timespec tv[2])
|
||||
-> api_error {
|
||||
#endif
|
||||
api_meta_map meta;
|
||||
auto res = provider_.get_item_meta(api_path, meta);
|
||||
|
@ -29,11 +29,6 @@
|
||||
|
||||
namespace repertory {
|
||||
// clang-format off
|
||||
E_SIMPLE2(invalid_cache_size, warn, true,
|
||||
std::uint64_t, cache_size, sz, E_FROM_UINT64,
|
||||
std::uint64_t, by, by, E_FROM_UINT64
|
||||
);
|
||||
|
||||
E_SIMPLE2(max_cache_size_reached, warn, true,
|
||||
std::uint64_t, cache_size, sz, E_FROM_UINT64,
|
||||
std::uint64_t, max_cache_size, max, E_FROM_UINT64
|
||||
@ -42,7 +37,6 @@ E_SIMPLE2(max_cache_size_reached, warn, true,
|
||||
|
||||
cache_size_mgr cache_size_mgr::instance_{};
|
||||
|
||||
// TODO add timeout
|
||||
auto cache_size_mgr::expand(std::uint64_t size) -> api_error {
|
||||
if (size == 0U) {
|
||||
return api_error::success;
|
||||
@ -50,24 +44,23 @@ auto cache_size_mgr::expand(std::uint64_t size) -> api_error {
|
||||
|
||||
unique_mutex_lock lock(mtx_);
|
||||
if (cfg_ == nullptr) {
|
||||
return api_error::cache_not_initialized;
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
cache_size_ += size;
|
||||
|
||||
auto max_cache_size = cfg_->get_max_cache_size_bytes();
|
||||
|
||||
auto cache_dir = utils::file::directory{cfg_->get_cache_directory()};
|
||||
while (not stop_requested_ && cache_size_ > max_cache_size &&
|
||||
cache_dir.count() > 1U) {
|
||||
while (not stop_requested_ && cache_size_ > max_cache_size) {
|
||||
event_system::instance().raise<max_cache_size_reached>(cache_size_,
|
||||
max_cache_size);
|
||||
notify_.notify_all();
|
||||
notify_.wait(lock);
|
||||
}
|
||||
|
||||
notify_.notify_all();
|
||||
|
||||
return api_error::success;
|
||||
return stop_requested_ ? api_error::error : api_error::success;
|
||||
}
|
||||
|
||||
void cache_size_mgr::initialize(app_config *cfg) {
|
||||
@ -92,27 +85,21 @@ void cache_size_mgr::initialize(app_config *cfg) {
|
||||
}
|
||||
|
||||
auto cache_size_mgr::shrink(std::uint64_t size) -> api_error {
|
||||
mutex_lock lock(mtx_);
|
||||
if (size == 0U) {
|
||||
notify_.notify_all();
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
mutex_lock lock(mtx_);
|
||||
if (cache_size_ >= size) {
|
||||
cache_size_ -= size;
|
||||
} else {
|
||||
event_system::instance().raise<invalid_cache_size>(cache_size_, size);
|
||||
// TODO raise warning
|
||||
cache_size_ = 0U;
|
||||
}
|
||||
|
||||
notify_.notify_all();
|
||||
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto cache_size_mgr::size() const -> std::uint64_t {
|
||||
mutex_lock lock(mtx_);
|
||||
return cache_size_;
|
||||
return stop_requested_ ? api_error::error : api_error::success;
|
||||
}
|
||||
|
||||
void cache_size_mgr::stop() {
|
||||
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include "file_manager/direct_open_file.hpp"
|
||||
|
||||
#include "file_manager/open_file_base.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
direct_open_file::direct_open_file(std::uint64_t chunk_size,
|
||||
std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi, i_provider &provider)
|
||||
: ring_buffer_base(chunk_size, chunk_timeout, fsi, provider,
|
||||
min_ring_size, true) {}
|
||||
|
||||
direct_open_file::~direct_open_file() {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
close();
|
||||
}
|
||||
|
||||
auto direct_open_file::on_check_start() -> bool {
|
||||
return (get_file_size() == 0U || has_reader_thread());
|
||||
}
|
||||
|
||||
auto direct_open_file::on_read_chunk(std::size_t chunk, std::size_t read_size,
|
||||
std::uint64_t read_offset,
|
||||
data_buffer &data,
|
||||
std::size_t &bytes_read) -> api_error {
|
||||
auto &buffer = ring_data_.at(chunk % get_ring_size());
|
||||
auto begin =
|
||||
std::next(buffer.begin(), static_cast<std::int64_t>(read_offset));
|
||||
auto end = std::next(begin, static_cast<std::int64_t>(read_size));
|
||||
data.insert(data.end(), begin, end);
|
||||
bytes_read = read_size;
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto direct_open_file::use_buffer(std::size_t chunk,
|
||||
std::function<api_error(data_buffer &)> func)
|
||||
-> api_error {
|
||||
return func(ring_data_.at(chunk % get_ring_size()));
|
||||
}
|
||||
} // namespace repertory
|
@ -24,7 +24,6 @@
|
||||
#include "app_config.hpp"
|
||||
#include "db/file_mgr_db.hpp"
|
||||
#include "file_manager/cache_size_mgr.hpp"
|
||||
#include "file_manager/direct_open_file.hpp"
|
||||
#include "file_manager/events.hpp"
|
||||
#include "file_manager/open_file.hpp"
|
||||
#include "file_manager/open_file_base.hpp"
|
||||
@ -39,6 +38,7 @@
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/polling.hpp"
|
||||
#include "utils/time.hpp"
|
||||
|
||||
namespace repertory {
|
||||
file_manager::file_manager(app_config &config, i_provider &provider)
|
||||
@ -73,13 +73,13 @@ void file_manager::close(std::uint64_t handle) {
|
||||
closeable_file->remove(handle);
|
||||
}
|
||||
|
||||
auto file_manager::close_all(const std::string &api_path) -> bool {
|
||||
void file_manager::close_all(const std::string &api_path) {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
unique_recur_mutex_lock file_lock(open_file_mtx_);
|
||||
auto file_iter = open_file_lookup_.find(api_path);
|
||||
if (file_iter == open_file_lookup_.end()) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
auto closeable_file = file_iter->second;
|
||||
@ -88,8 +88,6 @@ auto file_manager::close_all(const std::string &api_path) -> bool {
|
||||
|
||||
closeable_file->remove_all();
|
||||
closeable_file->close();
|
||||
|
||||
return closeable_file->get_allocated();
|
||||
}
|
||||
|
||||
void file_manager::close_timed_out_files() {
|
||||
@ -104,12 +102,12 @@ void file_manager::close_timed_out_files() {
|
||||
}
|
||||
return items;
|
||||
});
|
||||
for (const auto &closeable_file : closeable_list) {
|
||||
for (auto &&closeable_file : closeable_list) {
|
||||
open_file_lookup_.erase(closeable_file->get_api_path());
|
||||
}
|
||||
file_lock.unlock();
|
||||
|
||||
for (auto &closeable_file : closeable_list) {
|
||||
for (auto &&closeable_file : closeable_list) {
|
||||
closeable_file->close();
|
||||
event_system::instance().raise<item_timeout>(
|
||||
closeable_file->get_api_path());
|
||||
@ -142,7 +140,7 @@ auto file_manager::evict_file(const std::string &api_path) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
unique_recur_mutex_lock open_lock(open_file_mtx_);
|
||||
recur_mutex_lock open_lock(open_file_mtx_);
|
||||
if (is_processing(api_path)) {
|
||||
return false;
|
||||
}
|
||||
@ -151,18 +149,8 @@ auto file_manager::evict_file(const std::string &api_path) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
filesystem_item fsi{};
|
||||
auto res = provider_.get_filesystem_item(api_path, false, fsi);
|
||||
if (res != api_error::success) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fsi.source_path.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string pinned;
|
||||
res = provider_.get_item_meta(api_path, META_PINNED, pinned);
|
||||
auto res = provider_.get_item_meta(api_path, META_PINNED, pinned);
|
||||
if (res != api_error::success && res != api_error::item_not_found) {
|
||||
utils::error::raise_api_path_error(std::string{function_name}, api_path,
|
||||
res, "failed to get pinned status");
|
||||
@ -173,22 +161,31 @@ auto file_manager::evict_file(const std::string &api_path) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<i_closeable_open_file> closeable_file;
|
||||
if (open_file_lookup_.contains(api_path)) {
|
||||
closeable_file = open_file_lookup_.at(api_path);
|
||||
std::string source_path{};
|
||||
res = provider_.get_item_meta(api_path, META_SOURCE, source_path);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(std::string{function_name}, api_path,
|
||||
res, "failed to get source path");
|
||||
return false;
|
||||
}
|
||||
if (source_path.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
open_file_lookup_.erase(api_path);
|
||||
open_lock.unlock();
|
||||
|
||||
auto allocated = closeable_file ? closeable_file->get_allocated() : true;
|
||||
closeable_file.reset();
|
||||
|
||||
auto removed = remove_source_and_shrink_cache(api_path, fsi.source_path,
|
||||
fsi.size, allocated);
|
||||
auto file = utils::file::file{source_path};
|
||||
auto file_size = file.size().value_or(0U);
|
||||
auto removed = file.remove();
|
||||
if (removed) {
|
||||
res = cache_size_mgr::instance().shrink(file_size);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(function_name, api_path, res,
|
||||
"failed to shrink cache");
|
||||
}
|
||||
|
||||
event_system::instance().raise<filesystem_item_evicted>(api_path,
|
||||
fsi.source_path);
|
||||
source_path);
|
||||
}
|
||||
|
||||
return removed;
|
||||
@ -219,7 +216,7 @@ auto file_manager::get_open_file_by_handle(std::uint64_t handle) const
|
||||
-> std::shared_ptr<i_closeable_open_file> {
|
||||
auto file_iter =
|
||||
std::find_if(open_file_lookup_.begin(), open_file_lookup_.end(),
|
||||
[&handle](auto &&item) -> bool {
|
||||
[&handle](const auto &item) -> bool {
|
||||
return item.second->has_handle(handle);
|
||||
});
|
||||
return (file_iter == open_file_lookup_.end()) ? nullptr : file_iter->second;
|
||||
@ -235,7 +232,7 @@ auto file_manager::get_open_file_count(const std::string &api_path) const
|
||||
|
||||
auto file_manager::get_open_file(std::uint64_t handle, bool write_supported,
|
||||
std::shared_ptr<i_open_file> &file) -> bool {
|
||||
unique_recur_mutex_lock open_lock(open_file_mtx_);
|
||||
recur_mutex_lock open_lock(open_file_mtx_);
|
||||
auto file_ptr = get_open_file_by_handle(handle);
|
||||
if (not file_ptr) {
|
||||
return false;
|
||||
@ -268,7 +265,7 @@ auto file_manager::get_open_files() const
|
||||
std::unordered_map<std::string, std::size_t> ret;
|
||||
|
||||
recur_mutex_lock open_lock(open_file_mtx_);
|
||||
for (const auto &item : open_file_lookup_) {
|
||||
for (auto &&item : open_file_lookup_) {
|
||||
ret[item.first] = item.second->get_open_file_count();
|
||||
}
|
||||
|
||||
@ -358,19 +355,12 @@ auto file_manager::is_processing(const std::string &api_path) const -> bool {
|
||||
return true;
|
||||
};
|
||||
|
||||
unique_recur_mutex_lock open_lock(open_file_mtx_);
|
||||
recur_mutex_lock open_lock(open_file_mtx_);
|
||||
auto file_iter = open_file_lookup_.find(api_path);
|
||||
if (file_iter == open_file_lookup_.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto closeable_file = file_iter->second;
|
||||
open_lock.unlock();
|
||||
|
||||
return closeable_file->is_write_supported()
|
||||
? closeable_file->is_modified() ||
|
||||
not closeable_file->is_complete()
|
||||
: false;
|
||||
return (file_iter == open_file_lookup_.end())
|
||||
? false
|
||||
: file_iter->second->is_modified() ||
|
||||
not file_iter->second->is_complete();
|
||||
}
|
||||
|
||||
auto file_manager::open(const std::string &api_path, bool directory,
|
||||
@ -384,8 +374,6 @@ auto file_manager::open(
|
||||
const std::string &api_path, bool directory, const open_file_data &ofd,
|
||||
std::uint64_t &handle, std::shared_ptr<i_open_file> &file,
|
||||
std::shared_ptr<i_closeable_open_file> closeable_file) -> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
const auto create_and_add_handle =
|
||||
[&](std::shared_ptr<i_closeable_open_file> cur_file) {
|
||||
handle = get_next_handle();
|
||||
@ -415,99 +403,21 @@ auto file_manager::open(
|
||||
}
|
||||
|
||||
if (not closeable_file) {
|
||||
auto buffer_directory{
|
||||
utils::path::combine(config_.get_data_directory(), {"buffer"}),
|
||||
};
|
||||
|
||||
auto chunk_size{
|
||||
closeable_file = std::make_shared<open_file>(
|
||||
utils::encryption::encrypting_reader::get_data_chunk_size(),
|
||||
};
|
||||
|
||||
auto chunk_timeout = config_.get_enable_download_timeout()
|
||||
? config_.get_download_timeout_secs()
|
||||
: 0U;
|
||||
|
||||
auto ring_buffer_file_size{
|
||||
static_cast<std::uint64_t>(config_.get_ring_buffer_file_size()) *
|
||||
1024UL * 1024UL,
|
||||
};
|
||||
|
||||
auto ring_size{ring_buffer_file_size / chunk_size};
|
||||
|
||||
const auto get_download_type = [&](download_type type) -> download_type {
|
||||
if (directory || fsi.size == 0U || is_processing(api_path)) {
|
||||
return download_type::default_;
|
||||
}
|
||||
|
||||
if (type == download_type::direct) {
|
||||
return type;
|
||||
}
|
||||
|
||||
if (type == download_type::default_) {
|
||||
auto free_space =
|
||||
utils::file::get_free_drive_space(config_.get_cache_directory());
|
||||
if (fsi.size < free_space) {
|
||||
return download_type::default_;
|
||||
}
|
||||
}
|
||||
|
||||
if (not ring_buffer_open_file::can_handle_file(fsi.size, chunk_size,
|
||||
ring_size)) {
|
||||
return download_type::direct;
|
||||
}
|
||||
|
||||
if (not utils::file::directory{buffer_directory}.create_directory()) {
|
||||
utils::error::raise_error(
|
||||
function_name, utils::get_last_error_code(),
|
||||
fmt::format("failed to create buffer directory|sp|{}",
|
||||
buffer_directory));
|
||||
return download_type::direct;
|
||||
}
|
||||
|
||||
auto free_space = utils::file::get_free_drive_space(buffer_directory);
|
||||
if (ring_buffer_file_size < free_space) {
|
||||
return download_type::ring_buffer;
|
||||
}
|
||||
|
||||
return download_type::direct;
|
||||
};
|
||||
|
||||
auto preferred_type = config_.get_preferred_download_type();
|
||||
auto type = get_download_type(directory ? download_type::default_
|
||||
: preferred_type == download_type::default_
|
||||
? download_type::ring_buffer
|
||||
: preferred_type);
|
||||
if (not directory) {
|
||||
event_system::instance().raise<download_type_selected>(
|
||||
fsi.api_path, fsi.source_path, type);
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case repertory::download_type::direct: {
|
||||
closeable_file = std::make_shared<direct_open_file>(
|
||||
chunk_size, chunk_timeout, fsi, provider_);
|
||||
} break;
|
||||
|
||||
case repertory::download_type::ring_buffer: {
|
||||
closeable_file = std::make_shared<ring_buffer_open_file>(
|
||||
buffer_directory, chunk_size, chunk_timeout, fsi, provider_,
|
||||
ring_size);
|
||||
} break;
|
||||
|
||||
default: {
|
||||
closeable_file = std::make_shared<open_file>(chunk_size, chunk_timeout,
|
||||
fsi, provider_, *this);
|
||||
} break;
|
||||
}
|
||||
config_.get_enable_download_timeout()
|
||||
? config_.get_download_timeout_secs()
|
||||
: 0U,
|
||||
fsi, provider_, *this);
|
||||
}
|
||||
|
||||
open_file_lookup_[api_path] = closeable_file;
|
||||
create_and_add_handle(closeable_file);
|
||||
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
void file_manager::queue_upload(const i_open_file &file) {
|
||||
queue_upload(file.get_api_path(), file.get_source_path(), false);
|
||||
return queue_upload(file.get_api_path(), file.get_source_path(), false);
|
||||
}
|
||||
|
||||
void file_manager::queue_upload(const std::string &api_path,
|
||||
@ -516,9 +426,9 @@ void file_manager::queue_upload(const std::string &api_path,
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<mutex_lock> upload_lock;
|
||||
std::unique_ptr<mutex_lock> lock;
|
||||
if (not no_lock) {
|
||||
upload_lock = std::make_unique<mutex_lock>(upload_mtx_);
|
||||
lock = std::make_unique<mutex_lock>(upload_mtx_);
|
||||
}
|
||||
|
||||
remove_upload(api_path, true);
|
||||
@ -542,35 +452,47 @@ void file_manager::queue_upload(const std::string &api_path,
|
||||
auto file_manager::remove_file(const std::string &api_path) -> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
recur_mutex_lock open_lock(open_file_mtx_);
|
||||
|
||||
filesystem_item fsi{};
|
||||
auto res = provider_.get_filesystem_item(api_path, false, fsi);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
auto allocated = close_all(api_path);
|
||||
close_all(api_path);
|
||||
|
||||
unique_mutex_lock upload_lock(upload_mtx_);
|
||||
mutex_lock lock(upload_mtx_);
|
||||
remove_upload(api_path, true);
|
||||
remove_resume(api_path, fsi.source_path, true);
|
||||
upload_notify_.notify_all();
|
||||
upload_lock.unlock();
|
||||
|
||||
recur_mutex_lock open_lock(open_file_mtx_);
|
||||
|
||||
res = provider_.remove_file(api_path);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
remove_source_and_shrink_cache(api_path, fsi.source_path, fsi.size,
|
||||
allocated);
|
||||
auto file = utils::file::file{fsi.source_path};
|
||||
auto file_size = file.size().value_or(0U);
|
||||
if (file.remove()) {
|
||||
res = cache_size_mgr::instance().shrink(file_size);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(function_name, api_path, res,
|
||||
"failed to shrink cache");
|
||||
}
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, fsi.api_path, fsi.source_path,
|
||||
utils::get_last_error_code(), "failed to delete source");
|
||||
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
void file_manager::remove_resume(const std::string &api_path,
|
||||
const std::string &source_path) {
|
||||
remove_resume(api_path, source_path, false);
|
||||
return remove_resume(api_path, source_path, false);
|
||||
}
|
||||
|
||||
void file_manager::remove_resume(const std::string &api_path,
|
||||
@ -579,9 +501,9 @@ void file_manager::remove_resume(const std::string &api_path,
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<mutex_lock> upload_lock;
|
||||
std::unique_ptr<mutex_lock> lock;
|
||||
if (not no_lock) {
|
||||
upload_lock = std::make_unique<mutex_lock>(upload_mtx_);
|
||||
lock = std::make_unique<mutex_lock>(upload_mtx_);
|
||||
}
|
||||
|
||||
if (mgr_db_->remove_resume(api_path)) {
|
||||
@ -594,40 +516,6 @@ void file_manager::remove_resume(const std::string &api_path,
|
||||
}
|
||||
}
|
||||
|
||||
auto file_manager::remove_source_and_shrink_cache(
|
||||
const std::string &api_path, const std::string &source_path,
|
||||
std::uint64_t file_size, bool allocated) -> bool {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto file = utils::file::file{source_path};
|
||||
auto source_size = file.exists() ? file.size().value_or(0U) : 0U;
|
||||
|
||||
if (not file.remove()) {
|
||||
utils::error::raise_api_path_error(function_name, api_path, source_path,
|
||||
utils::get_last_error_code(),
|
||||
"failed to delete source");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (not allocated || source_size == 0U) {
|
||||
auto res = cache_size_mgr::instance().shrink(0U);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(function_name, api_path, source_path,
|
||||
res, "failed to shrink cache");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
auto res = cache_size_mgr::instance().shrink(file_size);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(function_name, api_path, source_path,
|
||||
res, "failed to shrink cache");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void file_manager::remove_upload(const std::string &api_path) {
|
||||
remove_upload(api_path, false);
|
||||
}
|
||||
@ -639,9 +527,9 @@ void file_manager::remove_upload(const std::string &api_path, bool no_lock) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<mutex_lock> upload_lock;
|
||||
std::unique_ptr<mutex_lock> lock;
|
||||
if (not no_lock) {
|
||||
upload_lock = std::make_unique<mutex_lock>(upload_mtx_);
|
||||
lock = std::make_unique<mutex_lock>(upload_mtx_);
|
||||
}
|
||||
|
||||
if (not mgr_db_->remove_upload(api_path)) {
|
||||
@ -907,6 +795,7 @@ void file_manager::stop() {
|
||||
|
||||
stop_requested_ = true;
|
||||
|
||||
polling::instance().remove_callback("db_cleanup");
|
||||
polling::instance().remove_callback("timed_out_close");
|
||||
|
||||
unique_mutex_lock upload_lock(upload_mtx_);
|
||||
@ -920,7 +809,7 @@ void file_manager::stop() {
|
||||
open_file_lookup_.clear();
|
||||
|
||||
upload_lock.lock();
|
||||
for (auto &item : upload_lookup_) {
|
||||
for (auto &&item : upload_lookup_) {
|
||||
item.second->stop();
|
||||
}
|
||||
upload_notify_.notify_all();
|
||||
@ -966,10 +855,10 @@ void file_manager::swap_renamed_items(std::string from_api_path,
|
||||
|
||||
auto file_iter = open_file_lookup_.find(from_api_path);
|
||||
if (file_iter != open_file_lookup_.end()) {
|
||||
auto closeable_file = std::move(open_file_lookup_[from_api_path]);
|
||||
auto ptr = std::move(open_file_lookup_[from_api_path]);
|
||||
open_file_lookup_.erase(from_api_path);
|
||||
closeable_file->set_api_path(to_api_path);
|
||||
open_file_lookup_[to_api_path] = std::move(closeable_file);
|
||||
ptr->set_api_path(to_api_path);
|
||||
open_file_lookup_[to_api_path] = std::move(ptr);
|
||||
}
|
||||
|
||||
if (directory) {
|
||||
|
@ -23,15 +23,17 @@
|
||||
|
||||
#include "file_manager/cache_size_mgr.hpp"
|
||||
#include "file_manager/events.hpp"
|
||||
#include "file_manager/file_manager.hpp"
|
||||
#include "file_manager/i_upload_manager.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/startup_exception.hpp"
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/time.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
open_file::open_file(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
||||
@ -60,246 +62,75 @@ open_file::open_file(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
||||
i_provider &provider,
|
||||
std::optional<boost::dynamic_bitset<>> read_state,
|
||||
i_upload_manager &mgr)
|
||||
: open_file_base(chunk_size, chunk_timeout, fsi, open_data, provider,
|
||||
false),
|
||||
: open_file_base(chunk_size, chunk_timeout, fsi, open_data, provider),
|
||||
mgr_(mgr) {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
if (fsi_.directory && read_state.has_value()) {
|
||||
throw startup_exception("cannot resume a directory|" + fsi.api_path);
|
||||
}
|
||||
|
||||
if (fsi.directory) {
|
||||
if (read_state.has_value()) {
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, fsi.api_path, fsi.source_path,
|
||||
fmt::format("cannot resume a directory|sp|", fsi.api_path));
|
||||
if (not fsi.directory) {
|
||||
nf_ = utils::file::file::open_or_create_file(fsi.source_path,
|
||||
provider_.is_read_only());
|
||||
set_api_error(*nf_ ? api_error::success : api_error::os_error);
|
||||
if (get_api_error() == api_error::success) {
|
||||
if (read_state.has_value()) {
|
||||
read_state_ = read_state.value();
|
||||
set_modified();
|
||||
} else if (fsi_.size > 0U) {
|
||||
read_state_.resize(static_cast<std::size_t>(utils::divide_with_ceiling(
|
||||
fsi_.size, chunk_size)),
|
||||
false);
|
||||
|
||||
auto file_size = nf_->size();
|
||||
if (provider_.is_read_only() || file_size == fsi.size) {
|
||||
read_state_.set(0U, read_state_.size(), true);
|
||||
} else if (not nf_->truncate(fsi.size)) {
|
||||
set_api_error(api_error::os_error);
|
||||
}
|
||||
}
|
||||
|
||||
if (get_api_error() != api_error::success && *nf_) {
|
||||
nf_->close();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
nf_ = utils::file::file::open_or_create_file(fsi.source_path,
|
||||
get_provider().is_read_only());
|
||||
set_api_error(*nf_ ? api_error::success : api_error::os_error);
|
||||
if (get_api_error() != api_error::success) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (read_state.has_value()) {
|
||||
read_state_ = read_state.value();
|
||||
set_modified();
|
||||
allocated = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (fsi.size == 0U) {
|
||||
return;
|
||||
}
|
||||
|
||||
read_state_.resize(static_cast<std::size_t>(
|
||||
utils::divide_with_ceiling(fsi.size, chunk_size)),
|
||||
false);
|
||||
|
||||
auto file_size = nf_->size();
|
||||
if (not file_size.has_value()) {
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, fsi.api_path, fsi.source_path,
|
||||
utils::get_last_error_code(), "failed to get file size");
|
||||
set_api_error(api_error::os_error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (get_provider().is_read_only() || file_size.value() == fsi.size) {
|
||||
read_state_.set(0U, read_state_.size(), true);
|
||||
allocated = true;
|
||||
}
|
||||
|
||||
if (get_api_error() != api_error::success && *nf_) {
|
||||
nf_->close();
|
||||
}
|
||||
}
|
||||
|
||||
open_file::~open_file() { close(); }
|
||||
|
||||
auto open_file::adjust_cache_size(std::uint64_t file_size,
|
||||
bool shrink) -> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
if (file_size == get_file_size()) {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
if (file_size > get_file_size()) {
|
||||
auto size = file_size - get_file_size();
|
||||
auto res = shrink ? cache_size_mgr::instance().shrink(size)
|
||||
: cache_size_mgr::instance().expand(size);
|
||||
if (res == api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, get_api_path(), get_source_path(), res,
|
||||
fmt::format("failed to {} cache|size|{}",
|
||||
(shrink ? "shrink" : "expand"), size));
|
||||
return set_api_error(res);
|
||||
}
|
||||
|
||||
auto size = get_file_size() - file_size;
|
||||
auto res = shrink ? cache_size_mgr::instance().expand(size)
|
||||
: cache_size_mgr::instance().shrink(size);
|
||||
if (res == api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, get_api_path(), get_source_path(), res,
|
||||
fmt::format("failed to {} cache|size|{}", (shrink ? "expand" : "shrink"),
|
||||
size));
|
||||
return set_api_error(res);
|
||||
}
|
||||
|
||||
auto open_file::check_start() -> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
unique_recur_mutex_lock file_lock(get_mutex());
|
||||
if (allocated) {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto file_size = nf_->size();
|
||||
if (not file_size.has_value()) {
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, get_api_path(), get_source_path(),
|
||||
utils::get_last_error_code(), "failed to get file size");
|
||||
return set_api_error(api_error::os_error);
|
||||
}
|
||||
|
||||
if (file_size.value() == get_file_size()) {
|
||||
allocated = true;
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
file_lock.unlock();
|
||||
auto res = adjust_cache_size(file_size.value(), true);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
file_lock.lock();
|
||||
|
||||
if (not nf_->truncate(get_file_size())) {
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, get_api_path(), get_source_path(),
|
||||
utils::get_last_error_code(),
|
||||
fmt::format("failed to truncate file|size|{}", get_file_size()));
|
||||
return set_api_error(res);
|
||||
}
|
||||
|
||||
allocated = true;
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto open_file::close() -> bool {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
if (is_directory() || stop_requested_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
stop_requested_ = true;
|
||||
|
||||
notify_io();
|
||||
|
||||
if (reader_thread_) {
|
||||
reader_thread_->join();
|
||||
reader_thread_.reset();
|
||||
}
|
||||
|
||||
if (not open_file_base::close()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto read_state = get_read_state();
|
||||
auto err = get_api_error();
|
||||
if (err == api_error::success || err == api_error::download_incomplete ||
|
||||
err == api_error::download_stopped) {
|
||||
if (is_modified() && not read_state.all()) {
|
||||
set_api_error(api_error::download_incomplete);
|
||||
} else if (not is_modified() && (get_file_size() > 0U) &&
|
||||
not read_state.all()) {
|
||||
set_api_error(api_error::download_stopped);
|
||||
}
|
||||
|
||||
err = get_api_error();
|
||||
}
|
||||
|
||||
nf_->close();
|
||||
|
||||
if (is_modified()) {
|
||||
if (err == api_error::success) {
|
||||
mgr_.queue_upload(*this);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (err == api_error::download_incomplete) {
|
||||
mgr_.store_resume(*this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (err != api_error::success || read_state.all()) {
|
||||
mgr_.remove_resume(get_api_path(), get_source_path());
|
||||
}
|
||||
|
||||
if (err == api_error::success) {
|
||||
return true;
|
||||
}
|
||||
|
||||
file_manager::remove_source_and_shrink_cache(
|
||||
get_api_path(), get_source_path(), get_file_size(), allocated);
|
||||
|
||||
auto parent = utils::path::get_parent_path(get_source_path());
|
||||
set_source_path(utils::path::combine(parent, {utils::create_uuid_string()}));
|
||||
|
||||
auto res = get_provider().set_item_meta(get_api_path(), META_SOURCE,
|
||||
get_source_path());
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(function_name, get_api_path(),
|
||||
get_source_path(), res,
|
||||
"failed to set new source path");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void open_file::download_chunk(std::size_t chunk, bool skip_active,
|
||||
bool should_reset) {
|
||||
if (should_reset) {
|
||||
reset_timeout();
|
||||
}
|
||||
|
||||
unique_recur_mutex_lock rw_lock(rw_mtx_);
|
||||
auto read_state = get_read_state();
|
||||
if ((get_api_error() == api_error::success) && (chunk < read_state.size()) &&
|
||||
not read_state[chunk]) {
|
||||
if (get_active_downloads().find(chunk) != get_active_downloads().end()) {
|
||||
if (skip_active) {
|
||||
return;
|
||||
unique_recur_mutex_lock download_lock(file_mtx_);
|
||||
if ((get_api_error() == api_error::success) && (chunk < read_state_.size()) &&
|
||||
not read_state_[chunk]) {
|
||||
if (active_downloads_.find(chunk) != active_downloads_.end()) {
|
||||
if (not skip_active) {
|
||||
auto active_download = active_downloads_.at(chunk);
|
||||
download_lock.unlock();
|
||||
|
||||
active_download->wait();
|
||||
}
|
||||
|
||||
auto active_download = get_active_downloads().at(chunk);
|
||||
rw_lock.unlock();
|
||||
|
||||
active_download->wait();
|
||||
return;
|
||||
}
|
||||
|
||||
auto data_offset = chunk * get_chunk_size();
|
||||
auto data_size = (chunk == read_state.size() - 1U) ? get_last_chunk_size()
|
||||
: get_chunk_size();
|
||||
if (get_active_downloads().empty() && (read_state.count() == 0U)) {
|
||||
event_system::instance().raise<download_begin>(get_api_path(),
|
||||
get_source_path());
|
||||
auto data_offset = chunk * chunk_size_;
|
||||
auto data_size =
|
||||
(chunk == read_state_.size() - 1U) ? last_chunk_size_ : chunk_size_;
|
||||
if (active_downloads_.empty() && (read_state_.count() == 0U)) {
|
||||
event_system::instance().raise<download_begin>(fsi_.api_path,
|
||||
fsi_.source_path);
|
||||
}
|
||||
event_system::instance().raise<download_chunk_begin>(
|
||||
fsi_.api_path, fsi_.source_path, chunk, read_state_.size(),
|
||||
read_state_.count());
|
||||
|
||||
get_active_downloads()[chunk] = std::make_shared<download>();
|
||||
rw_lock.unlock();
|
||||
active_downloads_[chunk] = std::make_shared<download>();
|
||||
download_lock.unlock();
|
||||
|
||||
if (should_reset) {
|
||||
reset_timeout();
|
||||
@ -308,28 +139,28 @@ void open_file::download_chunk(std::size_t chunk, bool skip_active,
|
||||
std::async(std::launch::async, [this, chunk, data_size, data_offset,
|
||||
should_reset]() {
|
||||
const auto notify_complete = [this, chunk, should_reset]() {
|
||||
auto state = get_read_state();
|
||||
|
||||
unique_recur_mutex_lock lock(rw_mtx_);
|
||||
auto active_download = get_active_downloads().at(chunk);
|
||||
get_active_downloads().erase(chunk);
|
||||
unique_recur_mutex_lock file_lock(file_mtx_);
|
||||
auto active_download = active_downloads_.at(chunk);
|
||||
active_downloads_.erase(chunk);
|
||||
event_system::instance().raise<download_chunk_end>(
|
||||
fsi_.api_path, fsi_.source_path, chunk, read_state_.size(),
|
||||
read_state_.count(), get_api_error());
|
||||
if (get_api_error() == api_error::success) {
|
||||
auto progress = (static_cast<double>(state.count()) /
|
||||
static_cast<double>(state.size())) *
|
||||
100.0;
|
||||
auto progress = (static_cast<double>(read_state_.count()) /
|
||||
static_cast<double>(read_state_.size()) * 100.0);
|
||||
event_system::instance().raise<download_progress>(
|
||||
get_api_path(), get_source_path(), progress);
|
||||
if (state.all() && not notified_) {
|
||||
fsi_.api_path, fsi_.source_path, progress);
|
||||
if (read_state_.all() && not notified_) {
|
||||
notified_ = true;
|
||||
event_system::instance().raise<download_end>(
|
||||
get_api_path(), get_source_path(), get_api_error());
|
||||
fsi_.api_path, fsi_.source_path, get_api_error());
|
||||
}
|
||||
} else if (not notified_) {
|
||||
notified_ = true;
|
||||
event_system::instance().raise<download_end>(
|
||||
get_api_path(), get_source_path(), get_api_error());
|
||||
fsi_.api_path, fsi_.source_path, get_api_error());
|
||||
}
|
||||
lock.unlock();
|
||||
file_lock.unlock();
|
||||
|
||||
active_download->notify(get_api_error());
|
||||
|
||||
@ -338,9 +169,9 @@ void open_file::download_chunk(std::size_t chunk, bool skip_active,
|
||||
}
|
||||
};
|
||||
|
||||
data_buffer buffer;
|
||||
auto res = get_provider().read_file_bytes(
|
||||
get_api_path(), data_size, data_offset, buffer, stop_requested_);
|
||||
data_buffer data;
|
||||
auto res = provider_.read_file_bytes(get_api_path(), data_size,
|
||||
data_offset, data, stop_requested_);
|
||||
if (res != api_error::success) {
|
||||
set_api_error(res);
|
||||
notify_complete();
|
||||
@ -353,7 +184,7 @@ void open_file::download_chunk(std::size_t chunk, bool skip_active,
|
||||
|
||||
res = do_io([&]() -> api_error {
|
||||
std::size_t bytes_written{};
|
||||
if (not nf_->write(buffer, data_offset, &bytes_written)) {
|
||||
if (not nf_->write(data, data_offset, &bytes_written)) {
|
||||
return api_error::os_error;
|
||||
}
|
||||
|
||||
@ -368,50 +199,48 @@ void open_file::download_chunk(std::size_t chunk, bool skip_active,
|
||||
return;
|
||||
}
|
||||
|
||||
set_read_state(chunk);
|
||||
unique_recur_mutex_lock file_lock(file_mtx_);
|
||||
read_state_.set(chunk);
|
||||
file_lock.unlock();
|
||||
|
||||
notify_complete();
|
||||
}).wait();
|
||||
}
|
||||
}
|
||||
|
||||
void open_file::download_range(std::size_t begin_chunk, std::size_t end_chunk,
|
||||
void open_file::download_range(std::size_t start_chunk, std::size_t end_chunk,
|
||||
bool should_reset) {
|
||||
for (std::size_t chunk = begin_chunk;
|
||||
(get_api_error() == api_error::success) && (chunk <= end_chunk);
|
||||
++chunk) {
|
||||
for (std::size_t chunk = start_chunk; chunk <= end_chunk; ++chunk) {
|
||||
download_chunk(chunk, false, should_reset);
|
||||
if (get_api_error() != api_error::success) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto open_file::get_allocated() const -> bool {
|
||||
recur_mutex_lock file_lock(get_mutex());
|
||||
return allocated;
|
||||
}
|
||||
|
||||
auto open_file::get_read_state() const -> boost::dynamic_bitset<> {
|
||||
recur_mutex_lock file_lock(get_mutex());
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
return read_state_;
|
||||
}
|
||||
|
||||
auto open_file::get_read_state(std::size_t chunk) const -> bool {
|
||||
return get_read_state()[chunk];
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
return read_state_[chunk];
|
||||
}
|
||||
|
||||
auto open_file::is_complete() const -> bool { return get_read_state().all(); }
|
||||
auto open_file::is_complete() const -> bool {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
return read_state_.all();
|
||||
}
|
||||
|
||||
auto open_file::native_operation(
|
||||
i_open_file::native_operation_callback callback) -> api_error {
|
||||
unique_recur_mutex_lock file_lock(file_mtx_);
|
||||
if (stop_requested_) {
|
||||
return set_api_error(api_error::download_stopped);
|
||||
return api_error::download_stopped;
|
||||
}
|
||||
file_lock.unlock();
|
||||
|
||||
auto res = check_start();
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
unique_recur_mutex_lock rw_lock(rw_mtx_);
|
||||
return do_io([&]() -> api_error { return callback(nf_->get_handle()); });
|
||||
}
|
||||
|
||||
@ -420,48 +249,38 @@ auto open_file::native_operation(
|
||||
i_open_file::native_operation_callback callback) -> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
if (is_directory()) {
|
||||
return set_api_error(api_error::invalid_operation);
|
||||
if (fsi_.directory) {
|
||||
return api_error::invalid_operation;
|
||||
}
|
||||
|
||||
unique_recur_mutex_lock file_lock(file_mtx_);
|
||||
if (stop_requested_) {
|
||||
return set_api_error(api_error::download_stopped);
|
||||
}
|
||||
|
||||
auto res = check_start();
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
res = adjust_cache_size(new_file_size, false);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
return api_error::download_stopped;
|
||||
}
|
||||
file_lock.unlock();
|
||||
|
||||
auto is_empty_file = new_file_size == 0U;
|
||||
auto last_chunk = is_empty_file
|
||||
? std::size_t(0U)
|
||||
: static_cast<std::size_t>(utils::divide_with_ceiling(
|
||||
new_file_size, get_chunk_size())) -
|
||||
new_file_size, chunk_size_)) -
|
||||
1U;
|
||||
|
||||
unique_recur_mutex_lock rw_lock(rw_mtx_);
|
||||
auto read_state = get_read_state();
|
||||
if (not is_empty_file && (last_chunk < read_state.size())) {
|
||||
rw_lock.unlock();
|
||||
update_reader(0U);
|
||||
file_lock.lock();
|
||||
if (not is_empty_file && (last_chunk < read_state_.size())) {
|
||||
file_lock.unlock();
|
||||
update_background_reader(0U);
|
||||
|
||||
download_chunk(last_chunk, false, true);
|
||||
if (get_api_error() != api_error::success) {
|
||||
return get_api_error();
|
||||
}
|
||||
rw_lock.lock();
|
||||
file_lock.lock();
|
||||
}
|
||||
|
||||
read_state = get_read_state();
|
||||
auto original_file_size = get_file_size();
|
||||
|
||||
res = do_io([&]() -> api_error { return callback(nf_->get_handle()); });
|
||||
auto res = do_io([&]() -> api_error { return callback(nf_->get_handle()); });
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(function_name, get_api_path(),
|
||||
utils::get_last_error_code(),
|
||||
@ -470,73 +289,59 @@ auto open_file::native_operation(
|
||||
}
|
||||
|
||||
{
|
||||
auto file_size = nf_->size();
|
||||
if (not file_size.has_value()) {
|
||||
auto file_size = nf_->size().value_or(0U);
|
||||
if (file_size != new_file_size) {
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, get_api_path(), api_error::file_size_mismatch,
|
||||
fmt::format("failed to get file size|error|{}",
|
||||
utils::get_last_error_code()));
|
||||
return set_api_error(api_error::error);
|
||||
}
|
||||
|
||||
if (file_size.value() != new_file_size) {
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, get_api_path(), api_error::file_size_mismatch,
|
||||
fmt::format("file size mismatch|expected|{}|actual|{}", new_file_size,
|
||||
file_size.value()));
|
||||
"allocated file size mismatch|expected|" +
|
||||
std::to_string(new_file_size) + "|actual|" +
|
||||
std::to_string(file_size));
|
||||
return set_api_error(api_error::error);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_empty_file || (read_state.size() != (last_chunk + 1U))) {
|
||||
auto old_size = read_state.size();
|
||||
read_state.resize(is_empty_file ? 0U : last_chunk + 1U);
|
||||
if (is_empty_file || (read_state_.size() != (last_chunk + 1U))) {
|
||||
auto old_size = read_state_.size();
|
||||
read_state_.resize(is_empty_file ? 0U : last_chunk + 1U);
|
||||
|
||||
if (not is_empty_file) {
|
||||
for (std::size_t chunk = old_size; chunk <= last_chunk; ++chunk) {
|
||||
read_state.set(chunk);
|
||||
read_state_.set(chunk);
|
||||
}
|
||||
}
|
||||
set_read_state(read_state);
|
||||
|
||||
set_last_chunk_size(static_cast<std::size_t>(
|
||||
new_file_size <= get_chunk_size() ? new_file_size
|
||||
: (new_file_size % get_chunk_size()) == 0U
|
||||
? get_chunk_size()
|
||||
: new_file_size % get_chunk_size()));
|
||||
last_chunk_size_ = static_cast<std::size_t>(
|
||||
new_file_size <= chunk_size_ ? new_file_size
|
||||
: (new_file_size % chunk_size_) == 0U ? chunk_size_
|
||||
: new_file_size % chunk_size_);
|
||||
}
|
||||
|
||||
if (original_file_size == new_file_size) {
|
||||
return res;
|
||||
}
|
||||
set_modified();
|
||||
if (original_file_size != new_file_size) {
|
||||
set_modified();
|
||||
|
||||
set_file_size(new_file_size);
|
||||
auto now = std::to_string(utils::time::get_time_now());
|
||||
res = get_provider().set_item_meta(
|
||||
get_api_path(), {
|
||||
{META_CHANGED, now},
|
||||
{META_MODIFIED, now},
|
||||
{META_SIZE, std::to_string(new_file_size)},
|
||||
{META_WRITTEN, now},
|
||||
});
|
||||
if (res == api_error::success) {
|
||||
return res;
|
||||
fsi_.size = new_file_size;
|
||||
auto now = std::to_string(utils::time::get_time_now());
|
||||
res = provider_.set_item_meta(
|
||||
fsi_.api_path, {
|
||||
{META_CHANGED, now},
|
||||
{META_MODIFIED, now},
|
||||
{META_SIZE, std::to_string(new_file_size)},
|
||||
{META_WRITTEN, now},
|
||||
});
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(function_name, get_api_path(), res,
|
||||
"failed to set file meta");
|
||||
return set_api_error(res);
|
||||
}
|
||||
}
|
||||
|
||||
utils::error::raise_api_path_error(function_name, get_api_path(), res,
|
||||
"failed to set file meta");
|
||||
return set_api_error(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
auto open_file::read(std::size_t read_size, std::uint64_t read_offset,
|
||||
data_buffer &data) -> api_error {
|
||||
if (is_directory()) {
|
||||
return set_api_error(api_error::invalid_operation);
|
||||
}
|
||||
|
||||
if (stop_requested_) {
|
||||
return set_api_error(api_error::download_stopped);
|
||||
if (fsi_.directory) {
|
||||
return api_error::invalid_operation;
|
||||
}
|
||||
|
||||
read_size =
|
||||
@ -545,17 +350,12 @@ auto open_file::read(std::size_t read_size, std::uint64_t read_offset,
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto res = check_start();
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
const auto read_from_source = [this, &data, &read_offset,
|
||||
&read_size]() -> api_error {
|
||||
return do_io([this, &data, &read_offset, &read_size]() -> api_error {
|
||||
if (get_provider().is_read_only()) {
|
||||
return get_provider().read_file_bytes(
|
||||
get_api_path(), read_size, read_offset, data, stop_requested_);
|
||||
if (provider_.is_read_only()) {
|
||||
return provider_.read_file_bytes(fsi_.api_path, read_size, read_offset,
|
||||
data, stop_requested_);
|
||||
}
|
||||
|
||||
data.resize(read_size);
|
||||
@ -566,48 +366,49 @@ auto open_file::read(std::size_t read_size, std::uint64_t read_offset,
|
||||
});
|
||||
};
|
||||
|
||||
if (get_read_state().all()) {
|
||||
unique_recur_mutex_lock file_lock(file_mtx_);
|
||||
if (read_state_.all()) {
|
||||
reset_timeout();
|
||||
return read_from_source();
|
||||
}
|
||||
file_lock.unlock();
|
||||
|
||||
auto begin_chunk = static_cast<std::size_t>(read_offset / get_chunk_size());
|
||||
auto start_chunk = static_cast<std::size_t>(read_offset / chunk_size_);
|
||||
auto end_chunk =
|
||||
static_cast<std::size_t>((read_size + read_offset) / get_chunk_size());
|
||||
static_cast<std::size_t>((read_size + read_offset) / chunk_size_);
|
||||
|
||||
update_reader(begin_chunk);
|
||||
update_background_reader(start_chunk);
|
||||
|
||||
download_range(begin_chunk, end_chunk, true);
|
||||
download_range(start_chunk, end_chunk, true);
|
||||
if (get_api_error() != api_error::success) {
|
||||
return get_api_error();
|
||||
}
|
||||
|
||||
unique_recur_mutex_lock rw_lock(rw_mtx_);
|
||||
file_lock.lock();
|
||||
return get_api_error() == api_error::success ? read_from_source()
|
||||
: get_api_error();
|
||||
}
|
||||
|
||||
void open_file::remove(std::uint64_t handle) {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
open_file_base::remove(handle);
|
||||
|
||||
recur_mutex_lock rw_lock(rw_mtx_);
|
||||
if (is_modified() && get_read_state().all() &&
|
||||
if (modified_ && read_state_.all() &&
|
||||
(get_api_error() == api_error::success)) {
|
||||
mgr_.queue_upload(*this);
|
||||
open_file_base::set_modified(false);
|
||||
modified_ = false;
|
||||
}
|
||||
|
||||
if (is_removed() && (get_open_file_count() == 0U)) {
|
||||
open_file_base::set_removed(false);
|
||||
if (removed_ && (get_open_file_count() == 0U)) {
|
||||
removed_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
void open_file::remove_all() {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
open_file_base::remove_all();
|
||||
|
||||
recur_mutex_lock rw_lock(rw_mtx_);
|
||||
open_file_base::set_modified(false);
|
||||
open_file_base::set_removed(true);
|
||||
modified_ = false;
|
||||
removed_ = true;
|
||||
|
||||
mgr_.remove_upload(get_api_path());
|
||||
|
||||
@ -615,14 +416,26 @@ void open_file::remove_all() {
|
||||
}
|
||||
|
||||
auto open_file::resize(std::uint64_t new_file_size) -> api_error {
|
||||
if (is_directory()) {
|
||||
return set_api_error(api_error::invalid_operation);
|
||||
if (fsi_.directory) {
|
||||
return api_error::invalid_operation;
|
||||
}
|
||||
|
||||
if (new_file_size == get_file_size()) {
|
||||
if (new_file_size == fsi_.size) {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
if (new_file_size > fsi_.size) {
|
||||
auto res = cache_size_mgr::instance().expand(new_file_size - fsi_.size);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
} else {
|
||||
auto res = cache_size_mgr::instance().shrink(fsi_.size - new_file_size);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
return native_operation(
|
||||
new_file_size, [this, &new_file_size](native_handle) -> api_error {
|
||||
return nf_->truncate(new_file_size) ? api_error::success
|
||||
@ -630,62 +443,135 @@ auto open_file::resize(std::uint64_t new_file_size) -> api_error {
|
||||
});
|
||||
}
|
||||
|
||||
auto open_file::close() -> bool {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
if (fsi_.directory || stop_requested_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
stop_requested_ = true;
|
||||
|
||||
unique_mutex_lock reader_lock(io_thread_mtx_);
|
||||
io_thread_notify_.notify_all();
|
||||
reader_lock.unlock();
|
||||
|
||||
if (reader_thread_) {
|
||||
reader_thread_->join();
|
||||
reader_thread_.reset();
|
||||
}
|
||||
|
||||
if (not open_file_base::close()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto err = get_api_error();
|
||||
if (err == api_error::success || err == api_error::download_incomplete ||
|
||||
err == api_error::download_stopped) {
|
||||
if (modified_ && not read_state_.all()) {
|
||||
set_api_error(api_error::download_incomplete);
|
||||
} else if (not modified_ && (fsi_.size > 0U) && not read_state_.all()) {
|
||||
set_api_error(api_error::download_stopped);
|
||||
}
|
||||
|
||||
err = get_api_error();
|
||||
}
|
||||
|
||||
nf_->close();
|
||||
|
||||
if (modified_) {
|
||||
if (err == api_error::success) {
|
||||
mgr_.queue_upload(*this);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (err == api_error::download_incomplete) {
|
||||
mgr_.store_resume(*this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (err != api_error::success || read_state_.all()) {
|
||||
mgr_.remove_resume(fsi_.api_path, get_source_path());
|
||||
}
|
||||
|
||||
if (err == api_error::success) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto file = utils::file::file{fsi_.source_path};
|
||||
auto file_size = file.size().value_or(0U);
|
||||
if (file.remove()) {
|
||||
auto res = cache_size_mgr::instance().shrink(file_size);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(function_name, fsi_.api_path,
|
||||
fsi_.source_path, res,
|
||||
"failed to shrink cache");
|
||||
}
|
||||
} else {
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, fsi_.api_path, fsi_.source_path,
|
||||
utils::get_last_error_code(), "failed to delete source file");
|
||||
}
|
||||
|
||||
auto parent = utils::path::get_parent_path(fsi_.source_path);
|
||||
fsi_.source_path =
|
||||
utils::path::combine(parent, {utils::create_uuid_string()});
|
||||
auto res =
|
||||
provider_.set_item_meta(fsi_.api_path, META_SOURCE, fsi_.source_path);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(function_name, fsi_.api_path,
|
||||
fsi_.source_path, res,
|
||||
"failed to set new source path");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void open_file::set_modified() {
|
||||
if (not is_modified()) {
|
||||
open_file_base::set_modified(true);
|
||||
if (not modified_) {
|
||||
modified_ = true;
|
||||
mgr_.store_resume(*this);
|
||||
}
|
||||
|
||||
if (not is_removed()) {
|
||||
open_file_base::set_removed(true);
|
||||
if (not removed_) {
|
||||
removed_ = true;
|
||||
mgr_.remove_upload(get_api_path());
|
||||
}
|
||||
}
|
||||
|
||||
void open_file::set_read_state(std::size_t chunk) {
|
||||
recur_mutex_lock file_lock(get_mutex());
|
||||
read_state_.set(chunk);
|
||||
}
|
||||
void open_file::update_background_reader(std::size_t read_chunk) {
|
||||
recur_mutex_lock reader_lock(file_mtx_);
|
||||
read_chunk_ = read_chunk;
|
||||
|
||||
void open_file::set_read_state(boost::dynamic_bitset<> read_state) {
|
||||
recur_mutex_lock file_lock(get_mutex());
|
||||
read_state_ = std::move(read_state);
|
||||
}
|
||||
if (not reader_thread_ && not stop_requested_) {
|
||||
reader_thread_ = std::make_unique<std::thread>([this]() {
|
||||
std::size_t next_chunk{};
|
||||
while (not stop_requested_) {
|
||||
unique_recur_mutex_lock file_lock(file_mtx_);
|
||||
if ((fsi_.size == 0U) || read_state_.all()) {
|
||||
file_lock.unlock();
|
||||
|
||||
void open_file::update_reader(std::size_t chunk) {
|
||||
recur_mutex_lock rw_lock(rw_mtx_);
|
||||
read_chunk_ = chunk;
|
||||
unique_mutex_lock io_lock(io_thread_mtx_);
|
||||
if (not stop_requested_ && io_thread_queue_.empty()) {
|
||||
io_thread_notify_.wait(io_lock);
|
||||
}
|
||||
io_thread_notify_.notify_all();
|
||||
io_lock.unlock();
|
||||
} else {
|
||||
do {
|
||||
next_chunk = read_chunk_ =
|
||||
((read_chunk_ + 1U) >= read_state_.size()) ? 0U
|
||||
: read_chunk_ + 1U;
|
||||
} while ((next_chunk != 0U) && (active_downloads_.find(next_chunk) !=
|
||||
active_downloads_.end()));
|
||||
|
||||
if (reader_thread_ || stop_requested_) {
|
||||
return;
|
||||
file_lock.unlock();
|
||||
download_chunk(next_chunk, true, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
reader_thread_ = std::make_unique<std::thread>([this]() {
|
||||
unique_recur_mutex_lock lock(rw_mtx_);
|
||||
auto next_chunk{read_chunk_};
|
||||
auto read_chunk{read_chunk_};
|
||||
lock.unlock();
|
||||
|
||||
while (not stop_requested_) {
|
||||
lock.lock();
|
||||
|
||||
auto read_state = get_read_state();
|
||||
if ((get_file_size() == 0U) || read_state.all()) {
|
||||
lock.unlock();
|
||||
wait_for_io(stop_requested_);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (read_chunk != read_chunk_) {
|
||||
next_chunk = read_chunk = read_chunk_;
|
||||
}
|
||||
|
||||
next_chunk = next_chunk + 1U >= read_state.size() ? 0U : next_chunk + 1U;
|
||||
lock.unlock();
|
||||
|
||||
download_chunk(next_chunk, true, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
auto open_file::write(std::uint64_t write_offset, const data_buffer &data,
|
||||
@ -694,44 +580,41 @@ auto open_file::write(std::uint64_t write_offset, const data_buffer &data,
|
||||
|
||||
bytes_written = 0U;
|
||||
|
||||
if (is_directory() || get_provider().is_read_only()) {
|
||||
return set_api_error(api_error::invalid_operation);
|
||||
if (fsi_.directory || provider_.is_read_only()) {
|
||||
return api_error::invalid_operation;
|
||||
}
|
||||
|
||||
if (data.empty()) {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
unique_recur_mutex_lock write_lock(file_mtx_);
|
||||
if (stop_requested_) {
|
||||
return set_api_error(api_error::download_stopped);
|
||||
return api_error::download_stopped;
|
||||
}
|
||||
write_lock.unlock();
|
||||
|
||||
auto res = check_start();
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
auto begin_chunk = static_cast<std::size_t>(write_offset / get_chunk_size());
|
||||
auto start_chunk = static_cast<std::size_t>(write_offset / chunk_size_);
|
||||
auto end_chunk =
|
||||
static_cast<std::size_t>((write_offset + data.size()) / get_chunk_size());
|
||||
static_cast<std::size_t>((write_offset + data.size()) / chunk_size_);
|
||||
|
||||
update_reader(begin_chunk);
|
||||
update_background_reader(start_chunk);
|
||||
|
||||
download_range(begin_chunk, std::min(get_read_state().size() - 1U, end_chunk),
|
||||
download_range(start_chunk, std::min(read_state_.size() - 1U, end_chunk),
|
||||
true);
|
||||
if (get_api_error() != api_error::success) {
|
||||
return get_api_error();
|
||||
}
|
||||
|
||||
unique_recur_mutex_lock rw_lock(rw_mtx_);
|
||||
if ((write_offset + data.size()) > get_file_size()) {
|
||||
res = resize(write_offset + data.size());
|
||||
write_lock.lock();
|
||||
if ((write_offset + data.size()) > fsi_.size) {
|
||||
auto res = resize(write_offset + data.size());
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
res = do_io([&]() -> api_error {
|
||||
auto res = do_io([&]() -> api_error {
|
||||
if (not nf_->write(data, write_offset, &bytes_written)) {
|
||||
return api_error::os_error;
|
||||
}
|
||||
@ -744,11 +627,11 @@ auto open_file::write(std::uint64_t write_offset, const data_buffer &data,
|
||||
}
|
||||
|
||||
auto now = std::to_string(utils::time::get_time_now());
|
||||
res = get_provider().set_item_meta(get_api_path(), {
|
||||
{META_CHANGED, now},
|
||||
{META_MODIFIED, now},
|
||||
{META_WRITTEN, now},
|
||||
});
|
||||
res = provider_.set_item_meta(fsi_.api_path, {
|
||||
{META_CHANGED, now},
|
||||
{META_MODIFIED, now},
|
||||
{META_WRITTEN, now},
|
||||
});
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(function_name, get_api_path(), res,
|
||||
"failed to set file meta");
|
||||
|
@ -35,15 +35,13 @@ void open_file_base::download::notify(const api_error &err) {
|
||||
}
|
||||
|
||||
auto open_file_base::download::wait() -> api_error {
|
||||
if (complete_) {
|
||||
return error_;
|
||||
}
|
||||
|
||||
unique_mutex_lock lock(mtx_);
|
||||
if (not complete_) {
|
||||
notify_.wait(lock);
|
||||
unique_mutex_lock lock(mtx_);
|
||||
if (not complete_) {
|
||||
notify_.wait(lock);
|
||||
}
|
||||
notify_.notify_all();
|
||||
}
|
||||
notify_.notify_all();
|
||||
|
||||
return error_;
|
||||
}
|
||||
@ -67,14 +65,12 @@ auto open_file_base::io_item::get_result() -> api_error {
|
||||
|
||||
open_file_base::open_file_base(std::uint64_t chunk_size,
|
||||
std::uint8_t chunk_timeout, filesystem_item fsi,
|
||||
i_provider &provider, bool disable_io)
|
||||
: open_file_base(chunk_size, chunk_timeout, fsi, {}, provider, disable_io) {
|
||||
}
|
||||
i_provider &provider)
|
||||
: open_file_base(chunk_size, chunk_timeout, fsi, {}, provider) {}
|
||||
|
||||
open_file_base::open_file_base(
|
||||
std::uint64_t chunk_size, std::uint8_t chunk_timeout, filesystem_item fsi,
|
||||
std::map<std::uint64_t, open_file_data> open_data, i_provider &provider,
|
||||
bool disable_io)
|
||||
std::map<std::uint64_t, open_file_data> open_data, i_provider &provider)
|
||||
: chunk_size_(chunk_size),
|
||||
chunk_timeout_(chunk_timeout),
|
||||
fsi_(std::move(fsi)),
|
||||
@ -84,7 +80,7 @@ open_file_base::open_file_base(
|
||||
: fsi.size % chunk_size)),
|
||||
open_data_(std::move(open_data)),
|
||||
provider_(provider) {
|
||||
if (not fsi.directory && not disable_io) {
|
||||
if (not fsi.directory) {
|
||||
io_thread_ = std::make_unique<std::thread>([this] { file_io_thread(); });
|
||||
}
|
||||
}
|
||||
@ -119,7 +115,7 @@ auto open_file_base::can_close() const -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (is_complete()) {
|
||||
if (is_download_complete()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -127,30 +123,12 @@ auto open_file_base::can_close() const -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::chrono::system_clock::time_point last_access{last_access_};
|
||||
auto duration = std::chrono::duration_cast<std::chrono::seconds>(
|
||||
const std::chrono::system_clock::time_point last_access = last_access_;
|
||||
const auto duration = std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now() - last_access);
|
||||
return (duration.count() >= chunk_timeout_);
|
||||
}
|
||||
|
||||
auto open_file_base::close() -> bool {
|
||||
unique_mutex_lock io_lock(io_thread_mtx_);
|
||||
if (io_stop_requested_ || not io_thread_) {
|
||||
io_thread_notify_.notify_all();
|
||||
io_lock.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
io_stop_requested_ = true;
|
||||
io_thread_notify_.notify_all();
|
||||
io_lock.unlock();
|
||||
|
||||
io_thread_->join();
|
||||
io_thread_.reset();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
auto open_file_base::do_io(std::function<api_error()> action) -> api_error {
|
||||
unique_mutex_lock io_lock(io_thread_mtx_);
|
||||
auto item = std::make_shared<io_item>(action);
|
||||
@ -209,36 +187,6 @@ auto open_file_base::get_file_size() const -> std::uint64_t {
|
||||
return fsi_.size;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto open_file_base::get_last_chunk_size() const -> std::size_t {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
return last_chunk_size_;
|
||||
}
|
||||
|
||||
void open_file_base::set_file_size(std::uint64_t size) {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
fsi_.size = size;
|
||||
}
|
||||
|
||||
void open_file_base::set_last_chunk_size(std::size_t size) {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
last_chunk_size_ = size;
|
||||
}
|
||||
|
||||
void open_file_base::set_modified(bool modified) {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
modified_ = modified;
|
||||
}
|
||||
|
||||
void open_file_base::set_removed(bool removed) {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
removed_ = removed;
|
||||
}
|
||||
|
||||
void open_file_base::set_source_path(std::string source_path) {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
fsi_.source_path = std::move(source_path);
|
||||
}
|
||||
|
||||
auto open_file_base::get_filesystem_item() const -> filesystem_item {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
return fsi_;
|
||||
@ -246,9 +194,8 @@ auto open_file_base::get_filesystem_item() const -> filesystem_item {
|
||||
|
||||
auto open_file_base::get_handles() const -> std::vector<std::uint64_t> {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
|
||||
std::vector<std::uint64_t> ret;
|
||||
for (const auto &item : open_data_) {
|
||||
for (auto &&item : open_data_) {
|
||||
ret.emplace_back(item.first);
|
||||
}
|
||||
|
||||
@ -283,31 +230,11 @@ auto open_file_base::get_open_file_count() const -> std::size_t {
|
||||
return open_data_.size();
|
||||
}
|
||||
|
||||
auto open_file_base::get_source_path() const -> std::string {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
return fsi_.source_path;
|
||||
}
|
||||
|
||||
auto open_file_base::has_handle(std::uint64_t handle) const -> bool {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
return open_data_.find(handle) != open_data_.end();
|
||||
}
|
||||
|
||||
auto open_file_base::is_modified() const -> bool {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
return modified_;
|
||||
}
|
||||
|
||||
auto open_file_base::is_removed() const -> bool {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
return removed_;
|
||||
}
|
||||
|
||||
void open_file_base::notify_io() {
|
||||
mutex_lock io_lock(io_thread_mtx_);
|
||||
io_thread_notify_.notify_all();
|
||||
}
|
||||
|
||||
void open_file_base::remove(std::uint64_t handle) {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
if (open_data_.find(handle) == open_data_.end()) {
|
||||
@ -334,7 +261,7 @@ void open_file_base::remove_all() {
|
||||
auto open_data = open_data_;
|
||||
open_data_.clear();
|
||||
|
||||
for (const auto &data : open_data) {
|
||||
for (auto &&data : open_data) {
|
||||
event_system::instance().raise<filesystem_item_handle_closed>(
|
||||
fsi_.api_path, data.first, fsi_.source_path, fsi_.directory, modified_);
|
||||
}
|
||||
@ -349,15 +276,15 @@ void open_file_base::reset_timeout() {
|
||||
|
||||
auto open_file_base::set_api_error(const api_error &err) -> api_error {
|
||||
mutex_lock error_lock(error_mtx_);
|
||||
if (error_ == err) {
|
||||
return error_;
|
||||
if (error_ != err) {
|
||||
return ((error_ = (error_ == api_error::success ||
|
||||
error_ == api_error::download_incomplete ||
|
||||
error_ == api_error::download_stopped
|
||||
? err
|
||||
: error_)));
|
||||
}
|
||||
|
||||
return ((error_ = (error_ == api_error::success ||
|
||||
error_ == api_error::download_incomplete ||
|
||||
error_ == api_error::download_stopped
|
||||
? err
|
||||
: error_)));
|
||||
return error_;
|
||||
}
|
||||
|
||||
void open_file_base::set_api_path(const std::string &api_path) {
|
||||
@ -366,12 +293,24 @@ void open_file_base::set_api_path(const std::string &api_path) {
|
||||
fsi_.api_parent = utils::path::get_parent_api_path(api_path);
|
||||
}
|
||||
|
||||
void open_file_base::wait_for_io(stop_type &stop_requested) {
|
||||
auto open_file_base::close() -> bool {
|
||||
unique_mutex_lock io_lock(io_thread_mtx_);
|
||||
if (not stop_requested && io_thread_queue_.empty()) {
|
||||
io_thread_notify_.wait(io_lock);
|
||||
if (not fsi_.directory && not io_stop_requested_) {
|
||||
io_stop_requested_ = true;
|
||||
io_thread_notify_.notify_all();
|
||||
io_lock.unlock();
|
||||
|
||||
if (io_thread_) {
|
||||
io_thread_->join();
|
||||
io_thread_.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
io_thread_notify_.notify_all();
|
||||
io_lock.unlock();
|
||||
return false;
|
||||
}
|
||||
} // namespace repertory
|
||||
|
@ -1,367 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include "file_manager/ring_buffer_base.hpp"
|
||||
|
||||
#include "events/event_system.hpp"
|
||||
#include "file_manager/events.hpp"
|
||||
#include "file_manager/open_file_base.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
ring_buffer_base::ring_buffer_base(std::uint64_t chunk_size,
|
||||
std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi, i_provider &provider,
|
||||
std::size_t ring_size, bool disable_io)
|
||||
: open_file_base(chunk_size, chunk_timeout, fsi, provider, disable_io),
|
||||
read_state_(ring_size),
|
||||
total_chunks_(static_cast<std::size_t>(
|
||||
utils::divide_with_ceiling(fsi.size, chunk_size))) {
|
||||
if (disable_io) {
|
||||
if (fsi.size > 0U) {
|
||||
read_state_.resize(std::min(total_chunks_, read_state_.size()));
|
||||
|
||||
ring_end_ =
|
||||
std::min(total_chunks_ - 1U, ring_begin_ + read_state_.size() - 1U);
|
||||
read_state_.set(0U, read_state_.size(), false);
|
||||
}
|
||||
} else {
|
||||
if (ring_size < min_ring_size) {
|
||||
throw std::runtime_error("ring size must be greater than or equal to 5");
|
||||
}
|
||||
|
||||
ring_end_ = std::min(total_chunks_ - 1U, ring_begin_ + ring_size - 1U);
|
||||
read_state_.set(0U, ring_size, false);
|
||||
}
|
||||
}
|
||||
|
||||
auto ring_buffer_base::check_start() -> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
if (on_check_start()) {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
event_system::instance().raise<download_begin>(get_api_path(),
|
||||
get_source_path());
|
||||
reader_thread_ =
|
||||
std::make_unique<std::thread>([this]() { reader_thread(); });
|
||||
return api_error::success;
|
||||
} catch (const std::exception &ex) {
|
||||
utils::error::raise_api_path_error(function_name, get_api_path(),
|
||||
get_source_path(), ex,
|
||||
"failed to start");
|
||||
return api_error::error;
|
||||
}
|
||||
}
|
||||
|
||||
auto ring_buffer_base::close() -> bool {
|
||||
stop_requested_ = true;
|
||||
|
||||
unique_mutex_lock chunk_lock(chunk_mtx_);
|
||||
chunk_notify_.notify_all();
|
||||
chunk_lock.unlock();
|
||||
|
||||
auto res = open_file_base::close();
|
||||
|
||||
if (reader_thread_) {
|
||||
reader_thread_->join();
|
||||
reader_thread_.reset();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
auto ring_buffer_base::download_chunk(std::size_t chunk,
|
||||
bool skip_active) -> api_error {
|
||||
unique_mutex_lock chunk_lock(chunk_mtx_);
|
||||
const auto unlock_and_notify = [this, &chunk_lock]() {
|
||||
chunk_notify_.notify_all();
|
||||
chunk_lock.unlock();
|
||||
};
|
||||
|
||||
const auto unlock_and_return =
|
||||
[&unlock_and_notify](api_error res) -> api_error {
|
||||
unlock_and_notify();
|
||||
return res;
|
||||
};
|
||||
|
||||
if (chunk < ring_begin_ || chunk > ring_end_) {
|
||||
return unlock_and_return(api_error::invalid_ring_buffer_position);
|
||||
}
|
||||
|
||||
if (get_active_downloads().find(chunk) != get_active_downloads().end()) {
|
||||
if (skip_active) {
|
||||
return unlock_and_return(api_error::success);
|
||||
}
|
||||
|
||||
auto active_download = get_active_downloads().at(chunk);
|
||||
unlock_and_notify();
|
||||
|
||||
return active_download->wait();
|
||||
}
|
||||
|
||||
if (read_state_[chunk % read_state_.size()]) {
|
||||
return unlock_and_return(api_error::success);
|
||||
}
|
||||
|
||||
auto active_download{std::make_shared<download>()};
|
||||
get_active_downloads()[chunk] = active_download;
|
||||
|
||||
return use_buffer(chunk, [&](data_buffer &buffer) -> api_error {
|
||||
auto data_offset{chunk * get_chunk_size()};
|
||||
auto data_size{
|
||||
chunk == (total_chunks_ - 1U) ? get_last_chunk_size()
|
||||
: get_chunk_size(),
|
||||
};
|
||||
unlock_and_notify();
|
||||
|
||||
auto result{
|
||||
get_provider().read_file_bytes(get_api_path(), data_size, data_offset,
|
||||
buffer, stop_requested_),
|
||||
};
|
||||
|
||||
chunk_lock.lock();
|
||||
if (chunk < ring_begin_ || chunk > ring_end_) {
|
||||
result = api_error::invalid_ring_buffer_position;
|
||||
}
|
||||
|
||||
if (result == api_error::success) {
|
||||
result = on_chunk_downloaded(chunk, buffer);
|
||||
if (result == api_error::success) {
|
||||
read_state_[chunk % read_state_.size()] = true;
|
||||
auto progress = (static_cast<double>(chunk + 1U) /
|
||||
static_cast<double>(total_chunks_)) *
|
||||
100.0;
|
||||
event_system::instance().raise<download_progress>(
|
||||
get_api_path(), get_source_path(), progress);
|
||||
}
|
||||
}
|
||||
|
||||
get_active_downloads().erase(chunk);
|
||||
unlock_and_notify();
|
||||
|
||||
active_download->notify(result);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
void ring_buffer_base::forward(std::size_t count) {
|
||||
update_position(count, true);
|
||||
}
|
||||
|
||||
auto ring_buffer_base::get_read_state() const -> boost::dynamic_bitset<> {
|
||||
recur_mutex_lock file_lock(get_mutex());
|
||||
return read_state_;
|
||||
}
|
||||
|
||||
auto ring_buffer_base::get_read_state(std::size_t chunk) const -> bool {
|
||||
recur_mutex_lock file_lock(get_mutex());
|
||||
return read_state_[chunk % read_state_.size()];
|
||||
}
|
||||
|
||||
auto ring_buffer_base::read(std::size_t read_size, std::uint64_t read_offset,
|
||||
data_buffer &data) -> api_error {
|
||||
if (is_directory()) {
|
||||
return api_error::invalid_operation;
|
||||
}
|
||||
|
||||
reset_timeout();
|
||||
|
||||
read_size =
|
||||
utils::calculate_read_size(get_file_size(), read_size, read_offset);
|
||||
if (read_size == 0U) {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto begin_chunk{static_cast<std::size_t>(read_offset / get_chunk_size())};
|
||||
read_offset = read_offset - (begin_chunk * get_chunk_size());
|
||||
|
||||
unique_mutex_lock read_lock(read_mtx_);
|
||||
auto res = check_start();
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
for (std::size_t chunk = begin_chunk;
|
||||
not stop_requested_ && (res == api_error::success) && (read_size > 0U);
|
||||
++chunk) {
|
||||
reset_timeout();
|
||||
|
||||
if (chunk > ring_pos_) {
|
||||
forward(chunk - ring_pos_);
|
||||
} else if (chunk < ring_pos_) {
|
||||
reverse(ring_pos_ - chunk);
|
||||
}
|
||||
|
||||
res = download_chunk(chunk, false);
|
||||
if (res != api_error::success) {
|
||||
if (res == api_error::invalid_ring_buffer_position) {
|
||||
read_lock.unlock();
|
||||
|
||||
// TODO limit retry
|
||||
return read(read_size, read_offset, data);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
reset_timeout();
|
||||
|
||||
std::size_t bytes_read{};
|
||||
res = on_read_chunk(
|
||||
chunk,
|
||||
std::min(static_cast<std::size_t>(get_chunk_size() - read_offset),
|
||||
read_size),
|
||||
read_offset, data, bytes_read);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
reset_timeout();
|
||||
|
||||
read_size -= bytes_read;
|
||||
read_offset = 0U;
|
||||
}
|
||||
|
||||
return stop_requested_ ? api_error::download_stopped : res;
|
||||
}
|
||||
|
||||
void ring_buffer_base::reader_thread() {
|
||||
unique_mutex_lock chunk_lock(chunk_mtx_);
|
||||
auto next_chunk{ring_pos_};
|
||||
chunk_notify_.notify_all();
|
||||
chunk_lock.unlock();
|
||||
|
||||
while (not stop_requested_) {
|
||||
chunk_lock.lock();
|
||||
|
||||
next_chunk = next_chunk + 1U > ring_end_ ? ring_begin_ : next_chunk + 1U;
|
||||
const auto check_and_wait = [this, &chunk_lock, &next_chunk]() {
|
||||
if (stop_requested_) {
|
||||
chunk_notify_.notify_all();
|
||||
chunk_lock.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
if (get_read_state().all()) {
|
||||
chunk_notify_.wait(chunk_lock);
|
||||
next_chunk = ring_pos_;
|
||||
}
|
||||
|
||||
chunk_notify_.notify_all();
|
||||
chunk_lock.unlock();
|
||||
};
|
||||
|
||||
if (read_state_[next_chunk % read_state_.size()]) {
|
||||
check_and_wait();
|
||||
continue;
|
||||
}
|
||||
|
||||
chunk_notify_.notify_all();
|
||||
chunk_lock.unlock();
|
||||
|
||||
download_chunk(next_chunk, true);
|
||||
}
|
||||
|
||||
event_system::instance().raise<download_end>(
|
||||
get_api_path(), get_source_path(), api_error::download_stopped);
|
||||
}
|
||||
|
||||
void ring_buffer_base::reverse(std::size_t count) {
|
||||
update_position(count, false);
|
||||
}
|
||||
|
||||
void ring_buffer_base::set(std::size_t first_chunk, std::size_t current_chunk) {
|
||||
mutex_lock chunk_lock(chunk_mtx_);
|
||||
if (first_chunk >= total_chunks_) {
|
||||
chunk_notify_.notify_all();
|
||||
throw std::runtime_error("first chunk must be less than total chunks");
|
||||
}
|
||||
|
||||
ring_begin_ = first_chunk;
|
||||
ring_end_ =
|
||||
std::min(total_chunks_ - 1U, ring_begin_ + read_state_.size() - 1U);
|
||||
|
||||
if (current_chunk > ring_end_) {
|
||||
chunk_notify_.notify_all();
|
||||
throw std::runtime_error(
|
||||
"current chunk must be less than or equal to last chunk");
|
||||
}
|
||||
|
||||
ring_pos_ = current_chunk;
|
||||
read_state_.set(0U, read_state_.size(), true);
|
||||
|
||||
chunk_notify_.notify_all();
|
||||
}
|
||||
|
||||
void ring_buffer_base::set_api_path(const std::string &api_path) {
|
||||
mutex_lock chunk_lock(chunk_mtx_);
|
||||
open_file_base::set_api_path(api_path);
|
||||
chunk_notify_.notify_all();
|
||||
}
|
||||
|
||||
void ring_buffer_base::update_position(std::size_t count, bool is_forward) {
|
||||
mutex_lock chunk_lock(chunk_mtx_);
|
||||
|
||||
if (is_forward) {
|
||||
if ((ring_pos_ + count) > (total_chunks_ - 1U)) {
|
||||
count = (total_chunks_ - 1U) - ring_pos_;
|
||||
}
|
||||
} else {
|
||||
count = std::min(ring_pos_, count);
|
||||
}
|
||||
|
||||
if (is_forward ? (ring_pos_ + count) <= ring_end_
|
||||
: (ring_pos_ - count) >= ring_begin_) {
|
||||
ring_pos_ += is_forward ? count : -count;
|
||||
} else {
|
||||
auto delta = is_forward ? count - (ring_end_ - ring_pos_)
|
||||
: count - (ring_pos_ - ring_begin_);
|
||||
|
||||
if (delta >= read_state_.size()) {
|
||||
read_state_.set(0U, read_state_.size(), false);
|
||||
ring_pos_ += is_forward ? count : -count;
|
||||
ring_begin_ += is_forward ? delta : -delta;
|
||||
} else {
|
||||
for (std::size_t idx = 0U; idx < delta; ++idx) {
|
||||
if (is_forward) {
|
||||
read_state_[(ring_begin_ + idx) % read_state_.size()] = false;
|
||||
} else {
|
||||
read_state_[(ring_end_ - idx) % read_state_.size()] = false;
|
||||
}
|
||||
}
|
||||
ring_begin_ += is_forward ? delta : -delta;
|
||||
ring_pos_ += is_forward ? count : -count;
|
||||
}
|
||||
|
||||
ring_end_ =
|
||||
std::min(total_chunks_ - 1U, ring_begin_ + read_state_.size() - 1U);
|
||||
}
|
||||
|
||||
chunk_notify_.notify_all();
|
||||
}
|
||||
} // namespace repertory
|
@ -21,30 +21,73 @@
|
||||
*/
|
||||
#include "file_manager/ring_buffer_open_file.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "file_manager/events.hpp"
|
||||
#include "file_manager/open_file_base.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
#include "utils/encrypting_reader.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
ring_buffer_open_file::ring_buffer_open_file(std::string buffer_directory,
|
||||
std::uint64_t chunk_size,
|
||||
std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi,
|
||||
i_provider &provider)
|
||||
: ring_buffer_open_file(std::move(buffer_directory), chunk_size,
|
||||
chunk_timeout, std::move(fsi), provider,
|
||||
(1024ULL * 1024ULL * 1024ULL) / chunk_size) {}
|
||||
|
||||
ring_buffer_open_file::ring_buffer_open_file(std::string buffer_directory,
|
||||
std::uint64_t chunk_size,
|
||||
std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi,
|
||||
i_provider &provider,
|
||||
std::size_t ring_size)
|
||||
: ring_buffer_base(chunk_size, chunk_timeout, fsi, provider, ring_size,
|
||||
false),
|
||||
source_path_(utils::path::combine(buffer_directory,
|
||||
{
|
||||
utils::create_uuid_string(),
|
||||
})) {
|
||||
if (not can_handle_file(fsi.size, chunk_size, ring_size)) {
|
||||
: open_file_base(chunk_size, chunk_timeout, fsi, provider),
|
||||
ring_state_(ring_size),
|
||||
total_chunks_(static_cast<std::size_t>(
|
||||
utils::divide_with_ceiling(fsi.size, chunk_size_))) {
|
||||
if ((ring_size % 2U) != 0U) {
|
||||
throw std::runtime_error("ring size must be a multiple of 2");
|
||||
}
|
||||
|
||||
if (ring_size < 4U) {
|
||||
throw std::runtime_error("ring size must be greater than or equal to 4");
|
||||
}
|
||||
|
||||
if (fsi.size < (ring_state_.size() * chunk_size)) {
|
||||
throw std::runtime_error("file size is less than ring buffer size");
|
||||
}
|
||||
|
||||
last_chunk_ = ring_state_.size() - 1U;
|
||||
ring_state_.set(0U, ring_state_.size(), true);
|
||||
|
||||
buffer_directory = utils::path::absolute(buffer_directory);
|
||||
if (not utils::file::directory(buffer_directory).create_directory()) {
|
||||
throw std::runtime_error("failed to create buffer directory|path|" +
|
||||
buffer_directory + "|err|" +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
}
|
||||
|
||||
fsi_.source_path =
|
||||
utils::path::combine(buffer_directory, {utils::create_uuid_string()});
|
||||
nf_ = utils::file::file::open_or_create_file(fsi_.source_path);
|
||||
if (not*nf_) {
|
||||
throw std::runtime_error("failed to create buffer file|err|" +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
}
|
||||
|
||||
if (not nf_->truncate(ring_state_.size() * chunk_size)) {
|
||||
nf_->close();
|
||||
throw std::runtime_error("failed to resize buffer file|err|" +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
}
|
||||
}
|
||||
|
||||
ring_buffer_open_file::~ring_buffer_open_file() {
|
||||
@ -52,24 +95,107 @@ ring_buffer_open_file::~ring_buffer_open_file() {
|
||||
|
||||
close();
|
||||
|
||||
if (not nf_) {
|
||||
return;
|
||||
}
|
||||
|
||||
nf_->close();
|
||||
nf_.reset();
|
||||
|
||||
if (not utils::file::file(source_path_).remove()) {
|
||||
if (not utils::file::file(fsi_.source_path).remove()) {
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, get_api_path(), source_path_,
|
||||
function_name, fsi_.api_path, fsi_.source_path,
|
||||
utils::get_last_error_code(), "failed to delete file");
|
||||
}
|
||||
}
|
||||
|
||||
auto ring_buffer_open_file::can_handle_file(std::uint64_t file_size,
|
||||
std::size_t chunk_size,
|
||||
std::size_t ring_size) -> bool {
|
||||
return file_size >= (static_cast<std::uint64_t>(ring_size) * chunk_size);
|
||||
auto ring_buffer_open_file::download_chunk(std::size_t chunk) -> api_error {
|
||||
unique_mutex_lock chunk_lock(chunk_mtx_);
|
||||
if (active_downloads_.find(chunk) != active_downloads_.end()) {
|
||||
auto active_download = active_downloads_.at(chunk);
|
||||
chunk_notify_.notify_all();
|
||||
chunk_lock.unlock();
|
||||
|
||||
return active_download->wait();
|
||||
}
|
||||
|
||||
if (ring_state_[chunk % ring_state_.size()]) {
|
||||
auto active_download = std::make_shared<download>();
|
||||
active_downloads_[chunk] = active_download;
|
||||
ring_state_[chunk % ring_state_.size()] = false;
|
||||
chunk_notify_.notify_all();
|
||||
chunk_lock.unlock();
|
||||
|
||||
data_buffer buffer((chunk == (total_chunks_ - 1U)) ? last_chunk_size_
|
||||
: chunk_size_);
|
||||
|
||||
stop_type stop_requested = !!ring_state_[chunk % ring_state_.size()];
|
||||
auto res =
|
||||
provider_.read_file_bytes(fsi_.api_path, buffer.size(),
|
||||
chunk * chunk_size_, buffer, stop_requested);
|
||||
if (res == api_error::success) {
|
||||
res = do_io([&]() -> api_error {
|
||||
std::size_t bytes_written{};
|
||||
if (not nf_->write(buffer, (chunk % ring_state_.size()) * chunk_size_,
|
||||
&bytes_written)) {
|
||||
return api_error::os_error;
|
||||
}
|
||||
|
||||
return api_error::success;
|
||||
});
|
||||
}
|
||||
|
||||
active_download->notify(res);
|
||||
|
||||
chunk_lock.lock();
|
||||
active_downloads_.erase(chunk);
|
||||
chunk_notify_.notify_all();
|
||||
return res;
|
||||
}
|
||||
|
||||
chunk_notify_.notify_all();
|
||||
chunk_lock.unlock();
|
||||
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
void ring_buffer_open_file::forward(std::size_t count) {
|
||||
mutex_lock chunk_lock(chunk_mtx_);
|
||||
if ((current_chunk_ + count) > (total_chunks_ - 1U)) {
|
||||
count = (total_chunks_ - 1U) - current_chunk_;
|
||||
}
|
||||
|
||||
if ((current_chunk_ + count) <= last_chunk_) {
|
||||
current_chunk_ += count;
|
||||
} else {
|
||||
const auto added = count - (last_chunk_ - current_chunk_);
|
||||
if (added >= ring_state_.size()) {
|
||||
ring_state_.set(0U, ring_state_.size(), true);
|
||||
current_chunk_ += count;
|
||||
first_chunk_ += added;
|
||||
last_chunk_ =
|
||||
std::min(total_chunks_ - 1U, first_chunk_ + ring_state_.size() - 1U);
|
||||
} else {
|
||||
for (std::size_t idx = 0U; idx < added; ++idx) {
|
||||
ring_state_[(first_chunk_ + idx) % ring_state_.size()] = true;
|
||||
}
|
||||
first_chunk_ += added;
|
||||
current_chunk_ += count;
|
||||
last_chunk_ =
|
||||
std::min(total_chunks_ - 1U, first_chunk_ + ring_state_.size() - 1U);
|
||||
}
|
||||
}
|
||||
|
||||
chunk_notify_.notify_all();
|
||||
}
|
||||
|
||||
auto ring_buffer_open_file::get_read_state() const -> boost::dynamic_bitset<> {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
auto read_state = ring_state_;
|
||||
return read_state.flip();
|
||||
}
|
||||
|
||||
auto ring_buffer_open_file::get_read_state(std::size_t chunk) const -> bool {
|
||||
recur_mutex_lock file_lock(file_mtx_);
|
||||
return not ring_state_[chunk % ring_state_.size()];
|
||||
}
|
||||
|
||||
auto ring_buffer_open_file::is_download_complete() const -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ring_buffer_open_file::native_operation(
|
||||
@ -77,75 +203,121 @@ auto ring_buffer_open_file::native_operation(
|
||||
return do_io([&]() -> api_error { return callback(nf_->get_handle()); });
|
||||
}
|
||||
|
||||
auto ring_buffer_open_file::on_check_start() -> bool {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
if (nf_) {
|
||||
return true;
|
||||
void ring_buffer_open_file::reverse(std::size_t count) {
|
||||
mutex_lock chunk_lock(chunk_mtx_);
|
||||
if (current_chunk_ < count) {
|
||||
count = current_chunk_;
|
||||
}
|
||||
|
||||
auto buffer_directory{utils::path::get_parent_path(source_path_)};
|
||||
if (not utils::file::directory(buffer_directory).create_directory()) {
|
||||
throw std::runtime_error(
|
||||
fmt::format("failed to create buffer directory|path|{}|err|{}",
|
||||
buffer_directory, utils::get_last_error_code()));
|
||||
if ((current_chunk_ - count) >= first_chunk_) {
|
||||
current_chunk_ -= count;
|
||||
} else {
|
||||
const auto removed = count - (current_chunk_ - first_chunk_);
|
||||
if (removed >= ring_state_.size()) {
|
||||
ring_state_.set(0U, ring_state_.size(), true);
|
||||
current_chunk_ -= count;
|
||||
first_chunk_ = current_chunk_;
|
||||
last_chunk_ =
|
||||
std::min(total_chunks_ - 1U, first_chunk_ + ring_state_.size() - 1U);
|
||||
} else {
|
||||
for (std::size_t idx = 0U; idx < removed; ++idx) {
|
||||
ring_state_[(last_chunk_ - idx) % ring_state_.size()] = true;
|
||||
}
|
||||
first_chunk_ -= removed;
|
||||
current_chunk_ -= count;
|
||||
last_chunk_ =
|
||||
std::min(total_chunks_ - 1U, first_chunk_ + ring_state_.size() - 1U);
|
||||
}
|
||||
}
|
||||
|
||||
nf_ = utils::file::file::open_or_create_file(source_path_);
|
||||
if (not nf_ || not *nf_) {
|
||||
throw std::runtime_error(fmt::format("failed to create buffer file|err|{}",
|
||||
utils::get_last_error_code()));
|
||||
}
|
||||
|
||||
if (not nf_->truncate(get_ring_size() * get_chunk_size())) {
|
||||
nf_->close();
|
||||
nf_.reset();
|
||||
|
||||
throw std::runtime_error(fmt::format("failed to resize buffer file|err|{}",
|
||||
utils::get_last_error_code()));
|
||||
}
|
||||
|
||||
return false;
|
||||
chunk_notify_.notify_all();
|
||||
}
|
||||
|
||||
auto ring_buffer_open_file::on_chunk_downloaded(
|
||||
std::size_t chunk, const data_buffer &buffer) -> api_error {
|
||||
return do_io([&]() -> api_error {
|
||||
std::size_t bytes_written{};
|
||||
if (nf_->write(buffer, (chunk % get_ring_size()) * get_chunk_size(),
|
||||
&bytes_written)) {
|
||||
return api_error::success;
|
||||
auto ring_buffer_open_file::read(std::size_t read_size,
|
||||
std::uint64_t read_offset, data_buffer &data)
|
||||
-> api_error {
|
||||
if (fsi_.directory) {
|
||||
return api_error::invalid_operation;
|
||||
}
|
||||
|
||||
reset_timeout();
|
||||
|
||||
read_size = utils::calculate_read_size(fsi_.size, read_size, read_offset);
|
||||
if (read_size == 0U) {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
const auto start_chunk_index =
|
||||
static_cast<std::size_t>(read_offset / chunk_size_);
|
||||
read_offset = read_offset - (start_chunk_index * chunk_size_);
|
||||
data_buffer buffer(chunk_size_);
|
||||
|
||||
auto res = api_error::success;
|
||||
for (std::size_t chunk = start_chunk_index;
|
||||
(res == api_error::success) && (read_size > 0U); ++chunk) {
|
||||
if (chunk > current_chunk_) {
|
||||
forward(chunk - current_chunk_);
|
||||
} else if (chunk < current_chunk_) {
|
||||
reverse(current_chunk_ - chunk);
|
||||
}
|
||||
|
||||
return api_error::os_error;
|
||||
});
|
||||
}
|
||||
reset_timeout();
|
||||
res = download_chunk(chunk);
|
||||
if (res == api_error::success) {
|
||||
const auto to_read = std::min(
|
||||
static_cast<std::size_t>(chunk_size_ - read_offset), read_size);
|
||||
res = do_io([this, &buffer, &chunk, &data, read_offset,
|
||||
&to_read]() -> api_error {
|
||||
std::size_t bytes_read{};
|
||||
auto ret =
|
||||
nf_->read(buffer, ((chunk % ring_state_.size()) * chunk_size_),
|
||||
&bytes_read)
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
if (ret == api_error::success) {
|
||||
data.insert(data.end(),
|
||||
buffer.begin() + static_cast<std::int64_t>(read_offset),
|
||||
buffer.begin() +
|
||||
static_cast<std::int64_t>(read_offset + to_read));
|
||||
reset_timeout();
|
||||
}
|
||||
|
||||
auto ring_buffer_open_file::on_read_chunk(
|
||||
std::size_t chunk, std::size_t read_size, std::uint64_t read_offset,
|
||||
data_buffer &data, std::size_t &bytes_read) -> api_error {
|
||||
data_buffer buffer(read_size);
|
||||
auto res = do_io([&]() -> api_error {
|
||||
return nf_->read(
|
||||
buffer,
|
||||
(((chunk % get_ring_size()) * get_chunk_size()) + read_offset),
|
||||
&bytes_read)
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
});
|
||||
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
return ret;
|
||||
});
|
||||
read_offset = 0U;
|
||||
read_size -= to_read;
|
||||
}
|
||||
}
|
||||
|
||||
data.insert(data.end(), buffer.begin(), buffer.end());
|
||||
return api_error::success;
|
||||
return res;
|
||||
}
|
||||
|
||||
auto ring_buffer_open_file::use_buffer(
|
||||
std::size_t /* chunk */,
|
||||
std::function<api_error(data_buffer &)> func) -> api_error {
|
||||
data_buffer buffer;
|
||||
return func(buffer);
|
||||
void ring_buffer_open_file::set(std::size_t first_chunk,
|
||||
std::size_t current_chunk) {
|
||||
mutex_lock chunk_lock(chunk_mtx_);
|
||||
if (first_chunk >= total_chunks_) {
|
||||
chunk_notify_.notify_all();
|
||||
throw std::runtime_error("first chunk must be less than total chunks");
|
||||
}
|
||||
|
||||
first_chunk_ = first_chunk;
|
||||
last_chunk_ = first_chunk_ + ring_state_.size() - 1U;
|
||||
|
||||
if (current_chunk > last_chunk_) {
|
||||
chunk_notify_.notify_all();
|
||||
throw std::runtime_error(
|
||||
"current chunk must be less than or equal to last chunk");
|
||||
}
|
||||
|
||||
current_chunk_ = current_chunk;
|
||||
ring_state_.set(0U, ring_state_.size(), false);
|
||||
|
||||
chunk_notify_.notify_all();
|
||||
}
|
||||
|
||||
void ring_buffer_open_file::set_api_path(const std::string &api_path) {
|
||||
mutex_lock chunk_lock(chunk_mtx_);
|
||||
open_file_base::set_api_path(api_path);
|
||||
chunk_notify_.notify_all();
|
||||
}
|
||||
} // namespace repertory
|
||||
|
@ -53,8 +53,7 @@ void upload::upload_thread() {
|
||||
|
||||
error_ =
|
||||
provider_.upload_file(fsi_.api_path, fsi_.source_path, stop_requested_);
|
||||
if (error_ == api_error::success &&
|
||||
not utils::file::reset_modified_time(fsi_.source_path)) {
|
||||
if (not utils::file::reset_modified_time(fsi_.source_path)) {
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, fsi_.api_path, fsi_.source_path,
|
||||
utils::get_last_error_code(), "failed to reset modified time");
|
||||
|
@ -24,8 +24,6 @@
|
||||
#include "platform/unix_platform.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "types/startup_exception.hpp"
|
||||
#include "utils/common.hpp"
|
||||
|
@ -23,14 +23,12 @@
|
||||
|
||||
#include "platform/win32_platform.hpp"
|
||||
|
||||
#include "events/event_system.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
auto lock_data::get_mount_state(const provider_type & /*pt*/,
|
||||
json &mount_state) -> bool {
|
||||
auto lock_data::get_mount_state(const provider_type & /*pt*/, json &mount_state)
|
||||
-> bool {
|
||||
const auto ret = get_mount_state(mount_state);
|
||||
if (ret) {
|
||||
const auto mount_id =
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include "file_manager/cache_size_mgr.hpp"
|
||||
#include "file_manager/i_file_manager.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/polling.hpp"
|
||||
|
@ -29,18 +29,22 @@
|
||||
#include "utils/collection.hpp"
|
||||
#include "utils/encrypting_reader.hpp"
|
||||
#include "utils/encryption.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/polling.hpp"
|
||||
|
||||
namespace {
|
||||
const std::string file_table = "file";
|
||||
} // namespace
|
||||
|
||||
namespace repertory {
|
||||
encrypt_provider::encrypt_provider(app_config &config)
|
||||
: config_(config), encrypt_config_(config.get_encrypt_config()) {}
|
||||
|
||||
auto encrypt_provider::create_api_file(
|
||||
const std::string &api_path, bool directory,
|
||||
const std::string &source_path) -> api_file {
|
||||
auto encrypt_provider::create_api_file(const std::string &api_path,
|
||||
bool directory,
|
||||
const std::string &source_path)
|
||||
-> api_file {
|
||||
auto times = utils::file::get_times(source_path);
|
||||
if (not times.has_value()) {
|
||||
throw std::runtime_error("failed to get file times");
|
||||
@ -66,10 +70,10 @@ auto encrypt_provider::create_api_file(
|
||||
void encrypt_provider::create_item_meta(api_meta_map &meta, bool directory,
|
||||
const api_file &file) {
|
||||
#if defined(_WIN32)
|
||||
struct _stat64 buf {};
|
||||
struct _stat64 buf{};
|
||||
_stat64(file.source_path.c_str(), &buf);
|
||||
#else // !defined(_WIN32)
|
||||
struct stat buf {};
|
||||
struct stat buf{};
|
||||
stat(file.source_path.c_str(), &buf);
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
@ -149,8 +153,9 @@ auto encrypt_provider::do_fs_operation(
|
||||
return callback(cfg, source_path);
|
||||
}
|
||||
|
||||
auto encrypt_provider::get_api_path_from_source(
|
||||
const std::string &source_path, std::string &api_path) const -> api_error {
|
||||
auto encrypt_provider::get_api_path_from_source(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
@ -189,8 +194,9 @@ auto encrypt_provider::get_directory_item_count(
|
||||
return count;
|
||||
}
|
||||
|
||||
auto encrypt_provider::get_directory_items(
|
||||
const std::string &api_path, directory_item_list &list) const -> api_error {
|
||||
auto encrypt_provider::get_directory_items(const std::string &api_path,
|
||||
directory_item_list &list) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
return do_fs_operation(
|
||||
@ -318,8 +324,9 @@ auto encrypt_provider::get_file(const std::string &api_path,
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
auto encrypt_provider::get_file_list(
|
||||
api_file_list &list, std::string & /* marker */) const -> api_error {
|
||||
auto encrypt_provider::get_file_list(api_file_list &list,
|
||||
std::string & /* marker */) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
const auto &cfg = get_encrypt_config();
|
||||
@ -342,8 +349,9 @@ auto encrypt_provider::get_file_list(
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
auto encrypt_provider::get_file_size(
|
||||
const std::string &api_path, std::uint64_t &file_size) const -> api_error {
|
||||
auto encrypt_provider::get_file_size(const std::string &api_path,
|
||||
std::uint64_t &file_size) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
@ -364,9 +372,10 @@ auto encrypt_provider::get_file_size(
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
auto encrypt_provider::get_filesystem_item(
|
||||
const std::string &api_path, bool directory,
|
||||
filesystem_item &fsi) const -> api_error {
|
||||
auto encrypt_provider::get_filesystem_item(const std::string &api_path,
|
||||
bool directory,
|
||||
filesystem_item &fsi) const
|
||||
-> api_error {
|
||||
std::string source_path;
|
||||
if (directory) {
|
||||
auto result = db_->get_directory_source_path(api_path, source_path);
|
||||
@ -417,9 +426,10 @@ auto encrypt_provider::get_filesystem_item_from_source_path(
|
||||
return get_filesystem_item(api_path, false, fsi);
|
||||
}
|
||||
|
||||
auto encrypt_provider::get_filesystem_item_and_file(
|
||||
const std::string &api_path, api_file &file,
|
||||
filesystem_item &fsi) const -> api_error {
|
||||
auto encrypt_provider::get_filesystem_item_and_file(const std::string &api_path,
|
||||
api_file &file,
|
||||
filesystem_item &fsi) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
@ -544,8 +554,8 @@ auto encrypt_provider::is_directory(const std::string &api_path,
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
auto encrypt_provider::is_file(const std::string &api_path,
|
||||
bool &exists) const -> api_error {
|
||||
auto encrypt_provider::is_file(const std::string &api_path, bool &exists) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
|
@ -23,8 +23,6 @@
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "comm/i_http_comm.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "file_manager/i_file_manager.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/s3.hpp"
|
||||
@ -43,8 +41,9 @@ namespace repertory {
|
||||
s3_provider::s3_provider(app_config &config, i_http_comm &comm)
|
||||
: base_provider(config, comm) {}
|
||||
|
||||
auto s3_provider::add_if_not_found(
|
||||
api_file &file, const std::string &object_name) const -> api_error {
|
||||
auto s3_provider::add_if_not_found(api_file &file,
|
||||
const std::string &object_name) const
|
||||
-> api_error {
|
||||
api_meta_map meta{};
|
||||
if (get_item_meta(file.api_path, meta) == api_error::item_not_found) {
|
||||
auto err = create_path_directories(
|
||||
@ -70,7 +69,7 @@ auto s3_provider::convert_api_date(std::string_view date) -> std::uint64_t {
|
||||
utils::string::split(date_parts.at(1U), 'Z', true).at(0U)) *
|
||||
1000000UL;
|
||||
|
||||
struct tm tm1 {};
|
||||
struct tm tm1{};
|
||||
#if defined(_WIN32)
|
||||
utils::time::strptime(date_time.c_str(), "%Y-%m-%dT%T", &tm1);
|
||||
return nanos + utils::time::windows_time_t_to_unix_time(_mkgmtime(&tm1));
|
||||
@ -162,8 +161,9 @@ auto s3_provider::create_file_extra(const std::string &api_path,
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto s3_provider::create_path_directories(
|
||||
const std::string &api_path, const std::string &key) const -> api_error {
|
||||
auto s3_provider::create_path_directories(const std::string &api_path,
|
||||
const std::string &key) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
if (api_path == "/") {
|
||||
@ -330,8 +330,9 @@ auto s3_provider::get_directory_item_count(const std::string &api_path) const
|
||||
return 0U;
|
||||
}
|
||||
|
||||
auto s3_provider::get_directory_items_impl(
|
||||
const std::string &api_path, directory_item_list &list) const -> api_error {
|
||||
auto s3_provider::get_directory_items_impl(const std::string &api_path,
|
||||
directory_item_list &list) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
const auto &cfg = get_s3_config();
|
||||
@ -476,8 +477,8 @@ auto s3_provider::get_directory_items_impl(
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto s3_provider::get_file(const std::string &api_path,
|
||||
api_file &file) const -> api_error {
|
||||
auto s3_provider::get_file(const std::string &api_path, api_file &file) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
@ -516,8 +517,8 @@ auto s3_provider::get_file(const std::string &api_path,
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
auto s3_provider::get_file_list(api_file_list &list,
|
||||
std::string &marker) const -> api_error {
|
||||
auto s3_provider::get_file_list(api_file_list &list, std::string &marker) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
std::string response_data;
|
||||
@ -592,8 +593,9 @@ auto s3_provider::get_file_list(api_file_list &list,
|
||||
return grab_more ? api_error::more_data : api_error::success;
|
||||
}
|
||||
|
||||
auto s3_provider::get_last_modified(
|
||||
bool directory, const std::string &api_path) const -> std::uint64_t {
|
||||
auto s3_provider::get_last_modified(bool directory,
|
||||
const std::string &api_path) const
|
||||
-> std::uint64_t {
|
||||
bool is_encrypted{};
|
||||
std::string object_name;
|
||||
head_object_result result{};
|
||||
@ -603,9 +605,10 @@ auto s3_provider::get_last_modified(
|
||||
: utils::time::get_time_now();
|
||||
}
|
||||
|
||||
auto s3_provider::get_object_info(
|
||||
bool directory, const std::string &api_path, bool &is_encrypted,
|
||||
std::string &object_name, head_object_result &result) const -> api_error {
|
||||
auto s3_provider::get_object_info(bool directory, const std::string &api_path,
|
||||
bool &is_encrypted, std::string &object_name,
|
||||
head_object_result &result) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
@ -654,10 +657,12 @@ auto s3_provider::get_object_info(
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
auto s3_provider::get_object_list(
|
||||
std::string &response_data, long &response_code,
|
||||
std::optional<std::string> delimiter, std::optional<std::string> prefix,
|
||||
std::optional<std::string> token) const -> bool {
|
||||
auto s3_provider::get_object_list(std::string &response_data,
|
||||
long &response_code,
|
||||
std::optional<std::string> delimiter,
|
||||
std::optional<std::string> prefix,
|
||||
std::optional<std::string> token) const
|
||||
-> bool {
|
||||
curl::requests::http_get get{};
|
||||
get.allow_timeout = true;
|
||||
get.aws_service = "aws:amz:" + get_s3_config().region + ":s3";
|
||||
@ -686,8 +691,8 @@ auto s3_provider::get_total_drive_space() const -> std::uint64_t {
|
||||
return std::numeric_limits<std::int64_t>::max() / std::int64_t(2);
|
||||
}
|
||||
|
||||
auto s3_provider::is_directory(const std::string &api_path,
|
||||
bool &exists) const -> api_error {
|
||||
auto s3_provider::is_directory(const std::string &api_path, bool &exists) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
exists = false;
|
||||
@ -714,8 +719,8 @@ auto s3_provider::is_directory(const std::string &api_path,
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
auto s3_provider::is_file(const std::string &api_path,
|
||||
bool &exists) const -> api_error {
|
||||
auto s3_provider::is_file(const std::string &api_path, bool &exists) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
exists = false;
|
||||
|
@ -22,14 +22,10 @@
|
||||
#include "rpc/server/full_server.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "file_manager/cache_size_mgr.hpp"
|
||||
#include "file_manager/i_file_manager.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/rpc.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/path.hpp"
|
||||
|
||||
@ -51,9 +47,11 @@ void full_server::handle_get_directory_items(const httplib::Request &req,
|
||||
|
||||
void full_server::handle_get_drive_information(const httplib::Request & /*req*/,
|
||||
httplib::Response &res) {
|
||||
auto dir_size =
|
||||
utils::file::directory(get_config().get_cache_directory()).size();
|
||||
res.set_content(
|
||||
json({
|
||||
{"cache_space_used", cache_size_mgr::instance().size()},
|
||||
{"cache_space_used", dir_size},
|
||||
{"drive_space_total", provider_.get_total_drive_space()},
|
||||
{"drive_space_used", provider_.get_used_drive_space()},
|
||||
{"item_count", provider_.get_total_item_count()},
|
||||
|
@ -22,8 +22,6 @@
|
||||
#include "rpc/server/server.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "utils/base64.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
|
||||
|
@ -25,8 +25,8 @@
|
||||
#include "utils/string.hpp"
|
||||
|
||||
namespace repertory {
|
||||
auto database_type_from_string(std::string type,
|
||||
database_type default_type) -> database_type {
|
||||
auto database_type_from_string(std::string type, database_type default_type)
|
||||
-> database_type {
|
||||
type = utils::string::to_lower(utils::string::trim(type));
|
||||
if (type == "rocksdb") {
|
||||
return database_type::rocksdb;
|
||||
@ -50,17 +50,17 @@ auto database_type_to_string(const database_type &type) -> std::string {
|
||||
}
|
||||
}
|
||||
|
||||
auto download_type_from_string(std::string type,
|
||||
download_type default_type) -> download_type {
|
||||
auto download_type_from_string(std::string type, download_type default_type)
|
||||
-> download_type {
|
||||
type = utils::string::to_lower(utils::string::trim(type));
|
||||
if (type == "default") {
|
||||
return download_type::default_;
|
||||
}
|
||||
|
||||
if (type == "direct") {
|
||||
return download_type::direct;
|
||||
}
|
||||
|
||||
if (type == "fallback") {
|
||||
return download_type::fallback;
|
||||
}
|
||||
|
||||
if (type == "ring_buffer") {
|
||||
return download_type::ring_buffer;
|
||||
}
|
||||
@ -70,14 +70,14 @@ auto download_type_from_string(std::string type,
|
||||
|
||||
auto download_type_to_string(const download_type &type) -> std::string {
|
||||
switch (type) {
|
||||
case download_type::default_:
|
||||
return "default";
|
||||
case download_type::direct:
|
||||
return "direct";
|
||||
case download_type::fallback:
|
||||
return "fallback";
|
||||
case download_type::ring_buffer:
|
||||
return "ring_buffer";
|
||||
default:
|
||||
return "default";
|
||||
return "fallback";
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,7 +87,6 @@ static const std::unordered_map<api_error, std::string> LOOKUP = {
|
||||
{api_error::bad_address, "bad_address"},
|
||||
{api_error::buffer_overflow, "buffer_overflow"},
|
||||
{api_error::buffer_too_small, "buffer_too_small"},
|
||||
{api_error::cache_not_initialized, "cache_not_initialized"},
|
||||
{api_error::comm_error, "comm_error"},
|
||||
{api_error::decryption_error, "decryption_error"},
|
||||
{api_error::directory_end_of_files, "directory_end_of_files"},
|
||||
@ -106,7 +105,6 @@ static const std::unordered_map<api_error, std::string> LOOKUP = {
|
||||
{api_error::invalid_handle, "invalid_handle"},
|
||||
{api_error::invalid_operation, "invalid_operation"},
|
||||
{api_error::invalid_ring_buffer_multiple, "invalid_ring_buffer_multiple"},
|
||||
{api_error::invalid_ring_buffer_position, "invalid_ring_buffer_position"},
|
||||
{api_error::invalid_ring_buffer_size, "invalid_ring_buffer_size"},
|
||||
{api_error::invalid_version, "invalid_version"},
|
||||
{api_error::item_exists, "item_exists"},
|
||||
|
@ -22,8 +22,6 @@
|
||||
#include "utils/polling.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "utils/tasks.hpp"
|
||||
|
||||
namespace repertory {
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "utils/tasks.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
tasks tasks::instance_;
|
||||
|
@ -52,8 +52,6 @@ auto from_api_error(const api_error &err) -> int {
|
||||
return -EEXIST;
|
||||
case api_error::file_in_use:
|
||||
return -EBUSY;
|
||||
case api_error::invalid_handle:
|
||||
return -EBADF;
|
||||
case api_error::invalid_operation:
|
||||
return -EINVAL;
|
||||
case api_error::item_not_found:
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "app_config.hpp"
|
||||
#include "types/startup_exception.hpp"
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/string.hpp"
|
||||
@ -51,8 +50,8 @@ void calculate_allocation_size(bool directory, std::uint64_t file_size,
|
||||
auto create_rocksdb(
|
||||
const app_config &cfg, const std::string &name,
|
||||
const std::vector<rocksdb::ColumnFamilyDescriptor> &families,
|
||||
std::vector<rocksdb::ColumnFamilyHandle *> &handles,
|
||||
bool clear) -> std::unique_ptr<rocksdb::TransactionDB> {
|
||||
std::vector<rocksdb::ColumnFamilyHandle *> &handles, bool clear)
|
||||
-> std::unique_ptr<rocksdb::TransactionDB> {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto db_dir = utils::path::combine(cfg.get_data_directory(), {"db"});
|
||||
|
@ -29,13 +29,6 @@
|
||||
namespace repertory {
|
||||
class mock_open_file : public virtual i_closeable_open_file {
|
||||
public:
|
||||
MOCK_METHOD(void, add, (std::uint64_t handle, open_file_data ofd),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(bool, can_close, (), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, close, (), (override));
|
||||
|
||||
MOCK_METHOD(std::string, get_api_path, (), (const, override));
|
||||
|
||||
MOCK_METHOD(std::size_t, get_chunk_size, (), (const, override));
|
||||
@ -54,30 +47,14 @@ public:
|
||||
|
||||
MOCK_METHOD(boost::dynamic_bitset<>, get_read_state, (), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, get_allocated, (), (const, override));
|
||||
|
||||
MOCK_METHOD(std::vector<std::uint64_t>, get_handles, (), (const, override));
|
||||
|
||||
MOCK_METHOD((std::map<std::uint64_t, open_file_data> &), get_open_data, (),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD((const std::map<std::uint64_t, open_file_data> &), get_open_data,
|
||||
(), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, get_read_state, (std::size_t chunk), (const, override));
|
||||
|
||||
MOCK_METHOD(std::string, get_source_path, (), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, has_handle, (std::uint64_t handle), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, is_complete, (), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, is_directory, (), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, is_modified, (), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, is_write_supported, (), (const, override));
|
||||
|
||||
MOCK_METHOD(api_error, native_operation, (native_operation_callback callback),
|
||||
(override));
|
||||
|
||||
@ -90,10 +67,6 @@ public:
|
||||
data_buffer &data),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(void, remove, (std::uint64_t handle), (override));
|
||||
|
||||
MOCK_METHOD(void, remove_all, (), (override));
|
||||
|
||||
MOCK_METHOD(api_error, resize, (std::uint64_t new_file_size), (override));
|
||||
|
||||
MOCK_METHOD(void, set_api_path, (const std::string &api_path), (override));
|
||||
@ -102,6 +75,31 @@ public:
|
||||
(std::uint64_t write_offset, const data_buffer &data,
|
||||
std::size_t &bytes_written),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(void, add, (std::uint64_t handle, open_file_data ofd),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(bool, can_close, (), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, close, (), (override));
|
||||
|
||||
MOCK_METHOD(std::vector<std::uint64_t>, get_handles, (), (const, override));
|
||||
|
||||
MOCK_METHOD((std::map<std::uint64_t, open_file_data> &), get_open_data, (),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD((const std::map<std::uint64_t, open_file_data> &), get_open_data,
|
||||
(), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, is_complete, (), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, is_modified, (), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, is_write_supported, (), (const, override));
|
||||
|
||||
MOCK_METHOD(void, remove, (std::uint64_t handle), (override));
|
||||
|
||||
MOCK_METHOD(void, remove_all, (), (override));
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -28,11 +28,6 @@ TEST(atomic, atomic_primitive) {
|
||||
atomic<std::uint16_t> value;
|
||||
value = 5U;
|
||||
EXPECT_EQ(5U, static_cast<std::uint16_t>(value));
|
||||
EXPECT_EQ(5U, value.load());
|
||||
|
||||
value.store(6U);
|
||||
EXPECT_EQ(6U, static_cast<std::uint16_t>(value));
|
||||
EXPECT_EQ(6U, value.load());
|
||||
}
|
||||
|
||||
TEST(atomic, atomic_primitive_equality) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@ -30,8 +30,7 @@
|
||||
namespace repertory {
|
||||
class config_test : public ::testing::Test {
|
||||
public:
|
||||
console_consumer cs;
|
||||
|
||||
static console_consumer cs;
|
||||
static std::atomic<std::uint64_t> idx;
|
||||
|
||||
std::string s3_directory;
|
||||
@ -57,6 +56,7 @@ public:
|
||||
void TearDown() override { event_system::instance().stop(); }
|
||||
};
|
||||
|
||||
console_consumer config_test::cs;
|
||||
std::atomic<std::uint64_t> config_test::idx{0U};
|
||||
|
||||
TEST_F(config_test, api_path) {
|
||||
@ -138,6 +138,20 @@ TEST_F(config_test, enable_download_timeout) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(config_test, enable_comm_duration_events) {
|
||||
bool original_value{};
|
||||
{
|
||||
app_config config(provider_type::sia, sia_directory);
|
||||
original_value = config.get_enable_comm_duration_events();
|
||||
config.set_enable_comm_duration_events(not original_value);
|
||||
EXPECT_EQ(not original_value, config.get_enable_comm_duration_events());
|
||||
}
|
||||
{
|
||||
app_config config(provider_type::sia, sia_directory);
|
||||
EXPECT_EQ(not original_value, config.get_enable_comm_duration_events());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(config_test, enable_drive_events) {
|
||||
bool original_value{};
|
||||
{
|
||||
|
@ -1,292 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "file_manager/direct_open_file.hpp"
|
||||
#include "mocks/mock_provider.hpp"
|
||||
|
||||
namespace {
|
||||
constexpr const std::size_t test_chunk_size{1024U};
|
||||
} // namespace
|
||||
|
||||
namespace repertory {
|
||||
class direct_open_file_test : public ::testing::Test {
|
||||
public:
|
||||
console_consumer con_consumer;
|
||||
mock_provider provider;
|
||||
|
||||
protected:
|
||||
void SetUp() override { event_system::instance().start(); }
|
||||
|
||||
void TearDown() override { event_system::instance().stop(); }
|
||||
};
|
||||
|
||||
TEST_F(direct_open_file_test, read_full_file) {
|
||||
auto &source_file = test::create_random_file(test_chunk_size * 32U);
|
||||
|
||||
auto dest_path = test::generate_test_file_name("direct_open_file");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.directory = false;
|
||||
fsi.size = test_chunk_size * 32U;
|
||||
|
||||
std::mutex read_mtx;
|
||||
EXPECT_CALL(provider, read_file_bytes)
|
||||
.WillRepeatedly([&read_mtx, &source_file](
|
||||
const std::string & /* api_path */, std::size_t size,
|
||||
std::uint64_t offset, data_buffer &data,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
mutex_lock lock(read_mtx);
|
||||
|
||||
EXPECT_FALSE(stop_requested);
|
||||
std::size_t bytes_read{};
|
||||
data.resize(size);
|
||||
auto ret = source_file.read(data, offset, &bytes_read)
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
EXPECT_EQ(bytes_read, data.size());
|
||||
return ret;
|
||||
});
|
||||
{
|
||||
direct_open_file file(test_chunk_size, 30U, fsi, provider);
|
||||
|
||||
auto dest_file = utils::file::file::open_or_create_file(dest_path);
|
||||
EXPECT_TRUE(dest_file);
|
||||
|
||||
auto to_read{fsi.size};
|
||||
std::size_t chunk{0U};
|
||||
while (to_read > 0U) {
|
||||
data_buffer data{};
|
||||
EXPECT_EQ(api_error::success,
|
||||
file.read(test_chunk_size, chunk * test_chunk_size, data));
|
||||
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_TRUE(
|
||||
dest_file->write(data, chunk * test_chunk_size, &bytes_written));
|
||||
++chunk;
|
||||
to_read -= data.size();
|
||||
}
|
||||
dest_file->close();
|
||||
source_file.close();
|
||||
|
||||
auto hash1 = utils::file::file(source_file.get_path()).sha256();
|
||||
auto hash2 = utils::file::file(dest_path).sha256();
|
||||
|
||||
EXPECT_TRUE(hash1.has_value());
|
||||
EXPECT_TRUE(hash2.has_value());
|
||||
if (hash1.has_value() && hash2.has_value()) {
|
||||
EXPECT_STREQ(hash1.value().c_str(), hash2.value().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(direct_open_file_test, read_full_file_in_reverse) {
|
||||
auto &source_file = test::create_random_file(test_chunk_size * 32U);
|
||||
|
||||
auto dest_path = test::generate_test_file_name("direct_open_file");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.directory = false;
|
||||
fsi.size = test_chunk_size * 32U;
|
||||
|
||||
std::mutex read_mtx;
|
||||
EXPECT_CALL(provider, read_file_bytes)
|
||||
.WillRepeatedly([&read_mtx, &source_file](
|
||||
const std::string & /* api_path */, std::size_t size,
|
||||
std::uint64_t offset, data_buffer &data,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
mutex_lock lock(read_mtx);
|
||||
|
||||
EXPECT_FALSE(stop_requested);
|
||||
std::size_t bytes_read{};
|
||||
data.resize(size);
|
||||
auto ret = source_file.read(data, offset, &bytes_read)
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
EXPECT_EQ(bytes_read, data.size());
|
||||
return ret;
|
||||
});
|
||||
{
|
||||
direct_open_file file(test_chunk_size, 30U, fsi, provider);
|
||||
|
||||
auto dest_file = utils::file::file::open_or_create_file(dest_path);
|
||||
EXPECT_TRUE(dest_file);
|
||||
|
||||
auto to_read{fsi.size};
|
||||
std::size_t chunk{file.get_total_chunks() - 1U};
|
||||
while (to_read > 0U) {
|
||||
data_buffer data{};
|
||||
EXPECT_EQ(api_error::success,
|
||||
file.read(test_chunk_size, chunk * test_chunk_size, data));
|
||||
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_TRUE(
|
||||
dest_file->write(data, chunk * test_chunk_size, &bytes_written));
|
||||
--chunk;
|
||||
to_read -= data.size();
|
||||
}
|
||||
dest_file->close();
|
||||
source_file.close();
|
||||
|
||||
auto hash1 = utils::file::file(source_file.get_path()).sha256();
|
||||
auto hash2 = utils::file::file(dest_path).sha256();
|
||||
|
||||
EXPECT_TRUE(hash1.has_value());
|
||||
EXPECT_TRUE(hash2.has_value());
|
||||
if (hash1.has_value() && hash2.has_value()) {
|
||||
EXPECT_STREQ(hash1.value().c_str(), hash2.value().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(direct_open_file_test, read_full_file_in_partial_chunks) {
|
||||
auto &source_file = test::create_random_file(test_chunk_size * 32U);
|
||||
|
||||
auto dest_path = test::generate_test_file_name("test");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.directory = false;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.size = test_chunk_size * 32U;
|
||||
|
||||
std::mutex read_mtx;
|
||||
EXPECT_CALL(provider, read_file_bytes)
|
||||
.WillRepeatedly([&read_mtx, &source_file](
|
||||
const std::string & /* api_path */, std::size_t size,
|
||||
std::uint64_t offset, data_buffer &data,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
mutex_lock lock(read_mtx);
|
||||
|
||||
EXPECT_FALSE(stop_requested);
|
||||
std::size_t bytes_read{};
|
||||
data.resize(size);
|
||||
auto ret = source_file.read(data, offset, &bytes_read)
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
EXPECT_EQ(bytes_read, data.size());
|
||||
return ret;
|
||||
});
|
||||
{
|
||||
direct_open_file file(test_chunk_size, 30U, fsi, provider);
|
||||
|
||||
auto dest_file = utils::file::file::open_or_create_file(dest_path);
|
||||
EXPECT_TRUE(dest_file);
|
||||
|
||||
auto total_read{std::uint64_t(0U)};
|
||||
while (total_read < fsi.size) {
|
||||
data_buffer data{};
|
||||
EXPECT_EQ(api_error::success, file.read(3U, total_read, data));
|
||||
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_TRUE(dest_file->write(data.data(), data.size(), total_read,
|
||||
&bytes_written));
|
||||
total_read += data.size();
|
||||
}
|
||||
dest_file->close();
|
||||
source_file.close();
|
||||
|
||||
auto hash1 = utils::file::file(source_file.get_path()).sha256();
|
||||
auto hash2 = utils::file::file(dest_path).sha256();
|
||||
|
||||
EXPECT_TRUE(hash1.has_value());
|
||||
EXPECT_TRUE(hash2.has_value());
|
||||
if (hash1.has_value() && hash2.has_value()) {
|
||||
EXPECT_STREQ(hash1.value().c_str(), hash2.value().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(direct_open_file_test, read_full_file_in_partial_chunks_in_reverse) {
|
||||
auto &source_file = test::create_random_file(test_chunk_size * 32U);
|
||||
|
||||
auto dest_path = test::generate_test_file_name("direct_open_file");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.directory = false;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.size = test_chunk_size * 32U;
|
||||
|
||||
std::mutex read_mtx;
|
||||
EXPECT_CALL(provider, read_file_bytes)
|
||||
.WillRepeatedly([&read_mtx, &source_file](
|
||||
const std::string & /* api_path */, std::size_t size,
|
||||
std::uint64_t offset, data_buffer &data,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
mutex_lock lock(read_mtx);
|
||||
|
||||
EXPECT_FALSE(stop_requested);
|
||||
std::size_t bytes_read{};
|
||||
data.resize(size);
|
||||
auto ret = source_file.read(data, offset, &bytes_read)
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
EXPECT_EQ(bytes_read, data.size());
|
||||
return ret;
|
||||
});
|
||||
{
|
||||
direct_open_file file(test_chunk_size, 30U, fsi, provider);
|
||||
|
||||
auto dest_file = utils::file::file::open_or_create_file(dest_path);
|
||||
EXPECT_TRUE(dest_file);
|
||||
|
||||
std::uint64_t total_read{0U};
|
||||
auto read_size{3U};
|
||||
|
||||
while (total_read < fsi.size) {
|
||||
auto offset = fsi.size - total_read - read_size;
|
||||
auto remain = fsi.size - total_read;
|
||||
|
||||
data_buffer data{};
|
||||
EXPECT_EQ(api_error::success,
|
||||
file.read(static_cast<std::size_t>(
|
||||
std::min(remain, std::uint64_t(read_size))),
|
||||
(remain >= read_size) ? offset : 0U, data));
|
||||
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_TRUE(dest_file->write(data, (remain >= read_size) ? offset : 0U,
|
||||
&bytes_written));
|
||||
total_read += data.size();
|
||||
}
|
||||
dest_file->close();
|
||||
source_file.close();
|
||||
|
||||
auto hash1 = utils::file::file(source_file.get_path()).sha256();
|
||||
auto hash2 = utils::file::file(dest_path).sha256();
|
||||
|
||||
EXPECT_TRUE(hash1.has_value());
|
||||
EXPECT_TRUE(hash2.has_value());
|
||||
if (hash1.has_value() && hash2.has_value()) {
|
||||
EXPECT_STREQ(hash1.value().c_str(), hash2.value().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace repertory
|
@ -22,7 +22,6 @@
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "file_manager/cache_size_mgr.hpp"
|
||||
#include "file_manager/events.hpp"
|
||||
#include "file_manager/file_manager.hpp"
|
||||
#include "file_manager/i_open_file.hpp"
|
||||
@ -52,7 +51,7 @@ auto file_manager::open(std::shared_ptr<i_closeable_open_file> of,
|
||||
|
||||
class file_manager_test : public ::testing::Test {
|
||||
public:
|
||||
console_consumer con_consumer;
|
||||
console_consumer c;
|
||||
std::unique_ptr<app_config> cfg;
|
||||
mock_provider mp;
|
||||
static std::atomic<std::size_t> inst;
|
||||
@ -68,8 +67,6 @@ protected:
|
||||
|
||||
cfg = std::make_unique<app_config>(provider_type::sia, file_manager_dir);
|
||||
cfg->set_enable_download_timeout(false);
|
||||
|
||||
cache_size_mgr::instance().initialize(cfg.get());
|
||||
}
|
||||
|
||||
void TearDown() override { event_system::instance().stop(); }
|
||||
@ -431,6 +428,16 @@ TEST_F(file_manager_test,
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
std::uint64_t handle{};
|
||||
std::shared_ptr<i_open_file> open_file;
|
||||
#if defined(_WIN32)
|
||||
EXPECT_EQ(api_error::success, mgr.open("/test_write_partial_download.txt",
|
||||
false, {}, handle, open_file));
|
||||
#else
|
||||
EXPECT_EQ(api_error::success, mgr.open("/test_write_partial_download.txt",
|
||||
false, O_RDWR, handle, open_file));
|
||||
#endif
|
||||
|
||||
EXPECT_CALL(mp, read_file_bytes)
|
||||
.WillRepeatedly([&file](const std::string & /* api_path */,
|
||||
std::size_t size, std::uint64_t offset,
|
||||
@ -455,17 +462,6 @@ TEST_F(file_manager_test,
|
||||
|
||||
return api_error::download_stopped;
|
||||
});
|
||||
|
||||
std::uint64_t handle{};
|
||||
std::shared_ptr<i_open_file> open_file;
|
||||
#if defined(_WIN32)
|
||||
EXPECT_EQ(api_error::success, mgr.open("/test_write_partial_download.txt",
|
||||
false, {}, handle, open_file));
|
||||
#else
|
||||
EXPECT_EQ(api_error::success, mgr.open("/test_write_partial_download.txt",
|
||||
false, O_RDWR, handle, open_file));
|
||||
#endif
|
||||
|
||||
EXPECT_CALL(mp, set_item_meta("/test_write_partial_download.txt", _))
|
||||
.WillOnce(
|
||||
[](const std::string &, const api_meta_map &meta2) -> api_error {
|
||||
@ -476,10 +472,6 @@ TEST_F(file_manager_test,
|
||||
});
|
||||
EXPECT_CALL(mp, upload_file).Times(0u);
|
||||
|
||||
if (not open_file->is_write_supported()) {
|
||||
EXPECT_TRUE(mgr.get_open_file(handle, true, open_file));
|
||||
}
|
||||
|
||||
std::size_t bytes_written{};
|
||||
data_buffer data = {0, 1, 2};
|
||||
EXPECT_EQ(api_error::success, open_file->write(0u, data, bytes_written));
|
||||
@ -565,6 +557,7 @@ TEST_F(file_manager_test, upload_occurs_after_write_if_fully_downloaded) {
|
||||
EXPECT_STREQ(source_path.c_str(),
|
||||
evt2.get_source().get<std::string>().c_str());
|
||||
});
|
||||
event_capture capture({"download_end"});
|
||||
|
||||
auto now = utils::time::get_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
@ -588,6 +581,16 @@ TEST_F(file_manager_test, upload_occurs_after_write_if_fully_downloaded) {
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
std::uint64_t handle{};
|
||||
std::shared_ptr<i_open_file> open_file;
|
||||
#if defined(_WIN32)
|
||||
EXPECT_EQ(api_error::success, mgr.open("/test_write_full_download.txt", false,
|
||||
{}, handle, open_file));
|
||||
#else
|
||||
EXPECT_EQ(api_error::success, mgr.open("/test_write_full_download.txt", false,
|
||||
O_RDWR, handle, open_file));
|
||||
#endif
|
||||
|
||||
EXPECT_CALL(mp, read_file_bytes)
|
||||
.WillRepeatedly([&file](const std::string & /* api_path */,
|
||||
std::size_t size, std::uint64_t offset,
|
||||
@ -600,17 +603,6 @@ TEST_F(file_manager_test, upload_occurs_after_write_if_fully_downloaded) {
|
||||
EXPECT_EQ(bytes_read, data.size());
|
||||
return ret;
|
||||
});
|
||||
|
||||
std::uint64_t handle{};
|
||||
std::shared_ptr<i_open_file> open_file;
|
||||
#if defined(_WIN32)
|
||||
EXPECT_EQ(api_error::success, mgr.open("/test_write_full_download.txt", false,
|
||||
{}, handle, open_file));
|
||||
#else
|
||||
EXPECT_EQ(api_error::success, mgr.open("/test_write_full_download.txt", false,
|
||||
O_RDWR, handle, open_file));
|
||||
#endif
|
||||
|
||||
EXPECT_CALL(mp, set_item_meta("/test_write_full_download.txt", _))
|
||||
.WillOnce(
|
||||
[](const std::string &, const api_meta_map &meta2) -> api_error {
|
||||
@ -619,33 +611,25 @@ TEST_F(file_manager_test, upload_occurs_after_write_if_fully_downloaded) {
|
||||
EXPECT_NO_THROW(EXPECT_FALSE(meta2.at(META_WRITTEN).empty()));
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
if (not open_file->is_write_supported()) {
|
||||
EXPECT_TRUE(mgr.get_open_file(handle, true, open_file));
|
||||
}
|
||||
|
||||
event_capture capture({
|
||||
"item_timeout",
|
||||
"file_upload_queued",
|
||||
"file_upload_completed",
|
||||
});
|
||||
|
||||
EXPECT_CALL(mp, upload_file("/test_write_full_download.txt", source_path, _))
|
||||
.WillOnce(Return(api_error::success));
|
||||
|
||||
std::size_t bytes_written{};
|
||||
data_buffer data = {0, 1, 2};
|
||||
EXPECT_EQ(api_error::success, open_file->write(0u, data, bytes_written));
|
||||
EXPECT_EQ(std::size_t(3u), bytes_written);
|
||||
|
||||
while (not open_file->is_complete()) {
|
||||
std::this_thread::sleep_for(10ms);
|
||||
}
|
||||
open_file.reset();
|
||||
|
||||
capture.wait_for_empty();
|
||||
|
||||
EXPECT_CALL(mp, upload_file("/test_write_full_download.txt", source_path, _))
|
||||
.WillOnce(Return(api_error::success));
|
||||
|
||||
event_capture ec2({
|
||||
"item_timeout",
|
||||
"file_upload_queued",
|
||||
"file_upload_completed",
|
||||
});
|
||||
mgr.close(handle);
|
||||
|
||||
capture.wait_for_empty();
|
||||
ec2.wait_for_empty();
|
||||
|
||||
EXPECT_EQ(std::size_t(0U), mgr.get_open_file_count());
|
||||
EXPECT_EQ(std::size_t(0U), mgr.get_open_handle_count());
|
||||
@ -710,14 +694,9 @@ TEST_F(file_manager_test, can_evict_file) {
|
||||
.WillRepeatedly(Return(api_error::success));
|
||||
EXPECT_CALL(mp, upload_file(_, _, _)).WillOnce(Return(api_error::success));
|
||||
|
||||
if (not open_file->is_write_supported()) {
|
||||
EXPECT_TRUE(mgr.get_open_file(handle, true, open_file));
|
||||
}
|
||||
|
||||
data_buffer data{{0, 1, 1}};
|
||||
std::size_t bytes_written{};
|
||||
auto res = open_file->write(0U, data, bytes_written);
|
||||
EXPECT_EQ(api_error::success, res);
|
||||
EXPECT_EQ(api_error::success, open_file->write(0U, data, bytes_written));
|
||||
|
||||
auto opt_size = utils::file::file{source_path}.size();
|
||||
EXPECT_TRUE(opt_size.has_value());
|
||||
@ -730,6 +709,15 @@ TEST_F(file_manager_test, can_evict_file) {
|
||||
EXPECT_TRUE(utils::retry_action(
|
||||
[&mgr]() -> bool { return not mgr.is_processing("/test_evict.txt"); }));
|
||||
|
||||
EXPECT_CALL(mp, get_item_meta(_, META_SOURCE, _))
|
||||
.WillOnce([&source_path](const std::string &api_path,
|
||||
const std::string &key,
|
||||
std::string &value) -> api_error {
|
||||
EXPECT_STREQ("/test_evict.txt", api_path.c_str());
|
||||
EXPECT_STREQ(META_SOURCE.c_str(), key.c_str());
|
||||
value = source_path;
|
||||
return api_error::success;
|
||||
});
|
||||
EXPECT_CALL(mp, get_item_meta(_, META_PINNED, _))
|
||||
.WillOnce([](const std::string &api_path, const std::string &key,
|
||||
std::string &value) -> api_error {
|
||||
@ -748,17 +736,6 @@ TEST_F(file_manager_test, evict_file_fails_if_file_is_pinned) {
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
file_manager mgr(*cfg, mp);
|
||||
|
||||
EXPECT_CALL(mp, get_filesystem_item)
|
||||
.WillRepeatedly([](const std::string &api_path, bool directory,
|
||||
filesystem_item &fsi) -> api_error {
|
||||
fsi.api_path = api_path;
|
||||
fsi.api_parent = utils::path::get_parent_api_path(api_path);
|
||||
fsi.directory = directory;
|
||||
fsi.size = 2U;
|
||||
fsi.source_path = "/test/test_open.src";
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
EXPECT_CALL(mp, get_item_meta(_, META_PINNED, _))
|
||||
.WillOnce([](const std::string &api_path, const std::string &key,
|
||||
std::string &value) -> api_error {
|
||||
@ -817,17 +794,28 @@ TEST_F(file_manager_test, evict_file_fails_if_file_is_open) {
|
||||
mgr.close(handle);
|
||||
}
|
||||
|
||||
TEST_F(file_manager_test, evict_file_fails_if_unable_to_get_filesystem_item) {
|
||||
TEST_F(file_manager_test,
|
||||
evict_file_fails_if_unable_to_get_source_path_from_item_meta) {
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
file_manager mgr(*cfg, mp);
|
||||
|
||||
EXPECT_CALL(mp, get_filesystem_item)
|
||||
.WillRepeatedly([](const std::string & /* api_path */,
|
||||
bool /* directory */,
|
||||
filesystem_item & /* fsi */) -> api_error {
|
||||
EXPECT_CALL(mp, get_item_meta(_, META_SOURCE, _))
|
||||
.WillOnce([](const std::string &api_path, const std::string &key,
|
||||
std::string & /*value*/) -> api_error {
|
||||
EXPECT_STREQ("/test_open.txt", api_path.c_str());
|
||||
EXPECT_STREQ(META_SOURCE.c_str(), key.c_str());
|
||||
return api_error::error;
|
||||
});
|
||||
|
||||
EXPECT_CALL(mp, get_item_meta(_, META_PINNED, _))
|
||||
.WillOnce([](const std::string &api_path, const std::string &key,
|
||||
std::string &value) -> api_error {
|
||||
EXPECT_STREQ("/test_open.txt", api_path.c_str());
|
||||
EXPECT_STREQ(META_PINNED.c_str(), key.c_str());
|
||||
value = "0";
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
EXPECT_FALSE(mgr.evict_file("/test_open.txt"));
|
||||
}
|
||||
|
||||
@ -835,13 +823,20 @@ TEST_F(file_manager_test, evict_file_fails_if_source_path_is_empty) {
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
file_manager mgr(*cfg, mp);
|
||||
|
||||
EXPECT_CALL(mp, get_filesystem_item)
|
||||
.WillRepeatedly([](const std::string &api_path, bool directory,
|
||||
filesystem_item &fsi) -> api_error {
|
||||
fsi.api_path = api_path;
|
||||
fsi.api_parent = utils::path::get_parent_api_path(api_path);
|
||||
fsi.directory = directory;
|
||||
fsi.size = 20U;
|
||||
EXPECT_CALL(mp, get_item_meta(_, META_SOURCE, _))
|
||||
.WillOnce([](const std::string &api_path, const std::string &key,
|
||||
std::string &value) -> api_error {
|
||||
EXPECT_STREQ("/test_open.txt", api_path.c_str());
|
||||
EXPECT_STREQ(META_SOURCE.c_str(), key.c_str());
|
||||
value = "";
|
||||
return api_error::success;
|
||||
});
|
||||
EXPECT_CALL(mp, get_item_meta(_, META_PINNED, _))
|
||||
.WillOnce([](const std::string &api_path, const std::string &key,
|
||||
std::string &value) -> api_error {
|
||||
EXPECT_STREQ("/test_open.txt", api_path.c_str());
|
||||
EXPECT_STREQ(META_PINNED.c_str(), key.c_str());
|
||||
value = "0";
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
@ -909,10 +904,6 @@ TEST_F(file_manager_test, evict_file_fails_if_file_is_uploading) {
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
if (not open_file->is_write_supported()) {
|
||||
EXPECT_TRUE(mgr.get_open_file(handle, true, open_file));
|
||||
}
|
||||
|
||||
data_buffer data{{0, 1, 1}};
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_EQ(api_error::success, open_file->write(0U, data, bytes_written));
|
||||
@ -956,7 +947,6 @@ TEST_F(file_manager_test, evict_file_fails_if_file_is_modified) {
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
file_manager mgr(*cfg, mp);
|
||||
|
||||
EXPECT_CALL(mp, get_filesystem_item)
|
||||
.WillOnce([](const std::string &api_path, bool directory,
|
||||
filesystem_item &fsi) -> api_error {
|
||||
@ -971,12 +961,11 @@ TEST_F(file_manager_test, evict_file_fails_if_file_is_modified) {
|
||||
});
|
||||
|
||||
auto file = std::make_shared<mock_open_file>();
|
||||
EXPECT_CALL(*file, is_directory).WillOnce(Return(false));
|
||||
EXPECT_CALL(*file, add).WillOnce(Return());
|
||||
EXPECT_CALL(*file, get_api_path).WillRepeatedly(Return("/test_evict.txt"));
|
||||
EXPECT_CALL(*file, get_source_path).WillRepeatedly(Return("/test_evict.src"));
|
||||
EXPECT_CALL(*file, is_directory).WillOnce(Return(false));
|
||||
EXPECT_CALL(*file, is_modified).WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(*file, is_write_supported).WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(*file, is_modified).Times(2).WillRepeatedly(Return(true));
|
||||
|
||||
std::uint64_t handle{};
|
||||
std::shared_ptr<i_open_file> open_file;
|
||||
@ -999,21 +988,20 @@ TEST_F(file_manager_test, evict_file_fails_if_file_is_not_complete) {
|
||||
filesystem_item &fsi) -> api_error {
|
||||
EXPECT_STREQ("/test_evict.txt", api_path.c_str());
|
||||
EXPECT_FALSE(directory);
|
||||
fsi.api_parent = utils::path::get_parent_api_path(api_path);
|
||||
fsi.api_path = api_path;
|
||||
fsi.api_parent = utils::path::get_parent_api_path(api_path);
|
||||
fsi.directory = directory;
|
||||
fsi.size = 1U;
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
auto file = std::make_shared<mock_open_file>();
|
||||
EXPECT_CALL(*file, is_directory).WillOnce(Return(false));
|
||||
EXPECT_CALL(*file, add).WillOnce(Return());
|
||||
EXPECT_CALL(*file, get_api_path).WillRepeatedly(Return("/test_evict.txt"));
|
||||
EXPECT_CALL(*file, get_source_path).WillRepeatedly(Return("/test_evict.src"));
|
||||
EXPECT_CALL(*file, is_complete).WillRepeatedly(Return(false));
|
||||
EXPECT_CALL(*file, is_directory).WillOnce(Return(false));
|
||||
EXPECT_CALL(*file, is_modified).WillRepeatedly(Return(false));
|
||||
EXPECT_CALL(*file, is_write_supported).WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(*file, is_modified).Times(2).WillRepeatedly(Return(false));
|
||||
EXPECT_CALL(*file, is_complete).Times(2).WillRepeatedly(Return(false));
|
||||
EXPECT_CALL(mp, set_item_meta("/test_evict.txt", META_SOURCE, _))
|
||||
.WillOnce(Return(api_error::success));
|
||||
|
||||
@ -1469,26 +1457,6 @@ TEST_F(file_manager_test, file_is_closed_after_download_timeout) {
|
||||
|
||||
event_capture capture({"item_timeout"});
|
||||
|
||||
EXPECT_CALL(mp, read_file_bytes)
|
||||
.WillRepeatedly([](const std::string & /* api_path */, std::size_t size,
|
||||
std::uint64_t offset, data_buffer &data,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
if (stop_requested) {
|
||||
return api_error::download_stopped;
|
||||
}
|
||||
|
||||
if (offset == 0U) {
|
||||
data.resize(size);
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
while (not stop_requested) {
|
||||
std::this_thread::sleep_for(100ms);
|
||||
}
|
||||
|
||||
return api_error::download_stopped;
|
||||
});
|
||||
|
||||
std::uint64_t handle{};
|
||||
std::shared_ptr<i_open_file> open_file;
|
||||
#if defined(_WIN32)
|
||||
@ -1499,15 +1467,33 @@ TEST_F(file_manager_test, file_is_closed_after_download_timeout) {
|
||||
O_RDWR, handle, open_file));
|
||||
#endif
|
||||
|
||||
EXPECT_CALL(mp, read_file_bytes)
|
||||
.WillRepeatedly([](const std::string & /* api_path */,
|
||||
std::size_t /*size*/, std::uint64_t offset,
|
||||
data_buffer & /*data*/,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
if (stop_requested) {
|
||||
return api_error::download_stopped;
|
||||
}
|
||||
|
||||
if (offset == 0U) {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
while (not stop_requested) {
|
||||
std::this_thread::sleep_for(100ms);
|
||||
}
|
||||
|
||||
return api_error::download_stopped;
|
||||
});
|
||||
|
||||
data_buffer data{};
|
||||
EXPECT_EQ(api_error::success, open_file->read(1U, 0U, data));
|
||||
|
||||
mgr.close(handle);
|
||||
|
||||
if (open_file->is_write_supported()) {
|
||||
EXPECT_CALL(mp, set_item_meta("/test_download_timeout.txt", META_SOURCE, _))
|
||||
.WillOnce(Return(api_error::success));
|
||||
}
|
||||
EXPECT_CALL(mp, set_item_meta("/test_download_timeout.txt", META_SOURCE, _))
|
||||
.WillOnce(Return(api_error::success));
|
||||
|
||||
EXPECT_EQ(std::size_t(1U), mgr.get_open_file_count());
|
||||
capture.wait_for_empty();
|
||||
|
@ -183,66 +183,4 @@ TEST(json_serialize, can_handle_sia_config) {
|
||||
EXPECT_STREQ(cfg2.bucket.c_str(), cfg.bucket.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(json_serialize, can_handle_atomic) {
|
||||
atomic<sia_config> cfg({
|
||||
"bucket",
|
||||
});
|
||||
|
||||
json data(cfg);
|
||||
EXPECT_STREQ("bucket", data.at(JSON_BUCKET).get<std::string>().c_str());
|
||||
|
||||
{
|
||||
auto cfg2 = data.get<atomic<sia_config>>();
|
||||
EXPECT_STREQ(cfg2.load().bucket.c_str(), cfg.load().bucket.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(json_serialize, can_handle_database_type) {
|
||||
json data(database_type::rocksdb);
|
||||
EXPECT_EQ(database_type::rocksdb, data.get<database_type>());
|
||||
EXPECT_STREQ("rocksdb", data.get<std::string>().c_str());
|
||||
|
||||
data = database_type::sqlite;
|
||||
EXPECT_EQ(database_type::sqlite, data.get<database_type>());
|
||||
EXPECT_STREQ("sqlite", data.get<std::string>().c_str());
|
||||
}
|
||||
|
||||
TEST(json_serialize, can_handle_download_type) {
|
||||
json data(download_type::direct);
|
||||
EXPECT_EQ(download_type::direct, data.get<download_type>());
|
||||
EXPECT_STREQ("direct", data.get<std::string>().c_str());
|
||||
|
||||
data = download_type::default_;
|
||||
EXPECT_EQ(download_type::default_, data.get<download_type>());
|
||||
EXPECT_STREQ("default", data.get<std::string>().c_str());
|
||||
|
||||
data = download_type::ring_buffer;
|
||||
EXPECT_EQ(download_type::ring_buffer, data.get<download_type>());
|
||||
EXPECT_STREQ("ring_buffer", data.get<std::string>().c_str());
|
||||
}
|
||||
|
||||
TEST(json_serialize, can_handle_atomic_database_type) {
|
||||
json data(atomic<database_type>{database_type::rocksdb});
|
||||
EXPECT_EQ(database_type::rocksdb, data.get<atomic<database_type>>());
|
||||
EXPECT_STREQ("rocksdb", data.get<std::string>().c_str());
|
||||
|
||||
data = atomic<database_type>(database_type::sqlite);
|
||||
EXPECT_EQ(database_type::sqlite, data.get<atomic<database_type>>());
|
||||
EXPECT_STREQ("sqlite", data.get<std::string>().c_str());
|
||||
}
|
||||
|
||||
TEST(json_serialize, can_handle_atomic_download_type) {
|
||||
json data(atomic<download_type>{download_type::direct});
|
||||
EXPECT_EQ(download_type::direct, data.get<atomic<download_type>>());
|
||||
EXPECT_STREQ("direct", data.get<std::string>().c_str());
|
||||
|
||||
data = atomic<download_type>{download_type::default_};
|
||||
EXPECT_EQ(download_type::default_, data.get<download_type>());
|
||||
EXPECT_STREQ("default", data.get<std::string>().c_str());
|
||||
|
||||
data = atomic<download_type>{download_type::ring_buffer};
|
||||
EXPECT_EQ(download_type::ring_buffer, data.get<atomic<download_type>>());
|
||||
EXPECT_STREQ("ring_buffer", data.get<std::string>().c_str());
|
||||
}
|
||||
} // namespace repertory
|
||||
|
@ -21,8 +21,6 @@
|
||||
*/
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "file_manager/cache_size_mgr.hpp"
|
||||
#include "file_manager/open_file.hpp"
|
||||
#include "mocks/mock_provider.hpp"
|
||||
#include "mocks/mock_upload_manager.hpp"
|
||||
@ -30,222 +28,191 @@
|
||||
#include "utils/event_capture.hpp"
|
||||
#include "utils/path.hpp"
|
||||
|
||||
namespace {
|
||||
constexpr const std::size_t test_chunk_size{1024U};
|
||||
}
|
||||
|
||||
namespace repertory {
|
||||
class open_file_test : public ::testing::Test {
|
||||
public:
|
||||
console_consumer con_consumer;
|
||||
std::unique_ptr<app_config> cfg;
|
||||
static std::atomic<std::size_t> inst;
|
||||
mock_provider provider;
|
||||
mock_upload_manager upload_mgr;
|
||||
static constexpr const std::size_t test_chunk_size = 1024u;
|
||||
|
||||
protected:
|
||||
void SetUp() override {
|
||||
event_system::instance().start();
|
||||
|
||||
auto open_file_dir = repertory::utils::path::combine(
|
||||
repertory::test::get_test_output_dir(),
|
||||
{"open_file_test" + std::to_string(++inst)});
|
||||
|
||||
cfg = std::make_unique<app_config>(provider_type::sia, open_file_dir);
|
||||
|
||||
cache_size_mgr::instance().initialize(cfg.get());
|
||||
}
|
||||
|
||||
void TearDown() override { event_system::instance().stop(); }
|
||||
};
|
||||
|
||||
std::atomic<std::size_t> open_file_test::inst{0U};
|
||||
|
||||
static void test_closeable_open_file(const open_file &file, bool directory,
|
||||
const api_error &err, std::uint64_t size,
|
||||
static void test_closeable_open_file(const open_file &o, bool directory,
|
||||
const api_error &e, std::uint64_t size,
|
||||
const std::string &source_path) {
|
||||
EXPECT_EQ(directory, file.is_directory());
|
||||
EXPECT_EQ(err, file.get_api_error());
|
||||
EXPECT_EQ(std::size_t(0U), file.get_open_file_count());
|
||||
EXPECT_EQ(std::uint64_t(size), file.get_file_size());
|
||||
EXPECT_STREQ(source_path.c_str(), file.get_source_path().c_str());
|
||||
EXPECT_TRUE(file.can_close());
|
||||
EXPECT_EQ(directory, o.is_directory());
|
||||
EXPECT_EQ(e, o.get_api_error());
|
||||
EXPECT_EQ(std::size_t(0u), o.get_open_file_count());
|
||||
EXPECT_EQ(std::uint64_t(size), o.get_file_size());
|
||||
EXPECT_STREQ(source_path.c_str(), o.get_source_path().c_str());
|
||||
EXPECT_TRUE(o.can_close());
|
||||
}
|
||||
|
||||
static void validate_write(open_file &file, std::size_t offset,
|
||||
data_buffer data, std::size_t bytes_written) {
|
||||
static void validate_write(open_file &o, std::size_t offset, data_buffer data,
|
||||
std::size_t bytes_written) {
|
||||
EXPECT_EQ(data.size(), bytes_written);
|
||||
|
||||
data_buffer read_data{};
|
||||
EXPECT_EQ(api_error::success, file.read(data.size(), offset, read_data));
|
||||
EXPECT_EQ(api_error::success, o.read(data.size(), offset, read_data));
|
||||
|
||||
EXPECT_TRUE(std::equal(data.begin(), data.end(), read_data.begin()));
|
||||
}
|
||||
|
||||
TEST_F(open_file_test, properly_initializes_state_for_0_byte_file) {
|
||||
TEST(open_file, properly_initializes_state_for_0_byte_file) {
|
||||
const auto source_path =
|
||||
test::generate_test_file_name("file_manager_open_file_test");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.directory = false;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.size = 0U;
|
||||
fsi.size = 0u;
|
||||
fsi.source_path = source_path;
|
||||
|
||||
EXPECT_CALL(upload_mgr, remove_resume)
|
||||
.WillOnce(
|
||||
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
||||
EXPECT_EQ(fsi.api_path, api_path);
|
||||
EXPECT_EQ(fsi.source_path, source_path2);
|
||||
});
|
||||
|
||||
open_file file(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
||||
EXPECT_EQ(std::size_t(0U), file.get_read_state().size());
|
||||
EXPECT_FALSE(file.is_modified());
|
||||
EXPECT_EQ(test_chunk_size, file.get_chunk_size());
|
||||
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||
EXPECT_EQ(std::size_t(0u), o.get_read_state().size());
|
||||
EXPECT_FALSE(o.is_modified());
|
||||
EXPECT_EQ(test_chunk_size, o.get_chunk_size());
|
||||
}
|
||||
|
||||
TEST_F(open_file_test, properly_initializes_state_based_on_chunk_size) {
|
||||
TEST(open_file, properly_initializes_state_based_on_chunk_size) {
|
||||
const auto source_path =
|
||||
test::generate_test_file_name("file_manager_open_file_test");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.directory = false;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.size = 8U;
|
||||
fsi.size = 8u;
|
||||
fsi.source_path = source_path;
|
||||
|
||||
EXPECT_CALL(upload_mgr, remove_resume)
|
||||
EXPECT_CALL(um, remove_resume)
|
||||
.WillOnce(
|
||||
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
||||
EXPECT_EQ(fsi.api_path, api_path);
|
||||
EXPECT_EQ(fsi.source_path, source_path2);
|
||||
});
|
||||
|
||||
open_file file(1U, 0U, fsi, provider, upload_mgr);
|
||||
EXPECT_EQ(std::size_t(8U), file.get_read_state().size());
|
||||
EXPECT_TRUE(file.get_read_state().none());
|
||||
open_file o(1u, 0U, fsi, mp, um);
|
||||
EXPECT_EQ(std::size_t(8u), o.get_read_state().size());
|
||||
EXPECT_TRUE(o.get_read_state().none());
|
||||
|
||||
EXPECT_FALSE(file.is_modified());
|
||||
EXPECT_FALSE(o.is_modified());
|
||||
|
||||
EXPECT_CALL(provider, set_item_meta(fsi.api_path, META_SOURCE, _))
|
||||
EXPECT_CALL(mp, set_item_meta(fsi.api_path, META_SOURCE, _))
|
||||
.WillOnce(Return(api_error::success));
|
||||
EXPECT_EQ(std::size_t(1U), file.get_chunk_size());
|
||||
EXPECT_EQ(std::size_t(1u), o.get_chunk_size());
|
||||
}
|
||||
|
||||
TEST_F(open_file_test, will_not_change_source_path_for_0_byte_file) {
|
||||
TEST(open_file, will_not_change_source_path_for_0_byte_file) {
|
||||
const auto source_path =
|
||||
test::generate_test_file_name("file_manager_open_file_test");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.directory = false;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.size = 0U;
|
||||
fsi.size = 0u;
|
||||
fsi.source_path = source_path;
|
||||
|
||||
EXPECT_CALL(upload_mgr, remove_resume)
|
||||
.WillOnce(
|
||||
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
||||
EXPECT_EQ(fsi.api_path, api_path);
|
||||
EXPECT_EQ(fsi.source_path, source_path2);
|
||||
});
|
||||
open_file o(0u, 0U, fsi, mp, um);
|
||||
test_closeable_open_file(o, false, api_error::success, 0u, source_path);
|
||||
|
||||
open_file file(0U, 0U, fsi, provider, upload_mgr);
|
||||
test_closeable_open_file(file, false, api_error::success, 0U, source_path);
|
||||
|
||||
file.close();
|
||||
EXPECT_EQ(api_error::success, file.get_api_error());
|
||||
EXPECT_STREQ(source_path.c_str(), file.get_source_path().c_str());
|
||||
o.close();
|
||||
EXPECT_EQ(api_error::success, o.get_api_error());
|
||||
EXPECT_STREQ(source_path.c_str(), o.get_source_path().c_str());
|
||||
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
|
||||
}
|
||||
|
||||
TEST_F(open_file_test, will_change_source_path_if_file_size_is_greater_than_0) {
|
||||
TEST(open_file, will_change_source_path_if_file_size_is_greater_than_0) {
|
||||
const auto source_path =
|
||||
test::generate_test_file_name("file_manager_open_file_test");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.size = test_chunk_size;
|
||||
fsi.source_path = source_path;
|
||||
|
||||
EXPECT_CALL(upload_mgr, remove_resume)
|
||||
EXPECT_CALL(um, remove_resume)
|
||||
.WillOnce(
|
||||
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
||||
EXPECT_EQ(fsi.api_path, api_path);
|
||||
EXPECT_EQ(fsi.source_path, source_path2);
|
||||
});
|
||||
|
||||
EXPECT_CALL(provider, set_item_meta(fsi.api_path, META_SOURCE, _))
|
||||
EXPECT_CALL(mp, set_item_meta(fsi.api_path, META_SOURCE, _))
|
||||
.WillOnce([&fsi](const std::string &, const std::string &,
|
||||
const std::string &source_path2) -> api_error {
|
||||
EXPECT_STRNE(fsi.source_path.c_str(), source_path2.c_str());
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
open_file file(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
||||
test_closeable_open_file(file, false, api_error::success, test_chunk_size,
|
||||
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||
test_closeable_open_file(o, false, api_error::success, test_chunk_size,
|
||||
source_path);
|
||||
|
||||
file.close();
|
||||
EXPECT_EQ(api_error::download_stopped, file.get_api_error());
|
||||
EXPECT_STRNE(source_path.c_str(), file.get_source_path().c_str());
|
||||
o.close();
|
||||
EXPECT_EQ(api_error::download_stopped, o.get_api_error());
|
||||
EXPECT_STRNE(source_path.c_str(), o.get_source_path().c_str());
|
||||
EXPECT_FALSE(utils::file::file(source_path).exists());
|
||||
}
|
||||
|
||||
TEST_F(open_file_test,
|
||||
will_not_change_source_path_if_file_size_matches_existing_source) {
|
||||
TEST(open_file,
|
||||
will_not_change_source_path_if_file_size_matches_existing_source) {
|
||||
auto &rf = test::create_random_file(test_chunk_size);
|
||||
const auto source_path = rf.get_path();
|
||||
rf.close();
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.size = test_chunk_size;
|
||||
fsi.source_path = source_path;
|
||||
|
||||
EXPECT_CALL(upload_mgr, remove_resume)
|
||||
.WillOnce(
|
||||
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
||||
EXPECT_EQ(fsi.api_path, api_path);
|
||||
EXPECT_EQ(fsi.source_path, source_path2);
|
||||
});
|
||||
|
||||
open_file file(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
||||
test_closeable_open_file(file, false, api_error::success, test_chunk_size,
|
||||
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||
test_closeable_open_file(o, false, api_error::success, test_chunk_size,
|
||||
source_path);
|
||||
|
||||
file.close();
|
||||
EXPECT_EQ(api_error::success, file.get_api_error());
|
||||
EXPECT_STREQ(source_path.c_str(), file.get_source_path().c_str());
|
||||
o.close();
|
||||
EXPECT_EQ(api_error::success, o.get_api_error());
|
||||
EXPECT_STREQ(source_path.c_str(), o.get_source_path().c_str());
|
||||
EXPECT_TRUE(utils::file::file(source_path).exists());
|
||||
}
|
||||
|
||||
TEST_F(open_file_test, write_with_incomplete_download) {
|
||||
TEST(open_file, write_with_incomplete_download) {
|
||||
const auto source_path = test::generate_test_file_name("test");
|
||||
auto &nf = test::create_random_file(test_chunk_size * 2u);
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.size = test_chunk_size * 2u;
|
||||
fsi.source_path = source_path;
|
||||
|
||||
open_file file(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
||||
test_closeable_open_file(file, false, api_error::success,
|
||||
test_chunk_size * 2u, source_path);
|
||||
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||
test_closeable_open_file(o, false, api_error::success, test_chunk_size * 2u,
|
||||
source_path);
|
||||
|
||||
EXPECT_CALL(provider, set_item_meta(fsi.api_path, _))
|
||||
EXPECT_CALL(mp, set_item_meta(fsi.api_path, _))
|
||||
.WillOnce([](const std::string &, const api_meta_map &meta) -> api_error {
|
||||
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_CHANGED).empty()));
|
||||
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_MODIFIED).empty()));
|
||||
@ -253,7 +220,7 @@ TEST_F(open_file_test, write_with_incomplete_download) {
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
EXPECT_CALL(provider, read_file_bytes)
|
||||
EXPECT_CALL(mp, read_file_bytes)
|
||||
.WillRepeatedly([&nf](const std::string & /* api_path */,
|
||||
std::size_t size, std::uint64_t offset,
|
||||
data_buffer &data,
|
||||
@ -262,7 +229,7 @@ TEST_F(open_file_test, write_with_incomplete_download) {
|
||||
return api_error::download_stopped;
|
||||
}
|
||||
|
||||
if (offset == 0U) {
|
||||
if (offset == 0u) {
|
||||
std::size_t bytes_read{};
|
||||
data.resize(size);
|
||||
auto ret = nf.read(data, offset, &bytes_read) ? api_error::success
|
||||
@ -277,12 +244,11 @@ TEST_F(open_file_test, write_with_incomplete_download) {
|
||||
return api_error::download_stopped;
|
||||
});
|
||||
|
||||
EXPECT_CALL(upload_mgr, remove_upload)
|
||||
.WillOnce([&fsi](const std::string &api_path) {
|
||||
EXPECT_EQ(fsi.api_path, api_path);
|
||||
});
|
||||
EXPECT_CALL(um, remove_upload).WillOnce([&fsi](const std::string &api_path) {
|
||||
EXPECT_EQ(fsi.api_path, api_path);
|
||||
});
|
||||
|
||||
EXPECT_CALL(upload_mgr, store_resume)
|
||||
EXPECT_CALL(um, store_resume)
|
||||
.Times(2)
|
||||
.WillRepeatedly([&fsi](const i_open_file &cur_file) {
|
||||
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
||||
@ -291,53 +257,55 @@ TEST_F(open_file_test, write_with_incomplete_download) {
|
||||
|
||||
data_buffer data = {10, 9, 8};
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_EQ(api_error::success, file.write(0U, data, bytes_written));
|
||||
validate_write(file, 0U, data, bytes_written);
|
||||
EXPECT_EQ(api_error::success, o.write(0u, data, bytes_written));
|
||||
validate_write(o, 0u, data, bytes_written);
|
||||
|
||||
const auto test_state = [&]() {
|
||||
EXPECT_STREQ(source_path.c_str(), file.get_source_path().c_str());
|
||||
EXPECT_STREQ(source_path.c_str(), o.get_source_path().c_str());
|
||||
|
||||
EXPECT_FALSE(file.can_close());
|
||||
EXPECT_FALSE(o.can_close());
|
||||
|
||||
EXPECT_TRUE(file.is_modified());
|
||||
EXPECT_TRUE(o.is_modified());
|
||||
|
||||
EXPECT_TRUE(file.get_read_state(0U));
|
||||
EXPECT_FALSE(file.get_read_state(1u));
|
||||
EXPECT_TRUE(o.get_read_state(0u));
|
||||
EXPECT_FALSE(o.get_read_state(1u));
|
||||
};
|
||||
test_state();
|
||||
|
||||
file.close();
|
||||
o.close();
|
||||
nf.close();
|
||||
|
||||
test_state();
|
||||
|
||||
EXPECT_EQ(api_error::download_incomplete, file.get_api_error());
|
||||
EXPECT_EQ(api_error::download_incomplete, o.get_api_error());
|
||||
|
||||
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
|
||||
}
|
||||
|
||||
TEST_F(open_file_test, write_new_file) {
|
||||
TEST(open_file, write_new_file) {
|
||||
const auto source_path =
|
||||
test::generate_test_file_name("file_manager_open_file_test");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.size = 0U;
|
||||
fsi.size = 0u;
|
||||
fsi.source_path = source_path;
|
||||
|
||||
EXPECT_CALL(upload_mgr, store_resume)
|
||||
.WillOnce([&fsi](const i_open_file &file) {
|
||||
EXPECT_EQ(fsi.api_path, file.get_api_path());
|
||||
EXPECT_EQ(fsi.source_path, file.get_source_path());
|
||||
});
|
||||
EXPECT_CALL(um, store_resume).WillOnce([&fsi](const i_open_file &o) {
|
||||
EXPECT_EQ(fsi.api_path, o.get_api_path());
|
||||
EXPECT_EQ(fsi.source_path, o.get_source_path());
|
||||
});
|
||||
|
||||
open_file file(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
||||
test_closeable_open_file(file, false, api_error::success, 0U, source_path);
|
||||
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||
test_closeable_open_file(o, false, api_error::success, 0u, source_path);
|
||||
data_buffer data = {10, 9, 8};
|
||||
|
||||
EXPECT_CALL(provider, set_item_meta(fsi.api_path, _))
|
||||
EXPECT_CALL(mp, set_item_meta(fsi.api_path, _))
|
||||
.WillOnce([&data](const std::string &,
|
||||
const api_meta_map &meta) -> api_error {
|
||||
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_CHANGED).empty()));
|
||||
@ -354,62 +322,62 @@ TEST_F(open_file_test, write_new_file) {
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
EXPECT_CALL(upload_mgr, remove_upload)
|
||||
.WillOnce([&fsi](const std::string &api_path) {
|
||||
EXPECT_EQ(fsi.api_path, api_path);
|
||||
});
|
||||
EXPECT_CALL(um, remove_upload).WillOnce([&fsi](const std::string &api_path) {
|
||||
EXPECT_EQ(fsi.api_path, api_path);
|
||||
});
|
||||
|
||||
EXPECT_CALL(upload_mgr, queue_upload)
|
||||
.WillOnce([&fsi](const i_open_file &cur_file) {
|
||||
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
||||
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
||||
});
|
||||
EXPECT_CALL(um, queue_upload).WillOnce([&fsi](const i_open_file &cur_file) {
|
||||
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
||||
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
||||
});
|
||||
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_EQ(api_error::success, file.write(0U, data, bytes_written));
|
||||
EXPECT_EQ(api_error::success, o.write(0u, data, bytes_written));
|
||||
|
||||
const auto test_state = [&]() {
|
||||
EXPECT_STREQ(source_path.c_str(), file.get_source_path().c_str());
|
||||
EXPECT_STREQ(source_path.c_str(), o.get_source_path().c_str());
|
||||
|
||||
EXPECT_FALSE(file.can_close());
|
||||
EXPECT_TRUE(file.is_modified());
|
||||
EXPECT_FALSE(o.can_close());
|
||||
EXPECT_TRUE(o.is_modified());
|
||||
|
||||
EXPECT_TRUE(file.get_read_state(0U));
|
||||
EXPECT_EQ(std::size_t(1u), file.get_read_state().size());
|
||||
EXPECT_EQ(data.size(), file.get_file_size());
|
||||
EXPECT_TRUE(o.get_read_state(0u));
|
||||
EXPECT_EQ(std::size_t(1u), o.get_read_state().size());
|
||||
EXPECT_EQ(data.size(), o.get_file_size());
|
||||
};
|
||||
test_state();
|
||||
|
||||
file.close();
|
||||
o.close();
|
||||
|
||||
test_state();
|
||||
|
||||
EXPECT_EQ(api_error::success, file.get_api_error());
|
||||
EXPECT_EQ(api_error::success, o.get_api_error());
|
||||
|
||||
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
|
||||
}
|
||||
|
||||
TEST_F(open_file_test, write_new_file_multiple_chunks) {
|
||||
TEST(open_file, write_new_file_multiple_chunks) {
|
||||
const auto source_path =
|
||||
test::generate_test_file_name("file_manager_open_file_test");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.size = 0U;
|
||||
fsi.size = 0u;
|
||||
fsi.source_path = source_path;
|
||||
|
||||
EXPECT_CALL(upload_mgr, store_resume)
|
||||
.WillOnce([&fsi](const i_open_file &file) {
|
||||
EXPECT_EQ(fsi.api_path, file.get_api_path());
|
||||
EXPECT_EQ(fsi.source_path, file.get_source_path());
|
||||
});
|
||||
open_file file(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
||||
test_closeable_open_file(file, false, api_error::success, 0U, source_path);
|
||||
EXPECT_CALL(um, store_resume).WillOnce([&fsi](const i_open_file &o) {
|
||||
EXPECT_EQ(fsi.api_path, o.get_api_path());
|
||||
EXPECT_EQ(fsi.source_path, o.get_source_path());
|
||||
});
|
||||
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||
test_closeable_open_file(o, false, api_error::success, 0u, source_path);
|
||||
data_buffer data = {10, 9, 8};
|
||||
|
||||
EXPECT_CALL(provider, set_item_meta(fsi.api_path, _))
|
||||
EXPECT_CALL(mp, set_item_meta(fsi.api_path, _))
|
||||
.WillOnce([&data](const std::string &,
|
||||
const api_meta_map &meta) -> api_error {
|
||||
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_CHANGED).empty()));
|
||||
@ -442,159 +410,153 @@ TEST_F(open_file_test, write_new_file_multiple_chunks) {
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
EXPECT_CALL(upload_mgr, remove_upload)
|
||||
.WillOnce([&fsi](const std::string &api_path) {
|
||||
EXPECT_EQ(fsi.api_path, api_path);
|
||||
});
|
||||
EXPECT_CALL(um, remove_upload).WillOnce([&fsi](const std::string &api_path) {
|
||||
EXPECT_EQ(fsi.api_path, api_path);
|
||||
});
|
||||
|
||||
EXPECT_CALL(upload_mgr, queue_upload)
|
||||
.WillOnce([&fsi](const i_open_file &cur_file) {
|
||||
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
||||
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
||||
});
|
||||
EXPECT_CALL(um, queue_upload).WillOnce([&fsi](const i_open_file &cur_file) {
|
||||
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
||||
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
||||
});
|
||||
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_EQ(api_error::success, file.write(0U, data, bytes_written));
|
||||
EXPECT_EQ(api_error::success,
|
||||
file.write(test_chunk_size, data, bytes_written));
|
||||
EXPECT_EQ(api_error::success, o.write(0u, data, bytes_written));
|
||||
EXPECT_EQ(api_error::success, o.write(test_chunk_size, data, bytes_written));
|
||||
|
||||
const auto test_state = [&]() {
|
||||
EXPECT_STREQ(source_path.c_str(), file.get_source_path().c_str());
|
||||
EXPECT_STREQ(source_path.c_str(), o.get_source_path().c_str());
|
||||
|
||||
EXPECT_FALSE(file.can_close());
|
||||
EXPECT_TRUE(file.is_modified());
|
||||
EXPECT_FALSE(o.can_close());
|
||||
EXPECT_TRUE(o.is_modified());
|
||||
|
||||
EXPECT_EQ(std::size_t(2u), file.get_read_state().size());
|
||||
for (std::size_t i = 0U; i < 2u; i++) {
|
||||
EXPECT_TRUE(file.get_read_state(i));
|
||||
EXPECT_EQ(std::size_t(2u), o.get_read_state().size());
|
||||
for (std::size_t i = 0u; i < 2u; i++) {
|
||||
EXPECT_TRUE(o.get_read_state(i));
|
||||
}
|
||||
|
||||
EXPECT_EQ(data.size() + test_chunk_size, file.get_file_size());
|
||||
EXPECT_EQ(data.size() + test_chunk_size, o.get_file_size());
|
||||
};
|
||||
test_state();
|
||||
|
||||
file.close();
|
||||
o.close();
|
||||
|
||||
test_state();
|
||||
|
||||
EXPECT_EQ(api_error::success, file.get_api_error());
|
||||
EXPECT_EQ(api_error::success, o.get_api_error());
|
||||
|
||||
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
|
||||
}
|
||||
|
||||
TEST_F(open_file_test, resize_file_to_0_bytes) {
|
||||
auto &r_file = test::create_random_file(test_chunk_size * 4U);
|
||||
const auto source_path = r_file.get_path();
|
||||
r_file.close();
|
||||
TEST(open_file, resize_file_to_0_bytes) {
|
||||
auto &rf = test::create_random_file(test_chunk_size * 4u);
|
||||
const auto source_path = rf.get_path();
|
||||
rf.close();
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.size = test_chunk_size * 4U;
|
||||
fsi.size = test_chunk_size * 4u;
|
||||
fsi.source_path = source_path;
|
||||
|
||||
EXPECT_EQ(api_error::success, cache_size_mgr::instance().expand(fsi.size));
|
||||
|
||||
open_file file(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
||||
test_closeable_open_file(file, false, api_error::success, fsi.size,
|
||||
source_path);
|
||||
EXPECT_CALL(provider, set_item_meta(fsi.api_path, _))
|
||||
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||
test_closeable_open_file(o, false, api_error::success, fsi.size, source_path);
|
||||
EXPECT_CALL(mp, set_item_meta(fsi.api_path, _))
|
||||
.WillOnce([](const std::string &, const api_meta_map &meta) -> api_error {
|
||||
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_CHANGED).empty()));
|
||||
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_MODIFIED).empty()));
|
||||
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_SIZE).empty()));
|
||||
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_WRITTEN).empty()));
|
||||
EXPECT_EQ(std::size_t(0U),
|
||||
EXPECT_EQ(std::size_t(0u),
|
||||
utils::string::to_size_t(meta.at(META_SIZE)));
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
EXPECT_CALL(upload_mgr, remove_upload)
|
||||
.WillOnce([&fsi](const std ::string &api_path) {
|
||||
EXPECT_EQ(fsi.api_path, api_path);
|
||||
});
|
||||
EXPECT_CALL(um, remove_upload).WillOnce([&fsi](const std ::string &api_path) {
|
||||
EXPECT_EQ(fsi.api_path, api_path);
|
||||
});
|
||||
|
||||
EXPECT_CALL(upload_mgr, queue_upload)
|
||||
.WillOnce([&fsi](const i_open_file &cur_file) {
|
||||
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
||||
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
||||
});
|
||||
EXPECT_CALL(upload_mgr, store_resume)
|
||||
.WillOnce([&fsi](const i_open_file &cur_file) {
|
||||
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
||||
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
||||
});
|
||||
EXPECT_CALL(um, queue_upload).WillOnce([&fsi](const i_open_file &cur_file) {
|
||||
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
||||
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
||||
});
|
||||
EXPECT_CALL(um, store_resume).WillOnce([&fsi](const i_open_file &cur_file) {
|
||||
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
||||
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
||||
});
|
||||
|
||||
EXPECT_EQ(api_error::success, file.resize(0U));
|
||||
EXPECT_EQ(api_error::success, o.resize(0u));
|
||||
|
||||
EXPECT_EQ(std::size_t(0U), file.get_file_size());
|
||||
EXPECT_FALSE(file.can_close());
|
||||
EXPECT_TRUE(file.is_modified());
|
||||
EXPECT_EQ(std::size_t(0u), o.get_file_size());
|
||||
EXPECT_FALSE(o.can_close());
|
||||
EXPECT_TRUE(o.is_modified());
|
||||
|
||||
EXPECT_EQ(std::size_t(0U), file.get_read_state().size());
|
||||
EXPECT_EQ(std::size_t(0u), o.get_read_state().size());
|
||||
}
|
||||
|
||||
TEST_F(open_file_test, resize_file_by_full_chunk) {
|
||||
auto &r_file = test::create_random_file(test_chunk_size * 4U);
|
||||
const auto source_path = r_file.get_path();
|
||||
r_file.close();
|
||||
TEST(open_file, resize_file_by_full_chunk) {
|
||||
auto &rf = test::create_random_file(test_chunk_size * 4u);
|
||||
const auto source_path = rf.get_path();
|
||||
rf.close();
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.size = test_chunk_size * 4U;
|
||||
fsi.size = test_chunk_size * 4u;
|
||||
fsi.source_path = source_path;
|
||||
|
||||
EXPECT_EQ(api_error::success, cache_size_mgr::instance().expand(fsi.size));
|
||||
EXPECT_CALL(um, store_resume).WillOnce([&fsi](const i_open_file &o) {
|
||||
EXPECT_EQ(fsi.api_path, o.get_api_path());
|
||||
EXPECT_EQ(fsi.source_path, o.get_source_path());
|
||||
});
|
||||
|
||||
EXPECT_CALL(upload_mgr, store_resume)
|
||||
.WillOnce([&fsi](const i_open_file &file) {
|
||||
EXPECT_EQ(fsi.api_path, file.get_api_path());
|
||||
EXPECT_EQ(fsi.source_path, file.get_source_path());
|
||||
});
|
||||
|
||||
open_file file(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
||||
test_closeable_open_file(file, false, api_error::success, fsi.size,
|
||||
source_path);
|
||||
EXPECT_CALL(provider, set_item_meta(fsi.api_path, _))
|
||||
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||
test_closeable_open_file(o, false, api_error::success, fsi.size, source_path);
|
||||
EXPECT_CALL(mp, set_item_meta(fsi.api_path, _))
|
||||
.WillOnce([](const std::string &, const api_meta_map &meta) -> api_error {
|
||||
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_CHANGED).empty()));
|
||||
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_MODIFIED).empty()));
|
||||
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_SIZE).empty()));
|
||||
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_WRITTEN).empty()));
|
||||
EXPECT_EQ(std::size_t(test_chunk_size * 3U),
|
||||
EXPECT_EQ(std::size_t(test_chunk_size * 3u),
|
||||
utils::string::to_size_t(meta.at(META_SIZE)));
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
EXPECT_CALL(upload_mgr, remove_upload)
|
||||
.WillOnce([&fsi](const std::string &api_path) {
|
||||
EXPECT_EQ(fsi.api_path, api_path);
|
||||
});
|
||||
EXPECT_CALL(um, remove_upload).WillOnce([&fsi](const std::string &api_path) {
|
||||
EXPECT_EQ(fsi.api_path, api_path);
|
||||
});
|
||||
|
||||
EXPECT_CALL(upload_mgr, queue_upload)
|
||||
.WillOnce([&fsi](const i_open_file &cur_file) {
|
||||
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
||||
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
||||
});
|
||||
EXPECT_CALL(um, queue_upload).WillOnce([&fsi](const i_open_file &cur_file) {
|
||||
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
||||
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
||||
});
|
||||
|
||||
EXPECT_EQ(api_error::success, file.resize(test_chunk_size * 3U));
|
||||
EXPECT_EQ(api_error::success, o.resize(test_chunk_size * 3u));
|
||||
|
||||
EXPECT_EQ(std::size_t(test_chunk_size * 3U), file.get_file_size());
|
||||
EXPECT_FALSE(file.can_close());
|
||||
EXPECT_TRUE(file.is_modified());
|
||||
EXPECT_EQ(std::size_t(3U), file.get_read_state().size());
|
||||
EXPECT_EQ(std::size_t(test_chunk_size * 3u), o.get_file_size());
|
||||
EXPECT_FALSE(o.can_close());
|
||||
EXPECT_TRUE(o.is_modified());
|
||||
EXPECT_EQ(std::size_t(3u), o.get_read_state().size());
|
||||
}
|
||||
|
||||
TEST_F(open_file_test, can_add_handle) {
|
||||
TEST(open_file, can_add_handle) {
|
||||
event_system::instance().start();
|
||||
console_consumer c;
|
||||
const auto source_path =
|
||||
test::generate_test_file_name("file_manager_open_file_test");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.api_path = "/test.txt";
|
||||
@ -620,9 +582,9 @@ TEST_F(open_file_test, can_add_handle) {
|
||||
EXPECT_STREQ("1", ee.get_handle().get<std::string>().c_str());
|
||||
});
|
||||
|
||||
EXPECT_CALL(provider, set_item_meta(fsi.api_path, META_SOURCE, _))
|
||||
EXPECT_CALL(mp, set_item_meta(fsi.api_path, META_SOURCE, _))
|
||||
.WillOnce(Return(api_error::success));
|
||||
EXPECT_CALL(upload_mgr, remove_resume)
|
||||
EXPECT_CALL(um, remove_resume)
|
||||
.WillOnce(
|
||||
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
||||
EXPECT_EQ(fsi.api_path, api_path);
|
||||
@ -632,7 +594,7 @@ TEST_F(open_file_test, can_add_handle) {
|
||||
event_capture capture(
|
||||
{"filesystem_item_opened", "filesystem_item_handle_opened"});
|
||||
|
||||
open_file o(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
||||
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||
#if defined(_WIN32)
|
||||
o.add(1u, {});
|
||||
EXPECT_EQ(nullptr, o.get_open_data(1u).directory_buffer);
|
||||
@ -646,14 +608,17 @@ TEST_F(open_file_test, can_add_handle) {
|
||||
event_system::instance().stop();
|
||||
}
|
||||
|
||||
TEST_F(open_file_test, can_remove_handle) {
|
||||
TEST(open_file, can_remove_handle) {
|
||||
event_system::instance().start();
|
||||
console_consumer c;
|
||||
|
||||
const auto source_path =
|
||||
test::generate_test_file_name("file_manager_open_file_test");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.api_path = "/test.txt";
|
||||
@ -679,13 +644,13 @@ TEST_F(open_file_test, can_remove_handle) {
|
||||
EXPECT_STREQ("1", ee.get_handle().get<std::string>().c_str());
|
||||
});
|
||||
|
||||
EXPECT_CALL(upload_mgr, remove_resume)
|
||||
EXPECT_CALL(um, remove_resume)
|
||||
.WillOnce(
|
||||
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
||||
EXPECT_EQ(fsi.api_path, api_path);
|
||||
EXPECT_EQ(fsi.source_path, source_path2);
|
||||
});
|
||||
EXPECT_CALL(provider, set_item_meta(fsi.api_path, META_SOURCE, _))
|
||||
EXPECT_CALL(mp, set_item_meta(fsi.api_path, META_SOURCE, _))
|
||||
.WillOnce(Return(api_error::success));
|
||||
|
||||
event_capture capture({
|
||||
@ -695,7 +660,7 @@ TEST_F(open_file_test, can_remove_handle) {
|
||||
"filesystem_item_closed",
|
||||
});
|
||||
|
||||
open_file o(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
||||
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||
#if defined(_WIN32)
|
||||
o.add(1u, {});
|
||||
#else
|
||||
@ -708,13 +673,12 @@ TEST_F(open_file_test, can_remove_handle) {
|
||||
event_system::instance().stop();
|
||||
}
|
||||
|
||||
TEST_F(open_file_test,
|
||||
can_read_locally_after_write_with_file_size_greater_than_existing_size) {
|
||||
}
|
||||
TEST(open_file,
|
||||
can_read_locally_after_write_with_file_size_greater_than_existing_size) {}
|
||||
|
||||
TEST_F(open_file_test, test_valid_download_chunks) {}
|
||||
TEST(open_file, test_valid_download_chunks) {}
|
||||
|
||||
TEST_F(open_file_test, test_full_download_with_partial_chunk) {}
|
||||
TEST(open_file, test_full_download_with_partial_chunk) {}
|
||||
|
||||
TEST_F(open_file_test, source_is_read_after_full_download) {}
|
||||
TEST(open_file, source_is_read_after_full_download) {}
|
||||
} // namespace repertory
|
||||
|
@ -31,29 +31,18 @@
|
||||
namespace {
|
||||
constexpr const std::size_t test_chunk_size{1024U};
|
||||
|
||||
const auto ring_buffer_dir{
|
||||
repertory::utils::path::combine(
|
||||
repertory::test::get_test_output_dir(),
|
||||
{"file_manager_ring_buffer_open_file_test"}),
|
||||
};
|
||||
std::string ring_buffer_dir = repertory::utils::path::combine(
|
||||
repertory::test::get_test_output_dir(),
|
||||
{"file_manager_ring_buffer_open_file_test"});
|
||||
} // namespace
|
||||
|
||||
namespace repertory {
|
||||
class ring_buffer_open_file_test : public ::testing::Test {
|
||||
public:
|
||||
console_consumer con_consumer;
|
||||
mock_provider provider;
|
||||
|
||||
protected:
|
||||
void SetUp() override { event_system::instance().start(); }
|
||||
|
||||
void TearDown() override { event_system::instance().stop(); }
|
||||
};
|
||||
|
||||
TEST_F(ring_buffer_open_file_test, can_forward_to_last_chunk) {
|
||||
TEST(ring_buffer_open_file, can_forward_to_last_chunk) {
|
||||
auto source_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider prov;
|
||||
|
||||
EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.directory = false;
|
||||
@ -62,8 +51,8 @@ TEST_F(ring_buffer_open_file_test, can_forward_to_last_chunk) {
|
||||
fsi.source_path = source_path;
|
||||
|
||||
{
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi,
|
||||
provider, 8U);
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi, prov,
|
||||
8U);
|
||||
file.set(0U, 3U);
|
||||
file.forward(4U);
|
||||
|
||||
@ -74,13 +63,17 @@ TEST_F(ring_buffer_open_file_test, can_forward_to_last_chunk) {
|
||||
EXPECT_TRUE(file.get_read_state(chunk));
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST_F(ring_buffer_open_file_test,
|
||||
can_forward_to_last_chunk_if_count_is_greater_than_remaining) {
|
||||
TEST(ring_buffer_open_file,
|
||||
can_forward_to_last_chunk_if_count_is_greater_than_remaining) {
|
||||
auto source_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider prov;
|
||||
|
||||
EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.directory = false;
|
||||
@ -89,8 +82,8 @@ TEST_F(ring_buffer_open_file_test,
|
||||
fsi.source_path = source_path;
|
||||
|
||||
{
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi,
|
||||
provider, 8U);
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi, prov,
|
||||
8U);
|
||||
file.set(0U, 3U);
|
||||
file.forward(100U);
|
||||
|
||||
@ -101,12 +94,16 @@ TEST_F(ring_buffer_open_file_test,
|
||||
EXPECT_FALSE(file.get_read_state(chunk));
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST_F(ring_buffer_open_file_test, can_forward_after_last_chunk) {
|
||||
TEST(ring_buffer_open_file, can_forward_after_last_chunk) {
|
||||
auto source_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider prov;
|
||||
|
||||
EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.directory = false;
|
||||
@ -115,8 +112,8 @@ TEST_F(ring_buffer_open_file_test, can_forward_after_last_chunk) {
|
||||
fsi.source_path = source_path;
|
||||
|
||||
{
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi,
|
||||
provider, 8U);
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi, prov,
|
||||
8U);
|
||||
file.set(0U, 3U);
|
||||
file.forward(5U);
|
||||
|
||||
@ -128,12 +125,16 @@ TEST_F(ring_buffer_open_file_test, can_forward_after_last_chunk) {
|
||||
EXPECT_TRUE(file.get_read_state(chunk));
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST_F(ring_buffer_open_file_test, can_forward_and_rollover_after_last_chunk) {
|
||||
TEST(ring_buffer_open_file, can_forward_and_rollover_after_last_chunk) {
|
||||
auto source_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider prov;
|
||||
|
||||
EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.directory = false;
|
||||
@ -142,8 +143,8 @@ TEST_F(ring_buffer_open_file_test, can_forward_and_rollover_after_last_chunk) {
|
||||
fsi.source_path = source_path;
|
||||
|
||||
{
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi,
|
||||
provider, 8U);
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi, prov,
|
||||
8U);
|
||||
file.set(16U, 20U);
|
||||
file.forward(8U);
|
||||
|
||||
@ -151,12 +152,16 @@ TEST_F(ring_buffer_open_file_test, can_forward_and_rollover_after_last_chunk) {
|
||||
EXPECT_EQ(std::size_t(21U), file.get_first_chunk());
|
||||
EXPECT_EQ(std::size_t(28U), file.get_last_chunk());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST_F(ring_buffer_open_file_test, can_reverse_to_first_chunk) {
|
||||
TEST(ring_buffer_open_file, can_reverse_to_first_chunk) {
|
||||
auto source_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider prov;
|
||||
|
||||
EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.directory = false;
|
||||
@ -165,8 +170,8 @@ TEST_F(ring_buffer_open_file_test, can_reverse_to_first_chunk) {
|
||||
fsi.source_path = source_path;
|
||||
|
||||
{
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi,
|
||||
provider, 8U);
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi, prov,
|
||||
8U);
|
||||
file.set(0U, 3U);
|
||||
file.reverse(3U);
|
||||
|
||||
@ -177,13 +182,17 @@ TEST_F(ring_buffer_open_file_test, can_reverse_to_first_chunk) {
|
||||
EXPECT_TRUE(file.get_read_state(chunk));
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST_F(ring_buffer_open_file_test,
|
||||
can_reverse_to_first_chunk_if_count_is_greater_than_remaining) {
|
||||
TEST(ring_buffer_open_file,
|
||||
can_reverse_to_first_chunk_if_count_is_greater_than_remaining) {
|
||||
auto source_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider prov;
|
||||
|
||||
EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.directory = false;
|
||||
@ -192,8 +201,8 @@ TEST_F(ring_buffer_open_file_test,
|
||||
fsi.source_path = source_path;
|
||||
|
||||
{
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi,
|
||||
provider, 8U);
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi, prov,
|
||||
8U);
|
||||
file.set(0U, 3U);
|
||||
file.reverse(13U);
|
||||
|
||||
@ -204,12 +213,16 @@ TEST_F(ring_buffer_open_file_test,
|
||||
EXPECT_TRUE(file.get_read_state(chunk));
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST_F(ring_buffer_open_file_test, can_reverse_before_first_chunk) {
|
||||
TEST(ring_buffer_open_file, can_reverse_before_first_chunk) {
|
||||
auto source_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider prov;
|
||||
|
||||
EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.directory = false;
|
||||
@ -218,8 +231,8 @@ TEST_F(ring_buffer_open_file_test, can_reverse_before_first_chunk) {
|
||||
fsi.source_path = source_path;
|
||||
|
||||
{
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi,
|
||||
provider, 8U);
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi, prov,
|
||||
8U);
|
||||
file.set(1U, 3U);
|
||||
file.reverse(3U);
|
||||
|
||||
@ -231,13 +244,16 @@ TEST_F(ring_buffer_open_file_test, can_reverse_before_first_chunk) {
|
||||
EXPECT_TRUE(file.get_read_state(chunk));
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST_F(ring_buffer_open_file_test,
|
||||
can_reverse_and_rollover_before_first_chunk) {
|
||||
TEST(ring_buffer_open_file, can_reverse_and_rollover_before_first_chunk) {
|
||||
auto source_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider prov;
|
||||
|
||||
EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.directory = false;
|
||||
@ -246,8 +262,8 @@ TEST_F(ring_buffer_open_file_test,
|
||||
fsi.source_path = source_path;
|
||||
|
||||
{
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi,
|
||||
provider, 8U);
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi, prov,
|
||||
8U);
|
||||
file.set(16U, 20U);
|
||||
file.reverse(8U);
|
||||
|
||||
@ -263,12 +279,16 @@ TEST_F(ring_buffer_open_file_test,
|
||||
EXPECT_TRUE(file.get_read_state(chunk));
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST_F(ring_buffer_open_file_test, can_reverse_full_ring) {
|
||||
TEST(ring_buffer_open_file, can_reverse_full_ring) {
|
||||
auto source_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
||||
mock_provider prov;
|
||||
|
||||
EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
filesystem_item fsi;
|
||||
fsi.directory = false;
|
||||
@ -277,8 +297,8 @@ TEST_F(ring_buffer_open_file_test, can_reverse_full_ring) {
|
||||
fsi.source_path = source_path;
|
||||
|
||||
{
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi,
|
||||
provider, 8U);
|
||||
ring_buffer_open_file file(ring_buffer_dir, test_chunk_size, 30U, fsi, prov,
|
||||
8U);
|
||||
file.set(8U, 15U);
|
||||
file.reverse(16U);
|
||||
|
||||
@ -290,10 +310,12 @@ TEST_F(ring_buffer_open_file_test, can_reverse_full_ring) {
|
||||
EXPECT_FALSE(file.get_read_state(chunk));
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST_F(ring_buffer_open_file_test, read_full_file) {
|
||||
auto &nf = test::create_random_file(test_chunk_size * 33u + 11u);
|
||||
TEST(ring_buffer_open_file, read_full_file) {
|
||||
auto &nf = test::create_random_file(test_chunk_size * 32u);
|
||||
auto download_source_path = nf.get_path();
|
||||
|
||||
auto dest_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
@ -305,17 +327,14 @@ TEST_F(ring_buffer_open_file_test, read_full_file) {
|
||||
filesystem_item fsi;
|
||||
fsi.directory = false;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.size = test_chunk_size * 33u + 11u;
|
||||
fsi.size = test_chunk_size * 32u;
|
||||
fsi.source_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
std::mutex read_mtx;
|
||||
EXPECT_CALL(mp, read_file_bytes)
|
||||
.WillRepeatedly([&read_mtx, &nf](const std::string & /* api_path */,
|
||||
std::size_t size, std::uint64_t offset,
|
||||
data_buffer &data,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
mutex_lock lock(read_mtx);
|
||||
|
||||
.WillRepeatedly([&nf](const std::string & /* api_path */,
|
||||
std::size_t size, std::uint64_t offset,
|
||||
data_buffer &data,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
EXPECT_FALSE(stop_requested);
|
||||
std::size_t bytes_read{};
|
||||
data.resize(size);
|
||||
@ -356,9 +375,11 @@ TEST_F(ring_buffer_open_file_test, read_full_file) {
|
||||
EXPECT_STREQ(hash1.value().c_str(), hash2.value().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST_F(ring_buffer_open_file_test, read_full_file_in_reverse) {
|
||||
TEST(ring_buffer_open_file, read_full_file_in_reverse) {
|
||||
auto &nf = test::create_random_file(test_chunk_size * 32u);
|
||||
auto download_source_path = nf.get_path();
|
||||
|
||||
@ -374,14 +395,11 @@ TEST_F(ring_buffer_open_file_test, read_full_file_in_reverse) {
|
||||
fsi.size = test_chunk_size * 32u;
|
||||
fsi.source_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
std::mutex read_mtx;
|
||||
EXPECT_CALL(mp, read_file_bytes)
|
||||
.WillRepeatedly([&read_mtx, &nf](const std::string & /* api_path */,
|
||||
std::size_t size, std::uint64_t offset,
|
||||
data_buffer &data,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
mutex_lock lock(read_mtx);
|
||||
|
||||
.WillRepeatedly([&nf](const std::string & /* api_path */,
|
||||
std::size_t size, std::uint64_t offset,
|
||||
data_buffer &data,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
EXPECT_FALSE(stop_requested);
|
||||
std::size_t bytes_read{};
|
||||
data.resize(size);
|
||||
@ -399,15 +417,15 @@ TEST_F(ring_buffer_open_file_test, read_full_file_in_reverse) {
|
||||
EXPECT_TRUE(nf2);
|
||||
|
||||
auto to_read = fsi.size;
|
||||
std::size_t chunk = rb.get_total_chunks() - 1U;
|
||||
while (to_read > 0U) {
|
||||
std::size_t chunk = rb.get_total_chunks() - 1u;
|
||||
while (to_read) {
|
||||
data_buffer data{};
|
||||
EXPECT_EQ(api_error::success,
|
||||
rb.read(test_chunk_size, chunk * test_chunk_size, data));
|
||||
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_TRUE(nf2.write(data, chunk * test_chunk_size, &bytes_written));
|
||||
--chunk;
|
||||
chunk--;
|
||||
to_read -= data.size();
|
||||
}
|
||||
nf2.close();
|
||||
@ -422,9 +440,11 @@ TEST_F(ring_buffer_open_file_test, read_full_file_in_reverse) {
|
||||
EXPECT_STREQ(hash1.value().c_str(), hash2.value().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST_F(ring_buffer_open_file_test, read_full_file_in_partial_chunks) {
|
||||
TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
|
||||
auto &nf = test::create_random_file(test_chunk_size * 32u);
|
||||
auto download_source_path = nf.get_path();
|
||||
|
||||
@ -440,14 +460,11 @@ TEST_F(ring_buffer_open_file_test, read_full_file_in_partial_chunks) {
|
||||
fsi.size = test_chunk_size * 32u;
|
||||
fsi.source_path = test::generate_test_file_name("test");
|
||||
|
||||
std::mutex read_mtx;
|
||||
EXPECT_CALL(mp, read_file_bytes)
|
||||
.WillRepeatedly([&read_mtx, &nf](const std::string & /* api_path */,
|
||||
std::size_t size, std::uint64_t offset,
|
||||
data_buffer &data,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
mutex_lock lock(read_mtx);
|
||||
|
||||
.WillRepeatedly([&nf](const std::string & /* api_path */,
|
||||
std::size_t size, std::uint64_t offset,
|
||||
data_buffer &data,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
EXPECT_FALSE(stop_requested);
|
||||
std::size_t bytes_read{};
|
||||
data.resize(size);
|
||||
@ -489,10 +506,11 @@ TEST_F(ring_buffer_open_file_test, read_full_file_in_partial_chunks) {
|
||||
EXPECT_STREQ(hash1.value().c_str(), hash2.value().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST_F(ring_buffer_open_file_test,
|
||||
read_full_file_in_partial_chunks_in_reverse) {
|
||||
TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
|
||||
auto &nf = test::create_random_file(test_chunk_size * 32u);
|
||||
auto download_source_path = nf.get_path();
|
||||
|
||||
@ -508,14 +526,11 @@ TEST_F(ring_buffer_open_file_test,
|
||||
fsi.size = test_chunk_size * 32u;
|
||||
fsi.source_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
std::mutex read_mtx;
|
||||
EXPECT_CALL(mp, read_file_bytes)
|
||||
.WillRepeatedly([&read_mtx, &nf](const std::string & /* api_path */,
|
||||
std::size_t size, std::uint64_t offset,
|
||||
data_buffer &data,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
mutex_lock lock(read_mtx);
|
||||
|
||||
.WillRepeatedly([&nf](const std::string & /* api_path */,
|
||||
std::size_t size, std::uint64_t offset,
|
||||
data_buffer &data,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
EXPECT_FALSE(stop_requested);
|
||||
std::size_t bytes_read{};
|
||||
data.resize(size);
|
||||
@ -562,5 +577,7 @@ TEST_F(ring_buffer_open_file_test,
|
||||
EXPECT_STREQ(hash1.value().c_str(), hash2.value().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
} // namespace repertory
|
||||
|
Reference in New Issue
Block a user