mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-02 04:50:49 +00:00
Compare commits
891 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c9f5763a70 | |||
| f61514edaf | |||
| 2aca913e92 | |||
| 26254a0ad8 | |||
| 6f130e1583 | |||
| 35ad6cacc8 | |||
| f519ecded7 | |||
| 4b2efeec7a | |||
| a687df2f4f | |||
| 29deae6fe0 | |||
| f9f1c8ee75 | |||
| a0544dc2b5 | |||
| 0a1798869a | |||
| 751fd2f9ba | |||
| 954b222fb6 | |||
| 4c04e77489 | |||
| 152538ccc1 | |||
| d955b06f03 | |||
| db19a56458 | |||
| 6539e1b856 | |||
| 8046fb1eb9 | |||
| 0302e39d57 | |||
| c29ccaadbc | |||
| d2d168f363 | |||
| cf98718a79 | |||
| 47bda055e0 | |||
| c1e577c1ac | |||
| 5b98039291 | |||
| 5a23f71a7f | |||
| c46f12f0d6 | |||
| f89350e6cd | |||
| fd404064c9 | |||
| 21029c326b | |||
| e8ec6385f3 | |||
| 1361bf20dd | |||
| 5d98546e1d | |||
| ff5eb53f48 | |||
| 814d4dbb51 | |||
| 2c68175b5c | |||
| 551a370c13 | |||
| 1afcd68e01 | |||
| cc30ef3ee2 | |||
| 235e35a2f3 | |||
| 4c54f967b7 | |||
| 8925949be3 | |||
| e96372c999 | |||
| e5d9d27069 | |||
| 853c990b6e | |||
| 86c1ffab2a | |||
| 952287a787 | |||
| b5d90b7b13 | |||
| 3e06af8515 | |||
| eff2e56d0d | |||
| eaac04ccf6 | |||
| 894192851e | |||
| f93bc6ef0f | |||
| 035d5314b0 | |||
| a40cfc679c | |||
| bda6eb4200 | |||
| 70f7d7409a | |||
| 48635c8057 | |||
| 122ff609e8 | |||
| 30e94064e5 | |||
| d60e575af5 | |||
| 91c3ed8ec4 | |||
| 0dc49d2a70 | |||
| a83dea705f | |||
| ed7a960e31 | |||
| 9bf1a44f75 | |||
| 8ecd01be1f | |||
| 4933e3caf4 | |||
| 4a9a5bc713 | |||
| 7412b84e04 | |||
| 3775d69a60 | |||
| 4cf57ae84d | |||
| ef2541776b | |||
| 78082bc10f | |||
| 5342e549cd | |||
| e2d1e9a7df | |||
| 9aa9917952 | |||
| c1cdb69f56 | |||
| 5b8c909ac3 | |||
| 20b038bfb7 | |||
| 9f9a1a138b | |||
| 4cb9ac5357 | |||
| cd76e481fd | |||
| 8e309b57b3 | |||
| beb9d43f4d | |||
| b281819cba | |||
| 6826efc723 | |||
| 370e3cdfea | |||
| fb8b05e7fd | |||
| 8c94973cf9 | |||
| 787cc8e3ee | |||
| ff51c46915 | |||
| 0914cd16af | |||
| 9b28d8984f | |||
| bd4c3a246d | |||
| 914ddf4859 | |||
| 2fa3adee1d | |||
| fd83c1a5bf | |||
| de2be9b8ae | |||
| 209b030502 | |||
| 5a65ce6adb | |||
| 79a7cf864e | |||
| 19f7b0fe8d | |||
| 2b7bb24c92 | |||
| faf2d588b1 | |||
| 8e02a03170 | |||
| d13de0464e | |||
| c0528888f4 | |||
| b4efe6a810 | |||
| f09a273ad7 | |||
| 3cd168c44d | |||
| b0ab8f417d | |||
| d7ccf95499 | |||
| 6ab5e60833 | |||
| e63d74dff2 | |||
| 25d7d7c037 | |||
| 1c7c07ace7 | |||
| f7f42a9cd8 | |||
| 1e7731c317 | |||
| 208a2151c1 | |||
| 4a6d53e16d | |||
| a778ff8903 | |||
| bb42a2158d | |||
| ab2f5420c6 | |||
| 174943cd0f | |||
| 0bc66032d2 | |||
| 899ed92ebc | |||
| 129eb8644d | |||
| d582f9bab2 | |||
| 0f1575d5af | |||
| f9c0d99790 | |||
| 1f56fb86e3 | |||
| f9d08e1377 | |||
| cbf0416d7e | |||
| 2422d3ab40 | |||
| 960cf76c42 | |||
| af2564c580 | |||
| b385b1e975 | |||
| ce1d4b852a | |||
| c43d31f693 | |||
| e4259c5045 | |||
| 993dd2ad1c | |||
| 3201244d9b | |||
| f4dc87fa44 | |||
| 24a027194e | |||
| 62c4dc1472 | |||
| b7f74b4e55 | |||
| 2da853dcbe | |||
| 0438a7c76b | |||
| c86c3a803f | |||
| 19db62d74f | |||
| 0146411483 | |||
| b731e17850 | |||
| bb66b2296d | |||
| c75ef8546e | |||
| d80c2b6104 | |||
| ec4bf35647 | |||
| 669d99bebc | |||
| 715af5950f | |||
| 7a5ac3dbc2 | |||
| ae61cbb4c0 | |||
| bde6e6bda4 | |||
| a656241d5e | |||
| 7ae5a12f4a | |||
| 769e984ef4 | |||
| 98e75f6d97 | |||
| 586f879e80 | |||
| e2112670bf | |||
| 060c6669c1 | |||
| aa02c5cbe9 | |||
| 77d7c3871a | |||
| 67e38955ae | |||
| 26098f6c8d | |||
| 021b6f694b | |||
| f0a370db24 | |||
| 2e7f624b34 | |||
| b63c0c7dfc | |||
| 906cbf1e6f | |||
| 5aefc741f2 | |||
| 5c28ea3064 | |||
| 70cd11e30f | |||
| 94a72b23ff | |||
| d08be990ef | |||
| ca5b7758ce | |||
| bb1def2910 | |||
| 673abae1be | |||
| 3b8c067e70 | |||
| 528459eeb2 | |||
| bc1ab4e55c | |||
| 5aefd0b393 | |||
| 7bc53a4253 | |||
| 8b12dccd76 | |||
| 952afb6040 | |||
| 56ca5e9e62 | |||
| a834461752 | |||
| 37166af321 | |||
| 2c91bcdc30 | |||
| e2d6a53de5 | |||
| 89537b1521 | |||
| 152b3cae90 | |||
| f104e53fd4 | |||
| fd99ae0e59 | |||
| 4b6c159e3a | |||
| 50f8cfbc15 | |||
| 22848b010d | |||
| 3b5840e248 | |||
| f955707201 | |||
| 86dc10028f | |||
| a64807efda | |||
| 61e00b5fbd | |||
| 1b2fccb615 | |||
| 702c1ff217 | |||
| d1b2814ec6 | |||
| ec57d1786c | |||
| 9f7c1f90ec | |||
| e23e30eb44 | |||
| 2b4a61b84c | |||
| fbafde6e27 | |||
| 14e5a75d35 | |||
| ea32d8627e | |||
| 814a0498df | |||
| e45f85cc1e | |||
| 1e9c032072 | |||
| c741cca5f2 | |||
| 72ff71f59c | |||
| 699323e2e0 | |||
| fb5985bbbe | |||
| 5a9f4bee12 | |||
| 4717793d8e | |||
| de38011dd2 | |||
| 0f4bbc4752 | |||
| 86a1c41e5d | |||
| 021b8c4cff | |||
| bcacb7b7f0 | |||
| 747b9752ce | |||
| b0be6c8a7a | |||
| 58c7358113 | |||
| b1a2523ef0 | |||
| b7323db31b | |||
| 2e52692ba6 | |||
| 0075ead526 | |||
| 6df4a746f1 | |||
| 074904ee92 | |||
| 108b0ea226 | |||
| 9a704de43b | |||
| 7dfc12d138 | |||
| 9000446663 | |||
| 814ac6c28c | |||
| d1a284298f | |||
| 9509629bcf | |||
| f1882cfe2c | |||
| 90e446ec16 | |||
| 464ed8269b | |||
| 57a51d94ed | |||
| 53c557271d | |||
| b6fe16095b | |||
| 6a1c439325 | |||
| 06b0be7bad | |||
| e5acf22285 | |||
| 5f904a164c | |||
| 9a30a11786 | |||
| d31144b9ae | |||
| c7a3a10846 | |||
| 2be0b7859d | |||
| 65528fc357 | |||
| 5a713534c6 | |||
| f89e322ece | |||
| cd6075ba94 | |||
| 77033df27b | |||
| b8c5303fdb | |||
| eaab66da58 | |||
| 2a8aff9746 | |||
| 797b2dd996 | |||
| e65fff058c | |||
| 548dcdb242 | |||
| 9a65bbe12c | |||
| 72d741a9b7 | |||
| 2f5bf96fc9 | |||
| 4d3b42eb11 | |||
| 5b85522400 | |||
| 5f96abc271 | |||
| 0e6ee35942 | |||
| 14798b2063 | |||
| cef4fefc40 | |||
| 181806a9a2 | |||
| 99a205c716 | |||
| dd78c026c1 | |||
| 20516dbbc2 | |||
| ba80f377a9 | |||
| dc7bbf35eb | |||
| b3b0dbb217 | |||
| d76259496d | |||
| aa3a2ab595 | |||
| 0f1fd1bca6 | |||
| 581876df9a | |||
| d0101be955 | |||
| caa5433787 | |||
| 9125745416 | |||
| b893c0a7ca | |||
| 02ac416561 | |||
| 00bb0ca8f3 | |||
| 2d0baef3b1 | |||
| 3ea803e3bb | |||
| 2fa9d7402f | |||
| 3c04c56639 | |||
| 7cd4b7a908 | |||
| 9242ea4d72 | |||
| 58790dadc6 | |||
| 182fbdef50 | |||
| 4fb57f65fb | |||
| 12e2982362 | |||
| 60fb415150 | |||
| 75c4d6da3b | |||
| 1aa88701fb | |||
| 43ddcd27cb | |||
| 9cb2a302f8 | |||
| d836334767 | |||
| 565fcf4390 | |||
| b7490fe909 | |||
| b2bf4f7884 | |||
| e504fdcd54 | |||
| 3efa1052fa | |||
| 2e488608ca | |||
| 674a0e84be | |||
| f5e1e194b3 | |||
| b4f3573d11 | |||
| 4718625388 | |||
| d6b4b795a5 | |||
| 2bd0b786ea | |||
| 092a7ed8f3 | |||
| 438e206b3d | |||
| 7498fd8fc8 | |||
| e07912770e | |||
| bb2db7e500 | |||
| c94e048198 | |||
| 3b4c06d28d | |||
| 15618c8ea8 | |||
| a037615962 | |||
| 5d301fb1b7 | |||
| 8a4d866810 | |||
| b98abcc049 | |||
| 10e0966edc | |||
| 340d1fdd7c | |||
| 14d4a2706c | |||
| 308ea83cc0 | |||
| 9c018ce636 | |||
| 359cda9d99 | |||
| e682639b20 | |||
| afd2c5fcea | |||
| 5a1d006850 | |||
| 67c26368ee | |||
| 1885cbd6a2 | |||
| 79d68ec3a7 | |||
| f43801cb96 | |||
| 46c2182ade | |||
| 5ef45bddda | |||
| 0d94f29c27 | |||
| 04b7543dea | |||
| 9051f13ce6 | |||
| 1b704db5c0 | |||
| 2d66a4ca0a | |||
| 182c21e38c | |||
| 9a767b7631 | |||
| 3756db2491 | |||
| ff8e4a8659 | |||
| aec6c2f2e2 | |||
| d611d0d829 | |||
| b4deedda01 | |||
| 0f14143141 | |||
| e5198178a5 | |||
| 1c44b4f787 | |||
| 6d2f265980 | |||
| 325d391007 | |||
| 91a3dc9e94 | |||
| 31f4af5722 | |||
| e0aaa8bb80 | |||
| 50035d5bc4 | |||
| 985f1a17b5 | |||
| 72ac1bc33c | |||
| f0d6b1c29f | |||
| bd5fc8ae62 | |||
| 9ca81ff3bc | |||
| d9607cf88c | |||
| 4f56f34d82 | |||
| e2956a84ce | |||
| 00a9eb72d8 | |||
| cbc8051c5c | |||
| a27b489ba2 | |||
| 790d85881b | |||
| d6a3917141 | |||
| 35e2253944 | |||
| a584b2e058 | |||
| 587bfd742f | |||
| 84ef963d7d | |||
| e70ef0a518 | |||
| e05768737f | |||
| a626e4693b | |||
| 4d9b4298d8 | |||
| 4cca7272ce | |||
| e9b2c18e2f | |||
| cbb576cbcc | |||
| bcc83bff31 | |||
| 68da8a674a | |||
| cafa82f018 | |||
| 83a9c394f3 | |||
| 2c0a1b836c | |||
| 28ae18792d | |||
| 2811ad02d5 | |||
| ab20c2d329 | |||
| d137bcf8d4 | |||
| 3674e1adee | |||
| 05a5e69483 | |||
| 5e9515a912 | |||
| 84a6d573f8 | |||
| 6228a399cf | |||
| 0e9f966dd1 | |||
| 07fde3177b | |||
| f9377b2aa6 | |||
| 499ab35012 | |||
| 3c95f92b95 | |||
| d7a7aa93a4 | |||
| 58ab4e8902 | |||
| fcd453118b | |||
| 7d179dd405 | |||
| 20b874f81f | |||
| e3f1880ad4 | |||
| 39293d7faf | |||
| c13eb99925 | |||
| 211ac0501f | |||
| af2f7baf63 | |||
| 3c25db3ffb | |||
| 12a6b0ceb8 | |||
| 0d041898ca | |||
| 982c093fbf | |||
| f54e798eac | |||
| cafb89f30f | |||
| f0360cf2d3 | |||
| 1be8d39105 | |||
| c026106352 | |||
| c507d0620b | |||
| f84672239a | |||
| c9bd7b4b5d | |||
| 470165a419 | |||
| 9de9fbe6bd | |||
| e396a2e6c3 | |||
| 829ea2e65c | |||
| 39d2d273dc | |||
| 5a3e660c0d | |||
| 589dc93380 | |||
| 33357c1fe4 | |||
| 5ce6bf8718 | |||
| d7bcf372c4 | |||
| 3aa044d722 | |||
| a9a5a73dfd | |||
| 66b44e68a9 | |||
| 51213899b7 | |||
| 7a7c9cd26c | |||
| 1b9ab46c5f | |||
| 2cbed28446 | |||
| 39aa0fdbfe | |||
| c983810e2d | |||
| c798db8056 | |||
| 1e4a80252e | |||
| bae3f949b4 | |||
| 7a7b981d4f | |||
| 2ffefeb1e0 | |||
| 1941418c10 | |||
| 186bb2dff0 | |||
| 2308632683 | |||
| ee21b69402 | |||
| 01512df853 | |||
| 7dcc0d597d | |||
| 154ef7fe65 | |||
| 4601f07349 | |||
| b7b9f12c88 | |||
| b48e8425ec | |||
| 3ce8227122 | |||
| 0bc3f71d27 | |||
| c1d4c0fb88 | |||
| 8078f3b588 | |||
| 5dd11a2ec2 | |||
| cc34a021ce | |||
| 10c096fbb6 | |||
| a85d8b6f90 | |||
| 5566111a7b | |||
| 6994e35119 | |||
| 4eedb62418 | |||
| 1f3cb2db5d | |||
| c40025a335 | |||
| 4171a73995 | |||
| 29e5f4ca10 | |||
| 05f6c75743 | |||
| 45d187bc14 | |||
| bc7903f86e | |||
| 72d233b587 | |||
| 2535367c3c | |||
| f4ff8d957f | |||
| 7bad358408 | |||
| 94b49818a1 | |||
| a245b722a8 | |||
| 8dc6a14766 | |||
| d66185ca03 | |||
| c3acabe303 | |||
| 4697d8eaf8 | |||
| 8bf71a5561 | |||
| 898cbd2c83 | |||
| 62762f1616 | |||
| 4d38e0bc87 | |||
| 25f9c29f00 | |||
| 096b30b5e8 | |||
| ac475c0a10 | |||
| 60800b5f25 | |||
| 36a4d78162 | |||
| 50cf2b49bd | |||
| 675d35c7a1 | |||
| bc469eecfb | |||
| bc01d9ed5b | |||
| 7a5be6736d | |||
| eb48460b7b | |||
| 85b4a8b1ae | |||
| e6bad637fd | |||
| 47b5cc27c8 | |||
| ca16841223 | |||
| 800c5c1e06 | |||
| 7fd8bd0171 | |||
| 4707efe4d6 | |||
| 8ae61f9448 | |||
| a138d0111d | |||
| af1adb44ce | |||
| 4ddf85bbc1 | |||
| 9978595c59 | |||
| 2943422d5d | |||
| 91219e3a0a | |||
| 7f8db9087a | |||
| aa16899c60 | |||
| 16a0d0d428 | |||
| 66f51d2b17 | |||
| 92c844b8ac | |||
| 2b56a3937b | |||
| 9cea9b6470 | |||
| e3e68b9f22 | |||
| d56839664d | |||
| 516dd7b044 | |||
| 53e59d3765 | |||
| 11d828b3b1 | |||
| 07472bec50 | |||
| f737787c01 | |||
| c6c1012330 | |||
| 070347295e | |||
| acd8d4a6ea | |||
| c9768416ed | |||
| bfb9ffad1d | |||
| 9cfe1307e3 | |||
| db8595711b | |||
| ce0001f94c | |||
| b102562478 | |||
| 69cbe10690 | |||
| e3e4ea91bd | |||
| 02c582e227 | |||
| 6e96cd29dc | |||
| 17044f43dc | |||
| 5d3b170ffc | |||
| a0f7b2242d | |||
| b8e7ad9022 | |||
| 1b80d55ea4 | |||
| a0832adfa5 | |||
| f17d398e8f | |||
| bc3b2ed5a8 | |||
| 07cf8925f9 | |||
| 564ebf3130 | |||
| dbee214259 | |||
| 6267c5cb25 | |||
| 4c06e26d85 | |||
| f2dc4eeec9 | |||
| f86e6ebf1f | |||
| 0d208c93bc | |||
| 485f311498 | |||
| 46b0d637e2 | |||
| 5a71847b7f | |||
| 38a9917815 | |||
| 4456f8da57 | |||
| 970b1a424a | |||
| edffa24658 | |||
| 3040e7360a | |||
| b948180b4e | |||
| f58d2627c1 | |||
| ab0d77f6f9 | |||
| 33d6cd8c0a | |||
| 4eef4f1803 | |||
| c75d4c749c | |||
| c8a1b9a1f0 | |||
| d8d8973ad5 | |||
| d1ded5c224 | |||
| 155a801bc1 | |||
| 6212b39264 | |||
| 92116072c2 | |||
| b0ab39e07f | |||
| 4bf27d1dae | |||
| 207ebffbb8 | |||
| b0dd83335f | |||
| 8df6457931 | |||
| 7d2a396b27 | |||
| d5df049630 | |||
| 7c62a706c4 | |||
| 96948d6f18 | |||
| 43e6498713 | |||
| 91561b40f6 | |||
| 0e8ea6363a | |||
| 345fa02fdc | |||
| 064adbae57 | |||
| ab458f4dfc | |||
| 0fdee9cbf6 | |||
| 50e3e93166 | |||
| 570835227b | |||
| 781c22e256 | |||
| babccfa21f | |||
| 891113717e | |||
| bfb9045fa9 | |||
| 1c6b174b8a | |||
| fb27fb01ea | |||
| b6327ecc43 | |||
| af71b9541c | |||
| f31b5ec3f8 | |||
| 6becd5a3aa | |||
| 653255c728 | |||
| 5f0ce38161 | |||
| d100033b46 | |||
| d008cabf07 | |||
| f3214144a4 | |||
| d41841b84a | |||
| 2a95e0eb1b | |||
| 81f8ab2691 | |||
| 4e61db8d0f | |||
| 273d4cfa1b | |||
| d290950d4f | |||
| 2ade5b8a7f | |||
| fcd4429370 | |||
| 8e62620880 | |||
| 511fb439ac | |||
| 34ea7e8d61 | |||
| 543c986885 | |||
| f939532461 | |||
| aa4e225455 | |||
| 65541a1df2 | |||
| 0a74b50a12 | |||
| 902c6487da | |||
| 1d5b7f59cf | |||
| 1c45c79cc1 | |||
| 85c5aeddae | |||
| a95e409f52 | |||
| 53b571d6fc | |||
| 7a8af044ee | |||
| a667744502 | |||
| aa53b8da15 | |||
| 52f7c83f95 | |||
| d7665119e4 | |||
| 587086beb4 | |||
| 644d24d1cc | |||
| 2fe8cfdc12 | |||
| 2ecd933d50 | |||
| 90ea1111e2 | |||
| 165a1c53b5 | |||
| 876935050a | |||
| d9a1299f6b | |||
| ff52d2655a | |||
| bc438ff694 | |||
| 0db3cac281 | |||
| 9ed6e8dbbd | |||
| 7294241c08 | |||
| 60cca0245b | |||
| 75b860e0b1 | |||
| 7f5a7323a6 | |||
| 1069458aee | |||
| 76edf9649b | |||
| 8b0d293c6a | |||
| 281d0dd68d | |||
| cfaa8f3881 | |||
| f1b6841757 | |||
| b966b2eabf | |||
| a4e573bb07 | |||
| 067d197dac | |||
| 18d04c7977 | |||
| a29453805c | |||
| 05b1296144 | |||
| 29e33069aa | |||
| ee05bb23c9 | |||
| 505da096e6 | |||
| 77be7b9e3b | |||
| ffafed472c | |||
| 8c9cc41099 | |||
| f50e008763 | |||
| 64b04c2764 | |||
| d6c7a9a89c | |||
| 0339f0fe23 | |||
| fcedaa3fc5 | |||
| 7acfc84c9d | |||
| 02b937ad17 | |||
| 7ad1c1ad17 | |||
| 640bd2b530 | |||
| 06149ef2bb | |||
| b271e8fe31 | |||
| efc6ab27db | |||
| 05c063839d | |||
| fd30b37a0e | |||
| 9738687116 | |||
| 219315c01d | |||
| 62f44e53fd | |||
| b25f8e438c | |||
| f14fce01e9 | |||
| a790770a19 | |||
| 7bb052ac37 | |||
| 631fe44c6b | |||
| ca319c804e | |||
| 3e368690fd | |||
| 339bf0a90b | |||
| c5b48f0362 | |||
| d5f50732c1 | |||
| 9d973aeceb | |||
| 7caeac7515 | |||
| 7f6a52019f | |||
| 16101b56fe | |||
| a294a91685 | |||
| cf644289a3 | |||
| 33c905ce02 | |||
| 8fdc222196 | |||
| 1e4d825d36 | |||
| 76bf7cba04 | |||
| 08bc5ac934 | |||
| c160cbccc7 | |||
| c473a5cba8 | |||
| 84801bce78 | |||
| b95b3473bf | |||
| f1d5caab8b | |||
| 6a973554ad | |||
| 698e239f45 | |||
| 205297d0b8 | |||
| ba4669a9c4 | |||
| 8bda799545 | |||
| 6c28e3aca8 | |||
| 901babe500 | |||
| 0c6f38ab08 | |||
| a131d6093c | |||
| 974cec3e73 | |||
| 442c5f090f | |||
| d04f08c1cf | |||
| 767c7ca0db | |||
| dd27aad751 | |||
| ddfdeaf2d0 | |||
| 4c51350517 | |||
| 40e48c963a | |||
| c44d347540 | |||
| 4a54bff225 | |||
| e39736153d | |||
| f032196d70 | |||
| a030e24b96 | |||
| c2993c6691 | |||
| 7d4a70ba25 | |||
| 38dfe3435a | |||
| 313c71dff6 | |||
| a88d92436f | |||
| 9d298dee51 | |||
| 9abc772b16 | |||
| 2f1df39204 | |||
| 0f328ec1fe | |||
| 78b6d6ca7b | |||
| 5cd3c33854 | |||
| 9af76843b5 | |||
| 53506124a4 | |||
| 9bbf9c7b13 | |||
| 82e6e8242e | |||
| 2bf11a556c | |||
| c62828bf14 | |||
| b53cf7e710 | |||
| 780277d0a6 | |||
| a6f5631542 | |||
| 52b1501ec0 | |||
| c9339f5cca | |||
| a9c23fb4aa | |||
| 72e3eaebfe | |||
| f3bcaa6cfb | |||
| 1c8f1517f8 | |||
| 50ae34cc19 | |||
| 8cc7d1345b | |||
| 0791c88a02 | |||
| ba08ffe38b | |||
| 1bec1e4dc4 | |||
| bcf8074f31 | |||
| 6a2d564eee | |||
| 709e14ecc1 | |||
| 5b1f446a6b | |||
| f41146c750 | |||
| d56ac81fd6 | |||
| fb213ef6eb | |||
| 933b019f71 | |||
| 6293ca3206 | |||
| d46d8de5f7 | |||
| 4e3284cd98 | |||
| 10876b99f5 | |||
| 61d31ce7c0 | |||
| e0f284d68f | |||
| df887d871b | |||
| 99f6ffe1ca | |||
| 138f9f7994 | |||
| 3886db9d4f | |||
| b877e06a02 | |||
| 38f4fc209b | |||
| b223acdecb | |||
| cc8a87b448 | |||
| ee3d414ed5 | |||
| d791aa0f15 | |||
| 393ae8adbd | |||
| 7037c6be7e | |||
| c10645f4f2 | |||
| 27da1015af | |||
| 78b0fe0e90 | |||
| 4651e41247 | |||
| a6c40f3193 | |||
| 3e138fd6db | |||
| 3c20b5472e | |||
| 8b782ce370 | |||
| a160a39d53 | |||
| 1c4b44e772 | |||
| b4b03f2752 | |||
| 1d21d3cfeb | |||
| d2ce33e66a | |||
| f0fbb8259b | |||
| 962c4a842d | |||
| 54e21afee7 | |||
| cc3f5149c6 | |||
| c8713aa412 | |||
| 02a82f3545 | |||
| c573746896 | |||
| 813b9593fa | |||
| bc68513708 | |||
| c4692bec3d | |||
| c53060d95a | |||
| 22c656d18e | |||
| 4d622e467c | |||
| 36326788b0 | |||
| 782ac1a36a | |||
| 8ca07d9acd | |||
| 4a57fe3c39 | |||
| 7579f1998c | |||
| 67a31d5eaa | |||
| 5b9d287b62 | |||
| 775670181c | |||
| 2a3bd5546a | |||
| 197e230ef1 | |||
| c6eeac11a4 | |||
| 90d3b623b4 | |||
| a59c2ac859 | |||
| 103fa5310f | |||
| 71b7de7a63 | |||
| a937ebc744 | |||
| 925882b253 | |||
| 615a5ee3f9 | |||
| 4a6d6a85f7 | |||
| 2937435960 | |||
| 2f3b5f5a51 | |||
| 5b4563f250 | |||
| 5da4bde428 | |||
| 42c4644be3 | |||
| 1845c493f4 | |||
| 8a0f754fe2 | |||
| 77bb4d423d | |||
| 1d483dc817 | |||
| a7103623af | |||
| 903e999cdc | |||
| 69eff97b34 | |||
| 8e20daa927 | |||
| 9e39dbf81e | |||
| 7a4feebe6f | |||
| 1d1561c6c3 | |||
| 9a5b3aeedc | |||
| ed931e7ed4 | |||
| 5ff9cecc5a | |||
| f8bca463bb | |||
| d5c6f0b623 | |||
| 7e57f443ed | |||
| b4cf2e7065 | |||
| 2ceabb69e6 | |||
| aa9d3360ba | |||
| 4580a64192 | |||
| 4cb0526980 | |||
| 03e2a8d558 | |||
| ab09cbfe3c | |||
| 0467e0c929 | |||
| 6e1c9afdd9 |
@@ -0,0 +1,7 @@
|
|||||||
|
[flake8]
|
||||||
|
max-line-length = 200
|
||||||
|
ignore = E126,E241,E741,W504
|
||||||
|
include =
|
||||||
|
system
|
||||||
|
exclude =
|
||||||
|
system/env
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<!--- Provide a general summary of the issue in the Title above -->
|
||||||
|
|
||||||
|
## Detailed Description
|
||||||
|
<!--- Provide a detailed description of the change or addition you are proposing -->
|
||||||
|
|
||||||
|
## Context
|
||||||
|
<!--- Why is this change important to you? How would you use it? -->
|
||||||
|
<!--- How can it benefit other users? -->
|
||||||
|
|
||||||
|
## Possible Implementation
|
||||||
|
<!--- Not obligatory, but suggest an idea for implementing addition or change -->
|
||||||
|
|
||||||
|
## Your Environment
|
||||||
|
<!--- Include as many relevant details about the environment you experienced the bug in -->
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
Fixes #
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
All new code should be covered with tests, documentation should be updated. CI should pass.
|
||||||
|
|
||||||
|
## Description of the Change
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
||||||
|
Why this change is important?
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
## Checklist
|
||||||
|
|
||||||
|
- [ ] unit-test added (if change is algorithm)
|
||||||
|
- [ ] functional test added/updated (if change is functional)
|
||||||
|
- [ ] man page updated (if applicable)
|
||||||
|
- [ ] bash completion updated (if applicable)
|
||||||
|
- [ ] documentation updated
|
||||||
|
- [ ] author name in `AUTHORS`
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
# Based on https://github.com/aptly-dev/aptly/blob/master/.travis.yml
|
||||||
|
|
||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
# see: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell
|
||||||
|
shell: bash --noprofile --norc -eo pipefail -x {0}
|
||||||
|
|
||||||
|
env:
|
||||||
|
DEBIAN_FRONTEND: noninteractive
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: test
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
continue-on-error: ${{ matrix.allow_failure }}
|
||||||
|
timeout-minutes: 30
|
||||||
|
strategy:
|
||||||
|
fail-fast: true
|
||||||
|
matrix:
|
||||||
|
go: [1.16, 1.17, 1.18]
|
||||||
|
run_long_tests: [no]
|
||||||
|
allow_failure: [false]
|
||||||
|
include:
|
||||||
|
# Disable this for now as it's not clear how to select the latest master branch
|
||||||
|
# version of go using actions/setup-go@v2.
|
||||||
|
# - go: master
|
||||||
|
# run_long_tests: no
|
||||||
|
# allow_failure: true
|
||||||
|
- go: 1.17
|
||||||
|
run_long_tests: yes
|
||||||
|
allow_failure: false
|
||||||
|
|
||||||
|
env:
|
||||||
|
NO_FTP_ACCESS: yes
|
||||||
|
BOTO_CONFIG: /dev/null
|
||||||
|
GO111MODULE: "on"
|
||||||
|
GOPROXY: "https://proxy.golang.org"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.go }}
|
||||||
|
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v2
|
||||||
|
with:
|
||||||
|
version: v1.45.0
|
||||||
|
|
||||||
|
- name: Setup Python
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: 3.9
|
||||||
|
|
||||||
|
- name: Install O/S packages
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y graphviz gnupg1 gnupg2 gpgv1 gpgv2 git gcc make
|
||||||
|
|
||||||
|
- name: Install Python packages
|
||||||
|
run: |
|
||||||
|
pip install six packaging appdirs virtualenv
|
||||||
|
pip install -U pip setuptools
|
||||||
|
pip install -r system/requirements.txt
|
||||||
|
|
||||||
|
- name: Install Azurite
|
||||||
|
id: azuright
|
||||||
|
uses: potatoqualitee/azuright@v1.1
|
||||||
|
with:
|
||||||
|
directory: ${{ runner.temp }}
|
||||||
|
|
||||||
|
- name: Get aptly version
|
||||||
|
run: |
|
||||||
|
make version
|
||||||
|
|
||||||
|
- name: Make
|
||||||
|
env:
|
||||||
|
RUN_LONG_TESTS: ${{ matrix.run_long_tests }}
|
||||||
|
AZURE_STORAGE_ENDPOINT: "127.0.0.1:10000"
|
||||||
|
AZURE_STORAGE_ACCOUNT: "devstoreaccount1"
|
||||||
|
AZURE_STORAGE_ACCESS_KEY: "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
|
||||||
|
run: |
|
||||||
|
make
|
||||||
|
|
||||||
|
- name: Upload code coverage
|
||||||
|
if: matrix.run_long_tests
|
||||||
|
uses: codecov/codecov-action@v2
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
files: coverage.txt
|
||||||
|
|
||||||
|
release:
|
||||||
|
name: release
|
||||||
|
needs: build
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
# fetch the whole repot for `git describe` to
|
||||||
|
# work and get the nightly verion
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
|
||||||
|
- name: Make Release
|
||||||
|
env:
|
||||||
|
GOBIN: /usr/local/bin
|
||||||
|
run: |
|
||||||
|
make release
|
||||||
|
|
||||||
|
- name: Publish nightly release to aptly
|
||||||
|
if: github.ref == 'refs/heads/master'
|
||||||
|
env:
|
||||||
|
APTLY_USER: ${{ secrets.APTLY_USER }}
|
||||||
|
APTLY_PASSWORD: ${{ secrets.APTLY_PASSWORD }}
|
||||||
|
run: |
|
||||||
|
./upload-artifacts.sh nightly
|
||||||
|
|
||||||
|
- name: Publish release to aptly
|
||||||
|
if: startsWith(github.event.ref, 'refs/tags')
|
||||||
|
env:
|
||||||
|
APTLY_USER: ${{ secrets.APTLY_USER }}
|
||||||
|
APTLY_PASSWORD: ${{ secrets.APTLY_PASSWORD }}
|
||||||
|
run: |
|
||||||
|
./upload-artifacts.sh release
|
||||||
|
|
||||||
|
- name: Upload artifacts to GitHub Release
|
||||||
|
if: startsWith(github.event.ref, 'refs/tags')
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
body: Release ${{ github.ref }} generated by the CI.
|
||||||
|
files: build/*
|
||||||
+14
-4
@@ -22,13 +22,23 @@ _testmain.go
|
|||||||
*.exe
|
*.exe
|
||||||
*.test
|
*.test
|
||||||
|
|
||||||
coverage.html
|
coverage.txt
|
||||||
coverage*.out
|
|
||||||
|
|
||||||
*.pyc
|
*.pyc
|
||||||
|
|
||||||
_vendor/
|
xc-out/
|
||||||
|
root/
|
||||||
|
|
||||||
gen
|
|
||||||
man/aptly.1.html
|
man/aptly.1.html
|
||||||
man/aptly.1.ronn
|
man/aptly.1.ronn
|
||||||
|
|
||||||
|
.goxc.local.json
|
||||||
|
|
||||||
|
system/env/
|
||||||
|
|
||||||
|
# created by make build for release artifacts
|
||||||
|
build/
|
||||||
|
|
||||||
|
pgp/keyrings/aptly2*.gpg
|
||||||
|
pgp/keyrings/aptly2*.gpg~
|
||||||
|
pgp/keyrings/.#*
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
run:
|
||||||
|
tests: false
|
||||||
|
|
||||||
|
|
||||||
|
linters:
|
||||||
|
disable-all: true
|
||||||
|
enable:
|
||||||
|
- deadcode
|
||||||
|
- goconst
|
||||||
|
- gofmt
|
||||||
|
- goimports
|
||||||
|
- govet
|
||||||
|
- ineffassign
|
||||||
|
- misspell
|
||||||
|
- revive
|
||||||
|
- staticcheck
|
||||||
|
- structcheck
|
||||||
|
- varcheck
|
||||||
|
- vetshadow
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
{
|
||||||
|
"AppName": "aptly",
|
||||||
|
"ArtifactsDest": "xc-out/",
|
||||||
|
"TasksExclude": [
|
||||||
|
"rmbin",
|
||||||
|
"go-test",
|
||||||
|
"go-vet"
|
||||||
|
],
|
||||||
|
"TasksAppend": [
|
||||||
|
"bintray"
|
||||||
|
],
|
||||||
|
"TaskSettings": {
|
||||||
|
"debs": {
|
||||||
|
"metadata": {
|
||||||
|
"maintainer": "Andrey Smirnov",
|
||||||
|
"maintainer-email": "me@smira.ru",
|
||||||
|
"description": "Debian repository management tool"
|
||||||
|
},
|
||||||
|
"metadata-deb": {
|
||||||
|
"License": "MIT",
|
||||||
|
"Homepage": "https://www.aptly.info/",
|
||||||
|
"Depends": "bzip2, xz-utils, gnupg, gpgv",
|
||||||
|
"Suggests": "graphviz"
|
||||||
|
},
|
||||||
|
"other-mapped-files": {
|
||||||
|
"/": "root/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"bintray": {
|
||||||
|
"repository": "aptly",
|
||||||
|
"subject": "smira",
|
||||||
|
"package": "aptly",
|
||||||
|
"downloadspage": "bintray.md"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ResourcesInclude": "README.rst,LICENSE,AUTHORS,man/aptly.1",
|
||||||
|
"BuildConstraints": "linux,386 linux,amd64 darwin,amd64 freebsd,386 freebsd,amd64",
|
||||||
|
"MainDirsExclude": "_man,vendor",
|
||||||
|
"BuildSettings": {
|
||||||
|
"LdFlagsXVars": {
|
||||||
|
"Version": "main.Version"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ConfigVersion": "0.9"
|
||||||
|
}
|
||||||
+88
-17
@@ -1,30 +1,63 @@
|
|||||||
|
dist: xenial
|
||||||
|
sudo: required
|
||||||
|
|
||||||
language: go
|
language: go
|
||||||
|
|
||||||
go:
|
go_import_path: github.com/aptly-dev/aptly
|
||||||
- 1.3.3
|
|
||||||
- tip
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- python-virtualenv
|
||||||
|
- graphviz
|
||||||
|
- gnupg2
|
||||||
|
- gpgv2
|
||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- secure: "YSwtFrMqh4oUvdSQTXBXMHHLWeQgyNEL23ChIZwU0nuDGIcQZ65kipu0PzefedtUbK4ieC065YCUi4UDDh6gPotB/Wu1pnYg3dyQ7rFvhaVYAAUEpajAdXZhlx+7+J8a4FZMeC/kqiahxoRgLbthF9019ouIqhGB9zHKI6/yZwc="
|
- secure: "EcCzJsqQ3HnIkprBPS1YHErsETcb7KQFBYEzVDE7RYDApWeapLq+r/twMtWMd/fkGeLzr3kWSg7nhSadeHMLYeMl9j+U7ncC5CWG5NMBOj/jowlb9cMCCDlmzMoZLAgR6jm1cJyrWCLsWVlv+D0ZiB0fx4xaBZP/gIr9g6nEwC8="
|
||||||
- secure: "V7OjWrfQ8UbktgT036jYQPb/7GJT3Ol9LObDr8FYlzsQ+F1uj2wLac6ePuxcOS4FwWOJinWGM1h+JiFkbxbyFqfRNJ0jj0O2p93QyDojxFVOn1mXqqvV66KFqAWR2Vzkny/gDvj8LTvdB1cgAIm2FNOkQc6E1BFnyWS2sN9ea5E="
|
|
||||||
- secure: "OxiVNmre2JzUszwPNNilKDgIqtfX2gnRSsVz6nuySB1uO2yQsOQmKWJ9cVYgH2IB5H8eWXKOhexcSE28kz6TPLRuEcU9fnqKY3uEkdwm7rJfz9lf+7C4bJEUdA1OIzJppjnWUiXxD7CEPL1DlnMZM24eDQYqa/4WKACAgkK53gE="
|
- secure: "OxiVNmre2JzUszwPNNilKDgIqtfX2gnRSsVz6nuySB1uO2yQsOQmKWJ9cVYgH2IB5H8eWXKOhexcSE28kz6TPLRuEcU9fnqKY3uEkdwm7rJfz9lf+7C4bJEUdA1OIzJppjnWUiXxD7CEPL1DlnMZM24eDQYqa/4WKACAgkK53gE="
|
||||||
before_install:
|
- NO_FTP_ACCESS: "yes"
|
||||||
- sudo apt-get update -qq
|
- BOTO_CONFIG: /dev/null
|
||||||
- sudo apt-get install -y python-virtualenv graphviz
|
- GO111MODULE: "on"
|
||||||
- virtualenv env
|
- GOPROXY: https://proxy.golang.org
|
||||||
- . env/bin/activate
|
|
||||||
- pip install boto requests python-swiftclient
|
|
||||||
install:
|
|
||||||
- make prepare
|
|
||||||
|
|
||||||
|
|
||||||
script: make travis
|
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- go: tip
|
- go: master
|
||||||
|
env: RUN_LONG_TESTS=no
|
||||||
|
fast_finish: true
|
||||||
|
include:
|
||||||
|
- go: 1.11.x
|
||||||
|
env: RUN_LONG_TESTS=no
|
||||||
|
- go: 1.12.x
|
||||||
|
env: RUN_LONG_TESTS=no
|
||||||
|
- go: 1.13.x
|
||||||
|
env: RUN_LONG_TESTS=no
|
||||||
|
- go: 1.14.x
|
||||||
|
env: RUN_LONG_TESTS=yes
|
||||||
|
- go: 1.15.x
|
||||||
|
env:
|
||||||
|
- RUN_LONG_TESTS=yes
|
||||||
|
- DEPLOY_BINARIES=yes
|
||||||
|
- APTLY_USER=aptly
|
||||||
|
- secure: "ejVss+Ansvk9f237iXVd87KA8N/SkfJkEdr/KCw9WRkVw3M9WyYtFnqpakIUPFT8RsSc7MW+RU4OM90DsbE9dbDIL0oW+t6QH/IfGjNG2HjDiGEWN/tMLeAQTtzPaVqlItJBo0ILMF2K6NrgkYBYU+tZ8gk5w7CuARvAk82d00o="
|
||||||
|
- go: master
|
||||||
|
env: RUN_LONG_TESTS=no
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- virtualenv system/env
|
||||||
|
- . system/env/bin/activate
|
||||||
|
- pip install six packaging appdirs
|
||||||
|
- pip install -U pip setuptools
|
||||||
|
- pip install -r system/requirements.txt
|
||||||
|
- make version
|
||||||
|
|
||||||
|
install:
|
||||||
|
- make prepare
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
- bash <(curl -s https://codecov.io/bash)
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
webhooks:
|
webhooks:
|
||||||
@@ -33,3 +66,41 @@ notifications:
|
|||||||
on_success: change # options: [always|never|change] default: always
|
on_success: change # options: [always|never|change] default: always
|
||||||
on_failure: always # options: [always|never|change] default: always
|
on_failure: always # options: [always|never|change] default: always
|
||||||
on_start: false # default: false
|
on_start: false # default: false
|
||||||
|
|
||||||
|
before_deploy:
|
||||||
|
- make release
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
- provider: releases
|
||||||
|
api_key:
|
||||||
|
secure: XHxYAFBzzgOZyK6JXQpEp0kGrZPmd02esEJjwJXZpWT68kRzCCrBXg+x3vIcgRtl82oQbflv/ThNlGT80iqSmd+Itsa5lUJoJnRxbP8qSykfCXmkrgsHIxbGxWIL+JHAWmwQdkV91kDS04nmjl9MDptLId0tuleWwcMH6h1hgMg=
|
||||||
|
file_glob: true
|
||||||
|
file: build/*
|
||||||
|
skip_cleanup: true
|
||||||
|
on:
|
||||||
|
tags: true
|
||||||
|
condition: "$DEPLOY_BINARIES = yes"
|
||||||
|
- provider: s3
|
||||||
|
access_key_id:
|
||||||
|
secure: "I2etn22HHsQjJNhr6zdM/P4VLCYwEA/6HEf2eGvwey93oLeog+KnDCUI7lwGAHYuwzyDGQbZZ6YdoNc3b0kxaRWT0W+ke78TAdJhTZ+xbqGfEWv1er0zklJLOsimYF097rDJw8g3Oh/Gjwt5TTp0GJ5l3IhJ6zepNsKCMuwQpJM="
|
||||||
|
secret_access_key:
|
||||||
|
secure: "inRWX7FuyhkhKzGknSd2/mjZaNFZm/zHMejM99OF6PiGLNtyt/esdA0ToYL8B8Icl0/SISlLlEr/DDa4OGENKueFVeHrKH7OK0jVbWp9Yvw4hCXSlw9VmlkHDMQrC4gybS2Hf7el8N4AFVqyeUE7LqiP3WruHRdbE9XgOnTkLkg="
|
||||||
|
bucket: aptly-nightly
|
||||||
|
skip_cleanup: true
|
||||||
|
acl: public-read
|
||||||
|
local_dir: build
|
||||||
|
on:
|
||||||
|
branch: master
|
||||||
|
condition: "$DEPLOY_BINARIES = yes"
|
||||||
|
- provider: script
|
||||||
|
script: bash upload-artifacts.sh nightly
|
||||||
|
skip_cleanup: true
|
||||||
|
on:
|
||||||
|
branch: master
|
||||||
|
condition: "$DEPLOY_BINARIES = yes"
|
||||||
|
- provider: script
|
||||||
|
script: bash upload-artifacts.sh release
|
||||||
|
skip_cleanup: true
|
||||||
|
on:
|
||||||
|
tags: true
|
||||||
|
condition: "$DEPLOY_BINARIES = yes"
|
||||||
|
|||||||
@@ -15,3 +15,37 @@ List of contributors, in chronological order:
|
|||||||
* Michael Koval (https://github.com/mkoval)
|
* Michael Koval (https://github.com/mkoval)
|
||||||
* Alexander Guy (https://github.com/alexanderguy)
|
* Alexander Guy (https://github.com/alexanderguy)
|
||||||
* Sebastien Badia (https://github.com/sbadia)
|
* Sebastien Badia (https://github.com/sbadia)
|
||||||
|
* Szymon Sobik (https://github.com/sobczyk)
|
||||||
|
* Paul Krohn (https://github.com/paul-krohn)
|
||||||
|
* Vincent Bernat (https://github.com/vincentbernat)
|
||||||
|
* x539 (https://github.com/x539)
|
||||||
|
* Phil Frost (https://github.com/bitglue)
|
||||||
|
* Benoit Foucher (https://github.com/bentoi)
|
||||||
|
* Geoffrey Thomas (https://github.com/geofft)
|
||||||
|
* Oliver Sauder (https://github.com/sliverc)
|
||||||
|
* Harald Sitter (https://github.com/apachelogger)
|
||||||
|
* Johannes Layher (https://github.com/jola5)
|
||||||
|
* Charles Hsu (https://github.com/charz)
|
||||||
|
* Clemens Rabe (https://github.com/seeraven)
|
||||||
|
* TJ Merritt (https://github.com/tjmerritt)
|
||||||
|
* Matt Martyn (https://github.com/MMartyn)
|
||||||
|
* Ludovico Cavedon (https://github.com/cavedon)
|
||||||
|
* Petr Jediny (https://github.com/pjediny)
|
||||||
|
* Maximilian Stein (https://github.com/steinymity)
|
||||||
|
* Strajan Sebastian (https://github.com/strajansebastian)
|
||||||
|
* Artem Smirnov (https://github.com/urpylka)
|
||||||
|
* William Manley (https://github.com/wmanley)
|
||||||
|
* Shengjing Zhu (https://github.com/zhsj)
|
||||||
|
* Nabil Bendafi (https://github.com/nabilbendafi)
|
||||||
|
* Raphael Medaer (https://github.com/rmedaer)
|
||||||
|
* Raul Benencia (https://github.com/rul)
|
||||||
|
* Don Kuntz (https://github.com/dkuntz2)
|
||||||
|
* Joshua Colson (https://github.com/freakinhippie)
|
||||||
|
* Andre Roth (https://github.com/neolynx)
|
||||||
|
* Lorenzo Bolla (https://github.com/lbolla)
|
||||||
|
* Benj Fassbind (https://github.com/randombenj)
|
||||||
|
* Markus Muellner (https://github.com/mmianl)
|
||||||
|
* Chuan Liu (https://github.com/chuan)
|
||||||
|
* Samuel Mutel (https://github.com/smutel)
|
||||||
|
* Russell Greene (https://github.com/russelltg)
|
||||||
|
* Wade Simmons (https://github.com/wadey)
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
# Contributor Covenant Code of Conduct
|
||||||
|
|
||||||
|
## Our Pledge
|
||||||
|
|
||||||
|
In the interest of fostering an open and welcoming environment, we as
|
||||||
|
contributors and maintainers pledge to making participation in our project and
|
||||||
|
our community a harassment-free experience for everyone, regardless of age, body
|
||||||
|
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||||
|
nationality, personal appearance, race, religion, or sexual identity and
|
||||||
|
orientation.
|
||||||
|
|
||||||
|
## Our Standards
|
||||||
|
|
||||||
|
Examples of behavior that contributes to creating a positive environment
|
||||||
|
include:
|
||||||
|
|
||||||
|
* Using welcoming and inclusive language
|
||||||
|
* Being respectful of differing viewpoints and experiences
|
||||||
|
* Gracefully accepting constructive criticism
|
||||||
|
* Focusing on what is best for the community
|
||||||
|
* Showing empathy towards other community members
|
||||||
|
|
||||||
|
Examples of unacceptable behavior by participants include:
|
||||||
|
|
||||||
|
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||||
|
advances
|
||||||
|
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||||
|
* Public or private harassment
|
||||||
|
* Publishing others' private information, such as a physical or electronic
|
||||||
|
address, without explicit permission
|
||||||
|
* Other conduct which could reasonably be considered inappropriate in a
|
||||||
|
professional setting
|
||||||
|
|
||||||
|
## Our Responsibilities
|
||||||
|
|
||||||
|
Project maintainers are responsible for clarifying the standards of acceptable
|
||||||
|
behavior and are expected to take appropriate and fair corrective action in
|
||||||
|
response to any instances of unacceptable behavior.
|
||||||
|
|
||||||
|
Project maintainers have the right and responsibility to remove, edit, or
|
||||||
|
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||||
|
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||||
|
permanently any contributor for other behaviors that they deem inappropriate,
|
||||||
|
threatening, offensive, or harmful.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
This Code of Conduct applies both within project spaces and in public spaces
|
||||||
|
when an individual is representing the project or its community. Examples of
|
||||||
|
representing a project or community include using an official project e-mail
|
||||||
|
address, posting via an official social media account, or acting as an appointed
|
||||||
|
representative at an online or offline event. Representation of a project may be
|
||||||
|
further defined and clarified by project maintainers.
|
||||||
|
|
||||||
|
## Enforcement
|
||||||
|
|
||||||
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||||
|
reported by contacting the project team at [team@aptly.info](mailto:team@aptly.info). All
|
||||||
|
complaints will be reviewed and investigated and will result in a response that
|
||||||
|
is deemed necessary and appropriate to the circumstances. The project team is
|
||||||
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||||
|
Further details of specific enforcement policies may be posted separately.
|
||||||
|
|
||||||
|
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||||
|
faith may face temporary or permanent repercussions as determined by other
|
||||||
|
members of the project's leadership.
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
|
||||||
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||||
|
available at [http://contributor-covenant.org/version/1/4][version]
|
||||||
|
|
||||||
|
[homepage]: http://contributor-covenant.org
|
||||||
|
[version]: http://contributor-covenant.org/version/1/4/
|
||||||
+241
@@ -0,0 +1,241 @@
|
|||||||
|
# Contributing to aptly
|
||||||
|
|
||||||
|
:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:
|
||||||
|
|
||||||
|
The following is a set of guidelines for contributing to [aptly](https://github.com/smira/aplty) and related repositories, which are hosted in the [aptly-dev Organization](https://github.com/aptly-dev) on GitHub.
|
||||||
|
These are just guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
|
||||||
|
|
||||||
|
## What should I know before I get started?
|
||||||
|
|
||||||
|
### Code of Conduct
|
||||||
|
|
||||||
|
This project adheres to the Contributor Covenant [code of conduct](CODE_OF_CONDUCT.md).
|
||||||
|
By participating, you are expected to uphold this code.
|
||||||
|
Please report unacceptable behavior to [team@aptly.info](mailto:team@aptly.info).
|
||||||
|
|
||||||
|
### List of Repositories
|
||||||
|
|
||||||
|
* [aptly-dev/aptly](https://github.com/aptly-dev/aptly) - aptly source code, functional tests, man page
|
||||||
|
* [apty-dev/aptly-dev.github.io](https://github.com/aptly-dev/aptly-dev.github.io) - aptly website (https://www.aptly.info/)
|
||||||
|
* [aptly-dev/aptly-fixture-db](https://github.com/aptly-dev/aptly-fixture-db) & [aptly-dev/aptly-fixture-pool](https://github.com/aptly-dev/aptly-fixture-pool) provide
|
||||||
|
fixtures for aptly functional tests
|
||||||
|
|
||||||
|
## How Can I Contribute?
|
||||||
|
|
||||||
|
### Reporting Bugs
|
||||||
|
|
||||||
|
1. Please search for similar bug report in [issue tracker](https://github.com/aptly-dev/aptly/issues)
|
||||||
|
2. Please verify that bug is not fixed in latest aptly nightly ([download information](https://www.aptly.info/download/))
|
||||||
|
3. Steps to reproduce increases chances for bug to be fixed quickly. If possible, submit PR with new functional test which fails.
|
||||||
|
4. If bug is reproducible with specific package, please provide link to package file.
|
||||||
|
5. Open issue at [GitHub](https://github.com/aptly-dev/aptly/issues)
|
||||||
|
|
||||||
|
### Suggesting Enhancements
|
||||||
|
|
||||||
|
1. Please search [issue tracker](https://github.com/aptly-dev/aptly/issues) for similar feature requests.
|
||||||
|
2. Describe why enhancement is important to you.
|
||||||
|
3. Include any additional details or implementation details.
|
||||||
|
|
||||||
|
### Improving Documentation
|
||||||
|
|
||||||
|
There are two kinds of documentation:
|
||||||
|
|
||||||
|
* [aptly website](https://www.aptly.info)
|
||||||
|
* aptly `man` page
|
||||||
|
|
||||||
|
Core content is mostly the same, but website contains more information, tutorials, examples.
|
||||||
|
|
||||||
|
If you want to update `man` page, please open PR to [main aptly repo](https://github.com/aptly-dev/aptly),
|
||||||
|
details in [man page](#man-page) section.
|
||||||
|
|
||||||
|
If you want to update website, please follow steps below:
|
||||||
|
|
||||||
|
1. Install [hugo](http://gohugo.io/)
|
||||||
|
2. Fork [website source](https://github.com/aptly-dev/aptly-dev.github.io) and clone it
|
||||||
|
3. Launch hugo in development mode: `hugo -w server`
|
||||||
|
4. Navigate to `http://localhost:1313/`: you should see aptly website
|
||||||
|
5. Update documentation, most of the time editing Markdown is all you need.
|
||||||
|
6. Page in browser should reload automatically as you make changes to source files.
|
||||||
|
|
||||||
|
We're always looking for new contributions to [FAQ](https://www.aptly.info/doc/faq/), [tutorials](https://www.aptly.info/tutorial/),
|
||||||
|
general fixes, clarifications, misspellings, grammar mistakes!
|
||||||
|
|
||||||
|
### Your First Code Contribution
|
||||||
|
|
||||||
|
Please follow [next section](#development-setup) on development process. When change is ready, please submit PR
|
||||||
|
following [PR template](.github/PULL_REQUEST_TEMPLATE.md).
|
||||||
|
|
||||||
|
Make sure that purpose of your change is clear, all the tests and checks pass, and all new code is covered with tests
|
||||||
|
if that is possible.
|
||||||
|
|
||||||
|
## Development Setup
|
||||||
|
|
||||||
|
This section describes local setup to start contributing to aptly source.
|
||||||
|
|
||||||
|
### Go & Python
|
||||||
|
|
||||||
|
You would need `Go` (latest version is recommended) and `Python` 2.7.x (3.x is not supported yet).
|
||||||
|
|
||||||
|
If you're new to Go, follow [getting started guide](https://golang.org/doc/install) to install it and perform
|
||||||
|
initial setup. With Go 1.8+, default `$GOPATH` is `$HOME/go`, so rest of this document assumes that.
|
||||||
|
|
||||||
|
Usually `$GOPATH/bin` is appended to your `$PATH` to make it easier to run built binaries, but you might choose
|
||||||
|
to prepend it or to skip this test if you're security conscious.
|
||||||
|
|
||||||
|
### Forking and Cloning
|
||||||
|
|
||||||
|
As aptly is using Go modules, aptly repository could be cloned to any location on the file system:
|
||||||
|
|
||||||
|
git clone git@github.com:aptly-dev/aptly.git
|
||||||
|
cd aptly
|
||||||
|
|
||||||
|
For main repo under your GitHub user and add it as another Git remote:
|
||||||
|
|
||||||
|
git remote add <user> git@github.com:<user>/aptly.git
|
||||||
|
|
||||||
|
That way you can continue to build project as is (you don't need to adjust import paths), but you would need
|
||||||
|
to specify your remote name when pushing branches:
|
||||||
|
|
||||||
|
git push <user> <your-branch>
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
|
||||||
|
You would need some additional tools and Python virtual environment to run tests and checks, install them with:
|
||||||
|
|
||||||
|
make prepare dev system/env
|
||||||
|
|
||||||
|
This is usually one-time action.
|
||||||
|
|
||||||
|
Aptly is using Go modules to manage dependencies, download modules using:
|
||||||
|
|
||||||
|
make modules
|
||||||
|
|
||||||
|
### Building
|
||||||
|
|
||||||
|
If you want to build aptly binary from your current source tree, run:
|
||||||
|
|
||||||
|
make install
|
||||||
|
|
||||||
|
This would build `aptly` in `$GOPATH/bin`, so depending on your `$PATH`, you should be able to run it immediately with:
|
||||||
|
|
||||||
|
aptly
|
||||||
|
|
||||||
|
Or, if it's not on your path:
|
||||||
|
|
||||||
|
~/go/bin/aptly
|
||||||
|
|
||||||
|
### Unit-tests
|
||||||
|
|
||||||
|
aptly has two kinds of tests: unit-tests and functional (system) tests. Functional tests are preferred way to test any
|
||||||
|
feature, but some features are much easier to test with unit-tests (e.g. algorithms, failure scenarios, ...)
|
||||||
|
|
||||||
|
aptly is using standard Go unit-test infrastructure plus [gocheck](http://labix.org/gocheck). Run the unit-tests with:
|
||||||
|
|
||||||
|
make test
|
||||||
|
|
||||||
|
### Functional Tests
|
||||||
|
|
||||||
|
Functional tests are implemented in Python, and they use custom test runner which is similar to Python unit-test
|
||||||
|
runner. Most of the tests start with clean aptly state, run some aptly commands to prepare environment, and finally
|
||||||
|
run some aptly commands capturing output, exit code, checking any additional files being created and so on. API tests
|
||||||
|
are a bit different, as they re-use same aptly process serving API requests.
|
||||||
|
|
||||||
|
The easiest way to run functional tests is to use `make`:
|
||||||
|
|
||||||
|
make system-test
|
||||||
|
|
||||||
|
This would check all the dependencies and run all the tests. Some tests (S3, Swift) require access credentials to
|
||||||
|
be set up in the environment. For example, it needs AWS credentials to run S3 tests (they would be used to publish to S3).
|
||||||
|
If credentials are missing, tests would be skipped.
|
||||||
|
|
||||||
|
You can also run subset of tests manually:
|
||||||
|
|
||||||
|
system/run.py t04_mirror
|
||||||
|
|
||||||
|
This would run all the mirroring tests under `system/t04_mirror` folder.
|
||||||
|
|
||||||
|
Or you can run tests by test name mask:
|
||||||
|
|
||||||
|
system/run.py UpdateMirror*
|
||||||
|
|
||||||
|
Or, you can run specific test by name:
|
||||||
|
|
||||||
|
system/run.py UpdateMirror7Test
|
||||||
|
|
||||||
|
Test runner can update expected output instead of failing on mismatch (this is especially useful while
|
||||||
|
working on new tests):
|
||||||
|
|
||||||
|
system/run.py --capture <test>
|
||||||
|
|
||||||
|
Output for some tests might contain environment-specific things, e.g. your home directory. In that case
|
||||||
|
you can use `${HOME}` and similar variable expansion in expected output files.
|
||||||
|
|
||||||
|
Some tests depend on fixtures, for example pre-populated GPG trusted keys. There are also test fixtures
|
||||||
|
captured after mirror update which contain pre-build aptly database and pool contents. They're useful if you
|
||||||
|
don't want to waste time in the test on populating aptly database while you need some packages to work with.
|
||||||
|
There are some packages available under `system/files/` directory which are used to build contents of local repos.
|
||||||
|
|
||||||
|
*WARNING*: tests are running under current `$HOME` directory with aptly default settings, so they clear completely
|
||||||
|
`~/.aptly.conf` and `~/.aptly` subdirectory between the runs. So it's not wise to have non-dev aptly being used with
|
||||||
|
this default location. You can run aptly under different user or by using non-default config location with non-default
|
||||||
|
aptly root directory.
|
||||||
|
|
||||||
|
### Style Checks
|
||||||
|
|
||||||
|
Style checks could be run with:
|
||||||
|
|
||||||
|
make check
|
||||||
|
|
||||||
|
aptly is using [golangci-lint](https://github.com/golangci/golangci-lint) to run style checks on Go code. Configuration
|
||||||
|
for the linter could be found in [.golangci.yml](.golangci.yml) file.
|
||||||
|
|
||||||
|
Python code (system tests) are linted with [flake8 tool](https://pypi.python.org/pypi/flake8).
|
||||||
|
|
||||||
|
### Vendored Code
|
||||||
|
|
||||||
|
aptly is using Go vendoring for all the libraries aptly depends upon. `vendor/` directory is checked into the source
|
||||||
|
repository to avoid any problems if source repositories go away. Go build process will automatically prefer vendored
|
||||||
|
packages over packages in `$GOPATH`.
|
||||||
|
|
||||||
|
If you want to update vendored dependencies or to introduce new dependency, use [dep tool](https://github.com/golang/dep).
|
||||||
|
Usually all you need is `dep ensure` or `dep ensure -update`.
|
||||||
|
|
||||||
|
### man Page
|
||||||
|
|
||||||
|
aptly is using combination of [Go templates](http://godoc.org/text/template) and automatically generated text to build `aptly.1` man page. If either source
|
||||||
|
template [man/aptly.1.ronn.tmpl](man/aptly.1.ronn.tmpl) is changed or any command help is changed, run `make man` to regenerate
|
||||||
|
final rendered man page [man/aptly.1](man/aptly.1). In the end of the build, new man page is displayed for visual
|
||||||
|
verification.
|
||||||
|
|
||||||
|
Man page is built with small helper [\_man/gen.go](man/gen.go) which pulls in template, command-line help from [cmd/](cmd/) folder
|
||||||
|
and runs that through [forked copy](https://github.com/smira/ronn) of [ronn](https://github.com/rtomayko/ronn).
|
||||||
|
|
||||||
|
### Bash and Zsh Completion
|
||||||
|
|
||||||
|
Bash and Zsh completion for aptly reside in the same repo under in [completion.d/aptly](completion.d/aptly) and
|
||||||
|
[completion.d/\_aptly](completion.d/_aptly), respectively. It's all hand-crafted.
|
||||||
|
When new option or command is introduced, bash completion should be updated to reflect that change.
|
||||||
|
|
||||||
|
When aptly package is being built, it automatically pulls bash completion and man page into the package.
|
||||||
|
|
||||||
|
## Design
|
||||||
|
|
||||||
|
This section requires future work.
|
||||||
|
|
||||||
|
*TBD*
|
||||||
|
|
||||||
|
### Database
|
||||||
|
|
||||||
|
### Package Pool
|
||||||
|
|
||||||
|
### Package
|
||||||
|
|
||||||
|
### PackageList, PackageRefList
|
||||||
|
|
||||||
|
### LocalRepo, RemoteRepo, Snapshot
|
||||||
|
|
||||||
|
### PublishedRepository
|
||||||
|
|
||||||
|
### Context
|
||||||
|
|
||||||
|
### Collections, CollectionFactory
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
gom 'code.google.com/p/go-uuid/uuid', :commit => '5fac954758f5'
|
|
||||||
gom 'code.google.com/p/gographviz', :commit => '454bc64fdfa2'
|
|
||||||
gom 'code.google.com/p/mxk/go1/flowcontrol', :commit => '5ff2502e2556'
|
|
||||||
gom 'code.google.com/p/snappy-go/snappy', :commit => '12e4b4183793'
|
|
||||||
gom 'github.com/AlekSi/pointer', :commit => '5f6d527dae3d678b46fbb20331ddf44e2b841943'
|
|
||||||
gom 'github.com/cheggaaa/pb', :commit => '2c1b74620cc58a81ac152ee2d322e28c806d81ed'
|
|
||||||
gom 'github.com/gin-gonic/gin', :commit => 'b1758d3bfa09e61ddbc1c9a627e936eec6a170de'
|
|
||||||
gom 'github.com/jlaffaye/ftp', :commit => 'fec71e62e457557fbe85cefc847a048d57815d76'
|
|
||||||
gom 'github.com/julienschmidt/httprouter', :commit => '46807412fe50aaceb73bb57061c2230fd26a1640'
|
|
||||||
gom 'github.com/mattn/go-shellwords', :commit => 'c7ca6f94add751566a61cf2199e1de78d4c3eee4'
|
|
||||||
gom 'github.com/mitchellh/goamz/s3', :commit => 'e7664b32019f31fd1bdf33f9e85f28722f700405'
|
|
||||||
gom 'github.com/mkrautz/goar', :commit => '36eb5f3452b1283a211fa35bc00c646fd0db5c4b'
|
|
||||||
gom 'github.com/ncw/swift', :commit => '384ef27c70645e285f8bb9d02276bf654d06027e'
|
|
||||||
gom 'github.com/smira/commander', :commit => 'f408b00e68d5d6e21b9f18bd310978dafc604e47'
|
|
||||||
gom 'github.com/smira/flag', :commit => '357ed3e599ffcbd4aeaa828e1d10da2df3ea5107'
|
|
||||||
gom 'github.com/smira/go-ftp-protocol/protocol', :commit => '066b75c2b70dca7ae10b1b88b47534a3c31ccfaa'
|
|
||||||
gom 'github.com/syndtr/gosnappy/snappy', :commit => 'ce8acff4829e0c2458a67ead32390ac0a381c862'
|
|
||||||
gom 'github.com/syndtr/goleveldb/leveldb', :commit => '97e257099d2ab9578151ba85e2641e2cd14d3ca8'
|
|
||||||
gom 'github.com/ugorji/go/codec', :commit => '71c2886f5a673a35f909803f38ece5810165097b'
|
|
||||||
gom 'github.com/vaughan0/go-ini', :commit => 'a98ad7ee00ec53921f08832bc06ecf7fd600e6a1'
|
|
||||||
gom 'github.com/wsxiaoys/terminal/color', :commit => '5668e431776a7957528361f90ce828266c69ed08'
|
|
||||||
gom 'golang.org/x/crypto/ssh/terminal', :commit => 'a7ead6ddf06233883deca151dffaef2effbf498f'
|
|
||||||
|
|
||||||
group :test do
|
|
||||||
gom 'gopkg.in/check.v1'
|
|
||||||
end
|
|
||||||
|
|
||||||
group :development do
|
|
||||||
gom 'github.com/golang/lint/golint'
|
|
||||||
gom 'github.com/mattn/goveralls'
|
|
||||||
gom 'github.com/axw/gocov/gocov'
|
|
||||||
gom 'golang.org/x/tools/cmd/cover'
|
|
||||||
end
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
Copyright 2013-2014 Andrey Smirnov. All rights reserved.
|
Copyright 2013-2015 aptly authors. All rights reserved.
|
||||||
|
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
|
|||||||
@@ -1,86 +1,81 @@
|
|||||||
GOVERSION=$(shell go version | awk '{print $$3;}')
|
GOVERSION=$(shell go version | awk '{print $$3;}')
|
||||||
PACKAGES=context database deb files http query swift s3 utils
|
ifdef TRAVIS_TAG
|
||||||
ALL_PACKAGES=api aptly context cmd console database deb files http query swift s3 utils
|
TAG=$(TRAVIS_TAG)
|
||||||
BINPATH=$(abspath ./_vendor/bin)
|
|
||||||
GOM_ENVIRONMENT=-test
|
|
||||||
PYTHON?=python
|
|
||||||
|
|
||||||
ifeq ($(GOVERSION), devel)
|
|
||||||
TRAVIS_TARGET=coveralls
|
|
||||||
GOM_ENVIRONMENT+=-development
|
|
||||||
else
|
else
|
||||||
TRAVIS_TARGET=test
|
TAG="$(shell git describe --tags --always)"
|
||||||
endif
|
endif
|
||||||
|
VERSION=$(shell echo $(TAG) | sed 's@^v@@' | sed 's@-@+@g')
|
||||||
|
PACKAGES=context database deb files gpg http query swift s3 utils
|
||||||
|
PYTHON?=python3
|
||||||
|
TESTS?=
|
||||||
|
BINPATH?=$(GOPATH)/bin
|
||||||
|
RUN_LONG_TESTS?=yes
|
||||||
|
|
||||||
ifeq ($(TRAVIS), true)
|
all: modules test bench check system-test
|
||||||
GOM=$(HOME)/gopath/bin/gom
|
|
||||||
else
|
|
||||||
GOM=gom
|
|
||||||
endif
|
|
||||||
|
|
||||||
all: test check system-test
|
|
||||||
|
|
||||||
prepare:
|
prepare:
|
||||||
go get -u github.com/mattn/gom
|
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.43.0
|
||||||
$(GOM) $(GOM_ENVIRONMENT) install
|
|
||||||
|
|
||||||
coverage.out:
|
modules:
|
||||||
rm -f coverage.*.out
|
go mod download
|
||||||
for i in $(PACKAGES); do $(GOM) test -coverprofile=coverage.$$i.out -covermode=count ./$$i; done
|
go mod verify
|
||||||
echo "mode: count" > coverage.out
|
go mod tidy -v
|
||||||
grep -v -h "mode: count" coverage.*.out >> coverage.out
|
|
||||||
rm -f coverage.*.out
|
|
||||||
|
|
||||||
coverage: coverage.out
|
dev:
|
||||||
$(GOM) exec go tool cover -html=coverage.out
|
go get -u github.com/laher/goxc
|
||||||
rm -f coverage.out
|
|
||||||
|
|
||||||
check:
|
check: system/env
|
||||||
$(GOM) exec go tool vet -all=true $(ALL_PACKAGES:%=./%)
|
ifeq ($(RUN_LONG_TESTS), yes)
|
||||||
$(GOM) exec golint $(ALL_PACKAGES:%=./%)
|
golangci-lint run
|
||||||
|
system/env/bin/flake8
|
||||||
|
endif
|
||||||
|
|
||||||
install:
|
install:
|
||||||
$(GOM) build -o $(BINPATH)/aptly
|
go install -v -ldflags "-X main.Version=$(VERSION)"
|
||||||
|
|
||||||
system-test: install
|
system/env: system/requirements.txt
|
||||||
|
ifeq ($(RUN_LONG_TESTS), yes)
|
||||||
|
rm -rf system/env
|
||||||
|
$(PYTHON) -m venv system/env
|
||||||
|
system/env/bin/pip install -r system/requirements.txt
|
||||||
|
endif
|
||||||
|
|
||||||
|
system-test: install system/env
|
||||||
|
ifeq ($(RUN_LONG_TESTS), yes)
|
||||||
if [ ! -e ~/aptly-fixture-db ]; then git clone https://github.com/aptly-dev/aptly-fixture-db.git ~/aptly-fixture-db/; fi
|
if [ ! -e ~/aptly-fixture-db ]; then git clone https://github.com/aptly-dev/aptly-fixture-db.git ~/aptly-fixture-db/; fi
|
||||||
if [ ! -e ~/aptly-fixture-pool ]; then git clone https://github.com/aptly-dev/aptly-fixture-pool.git ~/aptly-fixture-pool/; fi
|
if [ ! -e ~/aptly-fixture-pool ]; then git clone https://github.com/aptly-dev/aptly-fixture-pool.git ~/aptly-fixture-pool/; fi
|
||||||
PATH=$(BINPATH)/:$(PATH) $(PYTHON) system/run.py --long
|
PATH=$(BINPATH)/:$(PATH) && . system/env/bin/activate && APTLY_VERSION=$(VERSION) $(PYTHON) system/run.py --long $(TESTS)
|
||||||
|
endif
|
||||||
travis: $(TRAVIS_TARGET) system-test
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
$(GOM) test -v ./... -gocheck.v=true
|
go test -v ./... -gocheck.v=true -race -coverprofile=coverage.txt -covermode=atomic
|
||||||
|
|
||||||
coveralls: coverage.out
|
bench:
|
||||||
$(GOM) exec $(BINPATH)/goveralls -service travis-ci.org -coverprofile=coverage.out -repotoken=$(COVERALLS_TOKEN)
|
go test -v ./deb -run=nothing -bench=. -benchmem
|
||||||
|
|
||||||
mem.png: mem.dat mem.gp
|
mem.png: mem.dat mem.gp
|
||||||
gnuplot mem.gp
|
gnuplot mem.gp
|
||||||
open mem.png
|
open mem.png
|
||||||
|
|
||||||
package:
|
goxc: dev
|
||||||
rm -rf root/
|
rm -rf root/
|
||||||
mkdir -p root/usr/bin/ root/usr/share/man/man1/ root/etc/bash_completion.d
|
mkdir -p root/usr/share/man/man1/ root/etc/bash_completion.d/ root/usr/share/zsh/vendor-completions/
|
||||||
cp $(BINPATH)/aptly root/usr/bin
|
|
||||||
cp man/aptly.1 root/usr/share/man/man1
|
cp man/aptly.1 root/usr/share/man/man1
|
||||||
(cd root/etc/bash_completion.d && wget https://raw.github.com/aptly-dev/aptly-bash-completion/master/aptly)
|
cp completion.d/aptly root/etc/bash_completion.d/
|
||||||
|
cp completion.d/_aptly root/usr/share/zsh/vendor-completions/
|
||||||
gzip root/usr/share/man/man1/aptly.1
|
gzip root/usr/share/man/man1/aptly.1
|
||||||
fpm -s dir -t deb -n aptly -v $(VERSION) --url=http://www.aptly.info/ --license=MIT --vendor="Andrey Smirnov <me@smira.ru>" \
|
goxc -pv=$(VERSION) -max-processors=2 $(GOXC_OPTS)
|
||||||
-f -m "Andrey Smirnov <me@smira.ru>" --description="Debian repository management tool" --deb-recommends bzip2 --deb-recommends graphviz -C root/ .
|
|
||||||
mv aptly_$(VERSION)_*.deb ~
|
|
||||||
|
|
||||||
src-package:
|
release: GOXC_OPTS=-tasks-=bintray,go-vet,go-test,rmbin
|
||||||
rm -rf aptly-$(VERSION)
|
release: goxc
|
||||||
mkdir -p aptly-$(VERSION)/src/github.com/smira/aptly/
|
rm -rf build/
|
||||||
cd aptly-$(VERSION)/src/github.com/smira/ && git clone https://github.com/smira/aptly && cd aptly && git checkout v$(VERSION)
|
mkdir -p build/
|
||||||
cd aptly-$(VERSION)/src/github.com/smira/aptly && gom -production install
|
mv xc-out/$(VERSION)/aptly_$(VERSION)_* build/
|
||||||
cd aptly-$(VERSION)/src/github.com/smira/aptly && find . \( -name .git -o -name .bzr -o -name .hg \) -print | xargs rm -rf
|
|
||||||
rm -rf aptly-$(VERSION)/src/github.com/smira/aptly/_vendor/{pkg,bin}
|
|
||||||
mkdir -p aptly-$(VERSION)/bash_completion.d
|
|
||||||
(cd aptly-$(VERSION)/bash_completion.d && wget https://raw.github.com/aptly-dev/aptly-bash-completion/$(VERSION)/aptly)
|
|
||||||
tar cyf aptly-$(VERSION)-src.tar.bz2 aptly-$(VERSION)
|
|
||||||
rm -rf aptly-$(VERSION)
|
|
||||||
curl -T aptly-$(VERSION)-src.tar.bz2 -usmira:$(BINTRAY_KEY) https://api.bintray.com/content/smira/aptly/aptly/$(VERSION)/$(VERSION)/aptly-$(VERSION)-src.tar.bz2
|
|
||||||
|
|
||||||
.PHONY: coverage.out
|
man:
|
||||||
|
make -C man
|
||||||
|
|
||||||
|
version:
|
||||||
|
@echo $(VERSION)
|
||||||
|
|
||||||
|
.PHONY: man modules version release goxc
|
||||||
|
|||||||
+57
-21
@@ -2,24 +2,24 @@
|
|||||||
aptly
|
aptly
|
||||||
=====
|
=====
|
||||||
|
|
||||||
.. image:: https://travis-ci.org/smira/aptly.png?branch=master
|
.. image:: https://github.com/aptly-dev/aptly/actions/workflows/ci.yml/badge.svg
|
||||||
:target: https://travis-ci.org/smira/aptly
|
:target: https://github.com/aptly-dev/aptly/actions
|
||||||
|
|
||||||
.. image:: https://coveralls.io/repos/smira/aptly/badge.png?branch=HEAD
|
.. image:: https://codecov.io/gh/aptly-dev/aptly/branch/master/graph/badge.svg
|
||||||
:target: https://coveralls.io/r/smira/aptly?branch=HEAD
|
:target: https://codecov.io/gh/aptly-dev/aptly
|
||||||
|
|
||||||
.. image:: https://badges.gitter.im/Join Chat.svg
|
.. image:: https://badges.gitter.im/Join Chat.svg
|
||||||
:target: https://gitter.im/smira/aptly?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
:target: https://gitter.im/aptly-dev/aptly?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
||||||
|
|
||||||
.. image:: http://goreportcard.com/badge/gojp/goreportcard
|
.. image:: https://goreportcard.com/badge/github.com/aptly-dev/aptly
|
||||||
:target: http://goreportcard.com/report/gojp/goreportcard
|
:target: https://goreportcard.com/report/aptly-dev/aptly
|
||||||
|
|
||||||
Aptly is a swiss army knife for Debian repository management.
|
Aptly is a swiss army knife for Debian repository management.
|
||||||
|
|
||||||
.. image:: http://www.aptly.info/img/aptly_logo.png
|
.. image:: http://www.aptly.info/img/aptly_logo.png
|
||||||
:target: http://www.aptly.info/
|
:target: http://www.aptly.info/
|
||||||
|
|
||||||
Documentation is available at `http://www.aptly.info/ <http://www.aptly.info/>`_. For support use
|
Documentation is available at `http://www.aptly.info/ <http://www.aptly.info/>`_. For support please use
|
||||||
mailing list `aptly-discuss <https://groups.google.com/forum/#!forum/aptly-discuss>`_.
|
mailing list `aptly-discuss <https://groups.google.com/forum/#!forum/aptly-discuss>`_.
|
||||||
|
|
||||||
Aptly features: ("+" means planned features)
|
Aptly features: ("+" means planned features)
|
||||||
@@ -42,13 +42,13 @@ Current limitations:
|
|||||||
Download
|
Download
|
||||||
--------
|
--------
|
||||||
|
|
||||||
To install aptly on Debian/Ubuntu, add new repository to /etc/apt/sources.list::
|
To install aptly on Debian/Ubuntu, add new repository to ``/etc/apt/sources.list``::
|
||||||
|
|
||||||
deb http://repo.aptly.info/ squeeze main
|
deb http://repo.aptly.info/ squeeze main
|
||||||
|
|
||||||
And import key that is used to sign the release::
|
And import key that is used to sign the release::
|
||||||
|
|
||||||
$ apt-key adv --keyserver keys.gnupg.net --recv-keys E083A3782A194991
|
$ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EE727D4449467F0E
|
||||||
|
|
||||||
After that you can install aptly as any other software package::
|
After that you can install aptly as any other software package::
|
||||||
|
|
||||||
@@ -62,20 +62,56 @@ If you would like to use nightly builds (unstable), please use following reposit
|
|||||||
|
|
||||||
deb http://repo.aptly.info/ nightly main
|
deb http://repo.aptly.info/ nightly main
|
||||||
|
|
||||||
Binary executables (depends almost only on libc) are available for download from `Bintray <http://dl.bintray.com/smira/aptly/>`_.
|
Binary executables (depends almost only on libc) are available for download from `GitHub Releases <https://github.com/aptly-dev/aptly/releases>`_.
|
||||||
|
|
||||||
If you have Go environment set up, you can build aptly from source by running (go 1.3+ required)::
|
If you have Go environment set up, you can build aptly from source by running (go 1.14+ required)::
|
||||||
|
|
||||||
go get -u github.com/mattn/gom
|
git clone https://github.com/aptly-dev/aptly
|
||||||
mkdir -p $GOPATH/src/github.com/smira/aptly
|
cd aptly
|
||||||
git clone https://github.com/smira/aptly $GOPATH/src/github.com/smira/aptly
|
make modules install
|
||||||
cd $GOPATH/src/github.com/smira/aptly
|
|
||||||
gom -production install
|
|
||||||
gom build -o $GOPATH/bin/aptly
|
|
||||||
|
|
||||||
Aptly is using `gom <https://github.com/mattn/gom>`_ to fix external dependencies, so regular ``go get github.com/smira/aptly``
|
Binary would be installed to ``$GOPATH/bin/aptly``.
|
||||||
should work as well, but might fail or produce different result (if external libraries got updated).
|
|
||||||
|
|
||||||
If you don't have Go installed (or older version), you can easily install Go using `gvm <https://github.com/moovweb/gvm/>`_.
|
Contributing
|
||||||
|
------------
|
||||||
|
|
||||||
|
Please follow detailed documentation in `CONTRIBUTING.md <CONTRIBUTING.md>`_.
|
||||||
|
|
||||||
|
Integrations
|
||||||
|
------------
|
||||||
|
|
||||||
|
Vagrant:
|
||||||
|
|
||||||
|
- `Vagrant configuration <https://github.com/sepulworld/aptly-vagrant>`_ by
|
||||||
|
Zane Williamson, allowing to bring two virtual servers, one with aptly installed
|
||||||
|
and another one set up to install packages from repository published by aptly
|
||||||
|
|
||||||
|
Docker:
|
||||||
|
|
||||||
|
- `Docker container <https://github.com/mikepurvis/aptly-docker>`_ with aptly inside by Mike Purvis
|
||||||
|
- `Docker container <https://github.com/urpylka/docker-aptly>`_ with aptly and nginx by Artem Smirnov
|
||||||
|
|
||||||
|
With configuration management systems:
|
||||||
|
|
||||||
|
- `Chef cookbook <https://github.com/hw-cookbooks/aptly>`_ by Aaron Baer
|
||||||
|
(Heavy Water Operations, LLC)
|
||||||
|
- `Puppet module <https://github.com/alphagov/puppet-aptly>`_ by
|
||||||
|
Government Digital Services
|
||||||
|
- `Puppet module <https://github.com/tubemogul/puppet-aptly>`_ by
|
||||||
|
TubeMogul
|
||||||
|
- `SaltStack Formula <https://github.com/saltstack-formulas/aptly-formula>`_ by
|
||||||
|
Forrest Alvarez and Brian Jackson
|
||||||
|
- `Ansible role <https://github.com/aioue/ansible-role-aptly>`_ by Tom Paine
|
||||||
|
|
||||||
|
CLI for aptly API:
|
||||||
|
|
||||||
|
- `Ruby aptly CLI/library <https://github.com/sepulworld/aptly_cli>`_ by Zane Williamson
|
||||||
|
- `Python aptly CLI (good for CI) <https://github.com/TimSusa/aptly_api_cli>`_ by Tim Susa
|
||||||
|
|
||||||
|
GUI for aptly API:
|
||||||
|
|
||||||
|
- `Python aptly GUI (via pyqt5) <https://github.com/chnyda/python-aptly-gui>`_ by Cedric Hnyda
|
||||||
|
|
||||||
|
Scala sbt:
|
||||||
|
|
||||||
|
- `sbt aptly plugin <https://github.com/amalakar/sbt-aptly>`_ by Arup Malakar
|
||||||
|
|||||||
@@ -2,16 +2,17 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/cmd"
|
"io/ioutil"
|
||||||
"github.com/smira/commander"
|
|
||||||
"github.com/smira/flag"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/cmd"
|
||||||
|
"github.com/smira/commander"
|
||||||
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
func allFlags(flags *flag.FlagSet) []*flag.Flag {
|
func allFlags(flags *flag.FlagSet) []*flag.Flag {
|
||||||
@@ -43,22 +44,42 @@ func capitalize(s string) string {
|
|||||||
return strings.Join(parts, " ")
|
return strings.Join(parts, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var authorsS string
|
||||||
|
|
||||||
|
func authors() string {
|
||||||
|
return authorsS
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
command := cmd.RootCommand()
|
command := cmd.RootCommand()
|
||||||
command.UsageLine = "aptly"
|
command.UsageLine = "aptly"
|
||||||
command.Dispatch(nil)
|
command.Dispatch(nil)
|
||||||
|
|
||||||
_, _File, _, _ := runtime.Caller(0)
|
_File, _ := filepath.Abs("./man")
|
||||||
_File, _ = filepath.Abs(_File)
|
|
||||||
|
|
||||||
templ := template.New("man").Funcs(template.FuncMap{
|
templ := template.New("man").Funcs(template.FuncMap{
|
||||||
"allFlags": allFlags,
|
"allFlags": allFlags,
|
||||||
"findCommand": findCommand,
|
"findCommand": findCommand,
|
||||||
"toUpper": strings.ToUpper,
|
"toUpper": strings.ToUpper,
|
||||||
"capitalize": capitalize,
|
"capitalize": capitalize,
|
||||||
|
"authors": authors,
|
||||||
})
|
})
|
||||||
template.Must(templ.ParseFiles(filepath.Join(filepath.Dir(_File), "aptly.1.ronn.tmpl")))
|
template.Must(templ.ParseFiles(filepath.Join(filepath.Dir(_File), "aptly.1.ronn.tmpl")))
|
||||||
|
|
||||||
|
authorsF, err := os.Open(filepath.Join(filepath.Dir(_File), "..", "AUTHORS"))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
authorsB, err := ioutil.ReadAll(authorsF)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
authorsF.Close()
|
||||||
|
|
||||||
|
authorsS = string(authorsB)
|
||||||
|
|
||||||
output, err := os.Create(filepath.Join(filepath.Dir(_File), "aptly.1.ronn"))
|
output, err := os.Create(filepath.Join(filepath.Dir(_File), "aptly.1.ronn"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
+141
-33
@@ -3,12 +3,17 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"log"
|
||||||
"github.com/smira/aptly/aptly"
|
"net/http"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"github.com/smira/aptly/query"
|
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/query"
|
||||||
|
"github.com/aptly-dev/aptly/task"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Lock order acquisition (canonical):
|
// Lock order acquisition (canonical):
|
||||||
@@ -22,46 +27,148 @@ func apiVersion(c *gin.Context) {
|
|||||||
c.JSON(200, gin.H{"Version": aptly.Version})
|
c.JSON(200, gin.H{"Version": aptly.Version})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Periodically flushes CollectionFactory to free up memory used by collections,
|
type dbRequestKind int
|
||||||
// flushing caches.
|
|
||||||
|
const (
|
||||||
|
acquiredb dbRequestKind = iota
|
||||||
|
releasedb
|
||||||
|
)
|
||||||
|
|
||||||
|
type dbRequest struct {
|
||||||
|
kind dbRequestKind
|
||||||
|
err chan<- error
|
||||||
|
}
|
||||||
|
|
||||||
|
var dbRequests chan dbRequest
|
||||||
|
|
||||||
|
// Acquire database lock and release it when not needed anymore.
|
||||||
//
|
//
|
||||||
// Should be run in goroutine!
|
// Should be run in a goroutine!
|
||||||
func cacheFlusher() {
|
func acquireDatabase() {
|
||||||
ticker := time.Tick(15 * time.Minute)
|
clients := 0
|
||||||
|
for request := range dbRequests {
|
||||||
|
var err error
|
||||||
|
|
||||||
for {
|
switch request.kind {
|
||||||
<-ticker
|
case acquiredb:
|
||||||
|
if clients == 0 {
|
||||||
|
err = context.ReOpenDatabase()
|
||||||
|
}
|
||||||
|
|
||||||
// lock everything to eliminate in-progress calls
|
request.err <- err
|
||||||
r := context.CollectionFactory().RemoteRepoCollection()
|
|
||||||
r.Lock()
|
|
||||||
defer r.Unlock()
|
|
||||||
|
|
||||||
l := context.CollectionFactory().LocalRepoCollection()
|
if err == nil {
|
||||||
l.Lock()
|
clients++
|
||||||
defer l.Unlock()
|
}
|
||||||
|
case releasedb:
|
||||||
|
clients--
|
||||||
|
if clients == 0 {
|
||||||
|
err = context.CloseDatabase()
|
||||||
|
} else {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
|
|
||||||
s := context.CollectionFactory().SnapshotCollection()
|
request.err <- err
|
||||||
s.Lock()
|
}
|
||||||
defer s.Unlock()
|
}
|
||||||
|
}
|
||||||
|
|
||||||
p := context.CollectionFactory().PublishedRepoCollection()
|
// Should be called before database access is needed in any api call.
|
||||||
p.Lock()
|
// Happens per default for each api call. It is important that you run
|
||||||
defer p.Unlock()
|
// runTaskInBackground to run a task which accquire database.
|
||||||
|
// Important do not forget to defer to releaseDatabaseConnection
|
||||||
|
func acquireDatabaseConnection() error {
|
||||||
|
if dbRequests == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// all collections locked, flush them
|
errCh := make(chan error)
|
||||||
context.CollectionFactory().Flush()
|
dbRequests <- dbRequest{acquiredb, errCh}
|
||||||
|
|
||||||
|
return <-errCh
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release database connection when not needed anymore
|
||||||
|
func releaseDatabaseConnection() error {
|
||||||
|
if dbRequests == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
errCh := make(chan error)
|
||||||
|
dbRequests <- dbRequest{releasedb, errCh}
|
||||||
|
return <-errCh
|
||||||
|
}
|
||||||
|
|
||||||
|
// runs tasks in background. Acquires database connection first.
|
||||||
|
func runTaskInBackground(name string, resources []string, proc task.Process) (task.Task, *task.ResourceConflictError) {
|
||||||
|
return context.TaskList().RunTaskInBackground(name, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
|
err := acquireDatabaseConnection()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer releaseDatabaseConnection()
|
||||||
|
return proc(out, detail)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func truthy(value interface{}) bool {
|
||||||
|
if value == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
switch value.(type) {
|
||||||
|
case string:
|
||||||
|
switch strings.ToLower(value.(string)) {
|
||||||
|
case "n", "no", "f", "false", "0", "off":
|
||||||
|
return false
|
||||||
|
default:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
case int:
|
||||||
|
return !(value.(int) == 0)
|
||||||
|
case bool:
|
||||||
|
return value.(bool)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func maybeRunTaskInBackground(c *gin.Context, name string, resources []string, proc task.Process) {
|
||||||
|
// Run this task in background if configured globally or per-request
|
||||||
|
background := truthy(c.DefaultQuery("_async", strconv.FormatBool(context.Config().AsyncAPI)))
|
||||||
|
if background {
|
||||||
|
log.Println("Executing task asynchronously")
|
||||||
|
task, conflictErr := runTaskInBackground(name, resources, proc)
|
||||||
|
if conflictErr != nil {
|
||||||
|
c.AbortWithError(409, conflictErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(202, task)
|
||||||
|
} else {
|
||||||
|
log.Println("Executing task synchronously")
|
||||||
|
out := context.Progress()
|
||||||
|
detail := task.Detail{}
|
||||||
|
retValue, err := proc(out, &detail)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(retValue.Code, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if retValue != nil {
|
||||||
|
c.JSON(retValue.Code, retValue.Value)
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Common piece of code to show list of packages,
|
// Common piece of code to show list of packages,
|
||||||
// with searching & details if requested
|
// with searching & details if requested
|
||||||
func showPackages(c *gin.Context, reflist *deb.PackageRefList) {
|
func showPackages(c *gin.Context, reflist *deb.PackageRefList, collectionFactory *deb.CollectionFactory) {
|
||||||
result := []*deb.Package{}
|
result := []*deb.Package{}
|
||||||
|
|
||||||
list, err := deb.NewPackageListFromRefList(reflist, context.CollectionFactory().PackageCollection(), nil)
|
list, err := deb.NewPackageListFromRefList(reflist, collectionFactory.PackageCollection(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +176,7 @@ func showPackages(c *gin.Context, reflist *deb.PackageRefList) {
|
|||||||
if queryS != "" {
|
if queryS != "" {
|
||||||
q, err := query.Parse(c.Request.URL.Query().Get("q"))
|
q, err := query.Parse(c.Request.URL.Query().Get("q"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(400, err)
|
c.AbortWithError(400, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +193,7 @@ func showPackages(c *gin.Context, reflist *deb.PackageRefList) {
|
|||||||
sort.Strings(architecturesList)
|
sort.Strings(architecturesList)
|
||||||
|
|
||||||
if len(architecturesList) == 0 {
|
if len(architecturesList) == 0 {
|
||||||
c.Fail(400, fmt.Errorf("unable to determine list of architectures, please specify explicitly"))
|
c.AbortWithError(400, fmt.Errorf("unable to determine list of architectures, please specify explicitly"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,7 +203,8 @@ func showPackages(c *gin.Context, reflist *deb.PackageRefList) {
|
|||||||
list, err = list.Filter([]deb.PackageQuery{q}, withDeps,
|
list, err = list.Filter([]deb.PackageQuery{q}, withDeps,
|
||||||
nil, context.DependencyOptions(), architecturesList)
|
nil, context.DependencyOptions(), architecturesList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to search: %s", err))
|
c.AbortWithError(500, fmt.Errorf("unable to search: %s", err))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+117
@@ -0,0 +1,117 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
ctx "github.com/aptly-dev/aptly/context"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/smira/flag"
|
||||||
|
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test(t *testing.T) {
|
||||||
|
TestingT(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
type ApiSuite struct {
|
||||||
|
context *ctx.AptlyContext
|
||||||
|
flags *flag.FlagSet
|
||||||
|
configFile *os.File
|
||||||
|
router http.Handler
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = Suite(&ApiSuite{})
|
||||||
|
|
||||||
|
func createTestConfig() *os.File {
|
||||||
|
file, err := ioutil.TempFile("", "aptly")
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
jsonString, err := json.Marshal(gin.H{
|
||||||
|
"architectures": []string{},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
file.Write(jsonString)
|
||||||
|
return file
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiSuite) SetUpSuite(c *C) {
|
||||||
|
file := createTestConfig()
|
||||||
|
c.Assert(file, NotNil)
|
||||||
|
s.configFile = file
|
||||||
|
|
||||||
|
flags := flag.NewFlagSet("fakeFlags", flag.ContinueOnError)
|
||||||
|
flags.Bool("no-lock", false, "dummy")
|
||||||
|
flags.Int("db-open-attempts", 3, "dummy")
|
||||||
|
flags.String("config", s.configFile.Name(), "dummy")
|
||||||
|
flags.String("architectures", "", "dummy")
|
||||||
|
s.flags = flags
|
||||||
|
|
||||||
|
context, err := ctx.NewContext(s.flags)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
s.context = context
|
||||||
|
s.router = Router(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiSuite) TearDownSuite(c *C) {
|
||||||
|
os.Remove(s.configFile.Name())
|
||||||
|
s.context.Shutdown()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiSuite) SetUpTest(c *C) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiSuite) TearDownTest(c *C) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiSuite) HTTPRequest(method string, url string, body io.Reader) (*httptest.ResponseRecorder, error) {
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
req, err := http.NewRequest(method, url, body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req.Header.Add("Content-Type", "application/json")
|
||||||
|
s.router.ServeHTTP(w, req)
|
||||||
|
return w, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiSuite) TestGetVersion(c *C) {
|
||||||
|
response, err := s.HTTPRequest("GET", "/api/version", nil)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Check(response.Code, Equals, 200)
|
||||||
|
c.Check(response.Body.String(), Matches, ".*Version.*")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiSuite) TestTruthy(c *C) {
|
||||||
|
c.Check(truthy("no"), Equals, false)
|
||||||
|
c.Check(truthy("n"), Equals, false)
|
||||||
|
c.Check(truthy("off"), Equals, false)
|
||||||
|
c.Check(truthy("false"), Equals, false)
|
||||||
|
c.Check(truthy("0"), Equals, false)
|
||||||
|
c.Check(truthy(false), Equals, false)
|
||||||
|
c.Check(truthy(0), Equals, false)
|
||||||
|
|
||||||
|
c.Check(truthy("y"), Equals, true)
|
||||||
|
c.Check(truthy("yes"), Equals, true)
|
||||||
|
c.Check(truthy("t"), Equals, true)
|
||||||
|
c.Check(truthy("true"), Equals, true)
|
||||||
|
c.Check(truthy("1"), Equals, true)
|
||||||
|
c.Check(truthy(true), Equals, true)
|
||||||
|
c.Check(truthy(1), Equals, true)
|
||||||
|
|
||||||
|
c.Check(truthy(nil), Equals, false)
|
||||||
|
|
||||||
|
c.Check(truthy("foobar"), Equals, true)
|
||||||
|
c.Check(truthy(-1), Equals, true)
|
||||||
|
c.Check(truthy(gin.H{}), Equals, true)
|
||||||
|
}
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/task"
|
||||||
|
"github.com/aptly-dev/aptly/utils"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// POST /api/db/cleanup
|
||||||
|
func apiDbCleanup(c *gin.Context) {
|
||||||
|
|
||||||
|
resources := []string{string(task.AllResourcesKey)}
|
||||||
|
maybeRunTaskInBackground(c, "Clean up db", resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
|
||||||
|
// collect information about referenced packages...
|
||||||
|
existingPackageRefs := deb.NewPackageRefList()
|
||||||
|
|
||||||
|
out.Printf("Loading mirrors, local repos, snapshots and published repos...")
|
||||||
|
err = collectionFactory.RemoteRepoCollection().ForEach(func(repo *deb.RemoteRepo) error {
|
||||||
|
e := collectionFactory.RemoteRepoCollection().LoadComplete(repo)
|
||||||
|
if e != nil {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
if repo.RefList() != nil {
|
||||||
|
existingPackageRefs = existingPackageRefs.Merge(repo.RefList(), false, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = collectionFactory.LocalRepoCollection().ForEach(func(repo *deb.LocalRepo) error {
|
||||||
|
e := collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||||
|
if e != nil {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
if repo.RefList() != nil {
|
||||||
|
existingPackageRefs = existingPackageRefs.Merge(repo.RefList(), false, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = collectionFactory.SnapshotCollection().ForEach(func(snapshot *deb.Snapshot) error {
|
||||||
|
e := collectionFactory.SnapshotCollection().LoadComplete(snapshot)
|
||||||
|
if e != nil {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
existingPackageRefs = existingPackageRefs.Merge(snapshot.RefList(), false, true)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = collectionFactory.PublishedRepoCollection().ForEach(func(published *deb.PublishedRepo) error {
|
||||||
|
if published.SourceKind != deb.SourceLocalRepo {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
e := collectionFactory.PublishedRepoCollection().LoadComplete(published, collectionFactory)
|
||||||
|
if e != nil {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, component := range published.Components() {
|
||||||
|
existingPackageRefs = existingPackageRefs.Merge(published.RefList(component), false, true)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ... and compare it to the list of all packages
|
||||||
|
out.Printf("Loading list of all packages...")
|
||||||
|
allPackageRefs := collectionFactory.PackageCollection().AllPackageRefs()
|
||||||
|
|
||||||
|
toDelete := allPackageRefs.Subtract(existingPackageRefs)
|
||||||
|
|
||||||
|
// delete packages that are no longer referenced
|
||||||
|
out.Printf("Deleting unreferenced packages (%d)...", toDelete.Len())
|
||||||
|
|
||||||
|
// database can't err as collection factory already constructed
|
||||||
|
db, _ := context.Database()
|
||||||
|
|
||||||
|
if toDelete.Len() > 0 {
|
||||||
|
batch := db.CreateBatch()
|
||||||
|
toDelete.ForEach(func(ref []byte) error {
|
||||||
|
collectionFactory.PackageCollection().DeleteByKey(ref, batch)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
err = batch.Write()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to write to DB: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// now, build a list of files that should be present in Repository (package pool)
|
||||||
|
out.Printf("Building list of files referenced by packages...")
|
||||||
|
referencedFiles := make([]string, 0, existingPackageRefs.Len())
|
||||||
|
|
||||||
|
err = existingPackageRefs.ForEach(func(key []byte) error {
|
||||||
|
pkg, err2 := collectionFactory.PackageCollection().ByKey(key)
|
||||||
|
if err2 != nil {
|
||||||
|
tail := ""
|
||||||
|
return fmt.Errorf("unable to load package %s: %s%s", string(key), err2, tail)
|
||||||
|
}
|
||||||
|
paths, err2 := pkg.FilepathList(context.PackagePool())
|
||||||
|
if err2 != nil {
|
||||||
|
return err2
|
||||||
|
}
|
||||||
|
referencedFiles = append(referencedFiles, paths...)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(referencedFiles)
|
||||||
|
|
||||||
|
// build a list of files in the package pool
|
||||||
|
out.Printf("Building list of files in package pool...")
|
||||||
|
existingFiles, err := context.PackagePool().FilepathList(out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to collect file paths: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// find files which are in the pool but not referenced by packages
|
||||||
|
filesToDelete := utils.StrSlicesSubstract(existingFiles, referencedFiles)
|
||||||
|
|
||||||
|
// delete files that are no longer referenced
|
||||||
|
out.Printf("Deleting unreferenced files (%d)...", len(filesToDelete))
|
||||||
|
|
||||||
|
countFilesToDelete := len(filesToDelete)
|
||||||
|
taskDetail := struct {
|
||||||
|
TotalNumberOfPackagesToDelete int
|
||||||
|
RemainingNumberOfPackagesToDelete int
|
||||||
|
}{
|
||||||
|
countFilesToDelete, countFilesToDelete,
|
||||||
|
}
|
||||||
|
detail.Store(taskDetail)
|
||||||
|
|
||||||
|
if countFilesToDelete > 0 {
|
||||||
|
var size, totalSize int64
|
||||||
|
for _, file := range filesToDelete {
|
||||||
|
size, err = context.PackagePool().Remove(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
taskDetail.RemainingNumberOfPackagesToDelete--
|
||||||
|
detail.Store(taskDetail)
|
||||||
|
totalSize += size
|
||||||
|
}
|
||||||
|
|
||||||
|
out.Printf("Disk space freed: %s...", utils.HumanBytes(totalSize))
|
||||||
|
}
|
||||||
|
|
||||||
|
out.Printf("Compacting database...")
|
||||||
|
return nil, db.CompactDB()
|
||||||
|
})
|
||||||
|
}
|
||||||
+14
-13
@@ -2,11 +2,12 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func verifyPath(path string) bool {
|
func verifyPath(path string) bool {
|
||||||
@@ -23,7 +24,7 @@ func verifyPath(path string) bool {
|
|||||||
|
|
||||||
func verifyDir(c *gin.Context) bool {
|
func verifyDir(c *gin.Context) bool {
|
||||||
if !verifyPath(c.Params.ByName("dir")) {
|
if !verifyPath(c.Params.ByName("dir")) {
|
||||||
c.Fail(400, fmt.Errorf("wrong dir"))
|
c.AbortWithError(400, fmt.Errorf("wrong dir"))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ func apiFilesListDirs(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
c.Fail(400, err)
|
c.AbortWithError(400, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,13 +70,13 @@ func apiFilesUpload(c *gin.Context) {
|
|||||||
err := os.MkdirAll(path, 0777)
|
err := os.MkdirAll(path, 0777)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.Request.ParseMultipartForm(10 * 1024 * 1024)
|
err = c.Request.ParseMultipartForm(10 * 1024 * 1024)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(400, err)
|
c.AbortWithError(400, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +86,7 @@ func apiFilesUpload(c *gin.Context) {
|
|||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
src, err := file.Open()
|
src, err := file.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer src.Close()
|
defer src.Close()
|
||||||
@@ -93,14 +94,14 @@ func apiFilesUpload(c *gin.Context) {
|
|||||||
destPath := filepath.Join(path, filepath.Base(file.Filename))
|
destPath := filepath.Join(path, filepath.Base(file.Filename))
|
||||||
dst, err := os.Create(destPath)
|
dst, err := os.Create(destPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer dst.Close()
|
defer dst.Close()
|
||||||
|
|
||||||
_, err = io.Copy(dst, src)
|
_, err = io.Copy(dst, src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,9 +138,9 @@ func apiFilesListFiles(c *gin.Context) {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
} else {
|
} else {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -155,7 +156,7 @@ func apiFilesDeleteDir(c *gin.Context) {
|
|||||||
|
|
||||||
err := os.RemoveAll(filepath.Join(context.UploadPath(), c.Params.ByName("dir")))
|
err := os.RemoveAll(filepath.Join(context.UploadPath(), c.Params.ByName("dir")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,14 +170,14 @@ func apiFilesDeleteFile(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !verifyPath(c.Params.ByName("name")) {
|
if !verifyPath(c.Params.ByName("name")) {
|
||||||
c.Fail(400, fmt.Errorf("wrong file"))
|
c.AbortWithError(400, fmt.Errorf("wrong file"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := os.Remove(filepath.Join(context.UploadPath(), c.Params.ByName("dir"), c.Params.ByName("name")))
|
err := os.Remove(filepath.Join(context.UploadPath(), c.Params.ByName("dir"), c.Params.ByName("name")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err1, ok := err.(*os.PathError); !ok || !os.IsNotExist(err1.Err) {
|
if err1, ok := err.(*os.PathError); !ok || !os.IsNotExist(err1.Err) {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+84
@@ -0,0 +1,84 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/pgp"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// POST /api/gpg
|
||||||
|
func apiGPGAddKey(c *gin.Context) {
|
||||||
|
var b struct {
|
||||||
|
Keyserver string
|
||||||
|
GpgKeyID string
|
||||||
|
GpgKeyArmor string
|
||||||
|
Keyring string
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Bind(&b) != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
args := []string{"--no-default-keyring"}
|
||||||
|
keyring := "trustedkeys.gpg"
|
||||||
|
if len(b.Keyring) > 0 {
|
||||||
|
keyring = b.Keyring
|
||||||
|
}
|
||||||
|
args = append(args, "--keyring", keyring)
|
||||||
|
if len(b.Keyserver) > 0 {
|
||||||
|
args = append(args, "--keyserver", b.Keyserver)
|
||||||
|
}
|
||||||
|
if len(b.GpgKeyArmor) > 0 {
|
||||||
|
var tempdir string
|
||||||
|
tempdir, err = ioutil.TempDir(os.TempDir(), "aptly")
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(400, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tempdir)
|
||||||
|
|
||||||
|
keypath := filepath.Join(tempdir, "key")
|
||||||
|
keyfile, e := os.Create(keypath)
|
||||||
|
if e != nil {
|
||||||
|
c.AbortWithError(400, e)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, e = keyfile.WriteString(b.GpgKeyArmor); e != nil {
|
||||||
|
c.AbortWithError(400, e)
|
||||||
|
}
|
||||||
|
args = append(args, "--import", keypath)
|
||||||
|
|
||||||
|
}
|
||||||
|
if len(b.GpgKeyID) > 0 {
|
||||||
|
keys := strings.Fields(b.GpgKeyID)
|
||||||
|
args = append(args, "--recv-keys")
|
||||||
|
args = append(args, keys...)
|
||||||
|
}
|
||||||
|
|
||||||
|
finder := pgp.GPG1Finder()
|
||||||
|
gpg, _, err := finder.FindGPG()
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(400, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// it might happened that we have a situation with an erroneous
|
||||||
|
// gpg command (e.g. when GpgKeyID and GpgKeyArmor is set).
|
||||||
|
// there is no error handling for such as gpg will do this for us
|
||||||
|
cmd := exec.Command(gpg, args...)
|
||||||
|
fmt.Printf("running %s %s\n", gpg, strings.Join(args, " "))
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
if err = cmd.Run(); err != nil {
|
||||||
|
c.AbortWithError(400, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(200, gin.H{})
|
||||||
|
}
|
||||||
+18
-19
@@ -3,15 +3,16 @@ package api
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"io"
|
"io"
|
||||||
"mime"
|
"mime"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GET /api/graph.:ext
|
// GET /api/graph.:ext?layout=[vertical|horizontal(default)]
|
||||||
func apiGraph(c *gin.Context) {
|
func apiGraph(c *gin.Context) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
@@ -19,19 +20,10 @@ func apiGraph(c *gin.Context) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
ext := c.Params.ByName("ext")
|
ext := c.Params.ByName("ext")
|
||||||
|
layout := c.Request.URL.Query().Get("layout")
|
||||||
|
factory := context.NewCollectionFactory()
|
||||||
|
|
||||||
factory := context.CollectionFactory()
|
graph, err := deb.BuildGraph(factory, layout)
|
||||||
|
|
||||||
factory.RemoteRepoCollection().RLock()
|
|
||||||
defer factory.RemoteRepoCollection().RUnlock()
|
|
||||||
factory.LocalRepoCollection().RLock()
|
|
||||||
defer factory.LocalRepoCollection().RUnlock()
|
|
||||||
factory.SnapshotCollection().RLock()
|
|
||||||
defer factory.SnapshotCollection().RUnlock()
|
|
||||||
factory.PublishedRepoCollection().RLock()
|
|
||||||
defer factory.PublishedRepoCollection().RUnlock()
|
|
||||||
|
|
||||||
graph, err := deb.BuildGraph(factory)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(500, err)
|
c.JSON(500, err)
|
||||||
return
|
return
|
||||||
@@ -39,30 +31,37 @@ func apiGraph(c *gin.Context) {
|
|||||||
|
|
||||||
buf := bytes.NewBufferString(graph.String())
|
buf := bytes.NewBufferString(graph.String())
|
||||||
|
|
||||||
|
if ext == "dot" || ext == "gv" {
|
||||||
|
// If the raw dot data is requested, return it as string.
|
||||||
|
// This allows client-side rendering rather than server-side.
|
||||||
|
c.String(200, buf.String())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
command := exec.Command("dot", "-T"+ext)
|
command := exec.Command("dot", "-T"+ext)
|
||||||
command.Stderr = os.Stderr
|
command.Stderr = os.Stderr
|
||||||
|
|
||||||
stdin, err := command.StdinPipe()
|
stdin, err := command.StdinPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = io.Copy(stdin, buf)
|
_, err = io.Copy(stdin, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = stdin.Close()
|
err = stdin.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err = command.Output()
|
output, err = command.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to execute dot: %s (is graphviz package installed?)", err))
|
c.AbortWithError(500, fmt.Errorf("unable to execute dot: %s (is graphviz package installed?)", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
apiRequestsInFlightGauge = promauto.NewGaugeVec(
|
||||||
|
prometheus.GaugeOpts{
|
||||||
|
Name: "aptly_api_http_requests_in_flight",
|
||||||
|
Help: "Number of concurrent HTTP api requests currently handled.",
|
||||||
|
},
|
||||||
|
[]string{"method", "path"},
|
||||||
|
)
|
||||||
|
apiRequestsTotalCounter = promauto.NewCounterVec(
|
||||||
|
prometheus.CounterOpts{
|
||||||
|
Name: "aptly_api_http_requests_total",
|
||||||
|
Help: "Total number of api requests.",
|
||||||
|
},
|
||||||
|
[]string{"code", "method", "path"},
|
||||||
|
)
|
||||||
|
apiRequestSizeSummary = promauto.NewSummaryVec(
|
||||||
|
prometheus.SummaryOpts{
|
||||||
|
Name: "aptly_api_http_request_size_bytes",
|
||||||
|
Help: "Api HTTP request size in bytes.",
|
||||||
|
},
|
||||||
|
[]string{"code", "method", "path"},
|
||||||
|
)
|
||||||
|
apiResponseSizeSummary = promauto.NewSummaryVec(
|
||||||
|
prometheus.SummaryOpts{
|
||||||
|
Name: "aptly_api_http_response_size_bytes",
|
||||||
|
Help: "Api HTTP response size in bytes.",
|
||||||
|
},
|
||||||
|
[]string{"code", "method", "path"},
|
||||||
|
)
|
||||||
|
apiRequestsDurationSummary = promauto.NewSummaryVec(
|
||||||
|
prometheus.SummaryOpts{
|
||||||
|
Name: "aptly_api_http_request_duration_seconds",
|
||||||
|
Help: "Duration of api requests in seconds.",
|
||||||
|
},
|
||||||
|
[]string{"code", "method", "path"},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Only use base path as label value (e.g.: /api/repos) because of time series cardinality
|
||||||
|
// See https://prometheus.io/docs/practices/naming/#labels
|
||||||
|
func getBasePath(c *gin.Context) string {
|
||||||
|
return fmt.Sprintf("%s%s", getURLSegment(c.Request.URL.Path, 0), getURLSegment(c.Request.URL.Path, 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
func getURLSegment(url string, idx int) string {
|
||||||
|
var urlSegments = strings.Split(url, "/")
|
||||||
|
|
||||||
|
// Remove segment at index 0 because it's an empty string
|
||||||
|
var segmentAtIndex = urlSegments[1:cap(urlSegments)][idx]
|
||||||
|
return fmt.Sprintf("/%s", segmentAtIndex)
|
||||||
|
}
|
||||||
|
|
||||||
|
func instrumentHandlerInFlight(g *prometheus.GaugeVec, pathFunc func(*gin.Context) string) func(*gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
g.WithLabelValues(c.Request.Method, pathFunc(c)).Inc()
|
||||||
|
defer g.WithLabelValues(c.Request.Method, pathFunc(c)).Dec()
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func instrumentHandlerCounter(counter *prometheus.CounterVec, pathFunc func(*gin.Context) string) func(*gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
c.Next()
|
||||||
|
counter.WithLabelValues(strconv.Itoa(c.Writer.Status()), c.Request.Method, pathFunc(c)).Inc()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func instrumentHandlerRequestSize(obs prometheus.ObserverVec, pathFunc func(*gin.Context) string) func(*gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
c.Next()
|
||||||
|
obs.WithLabelValues(strconv.Itoa(c.Writer.Status()), c.Request.Method, pathFunc(c)).Observe(float64(c.Request.ContentLength))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func instrumentHandlerResponseSize(obs prometheus.ObserverVec, pathFunc func(*gin.Context) string) func(*gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
c.Next()
|
||||||
|
var responseSize = math.Max(float64(c.Writer.Size()), 0)
|
||||||
|
obs.WithLabelValues(strconv.Itoa(c.Writer.Status()), c.Request.Method, pathFunc(c)).Observe(responseSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func instrumentHandlerDuration(obs prometheus.ObserverVec, pathFunc func(*gin.Context) string) func(*gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
now := time.Now()
|
||||||
|
c.Next()
|
||||||
|
obs.WithLabelValues(strconv.Itoa(c.Writer.Status()), c.Request.Method, pathFunc(c)).Observe(time.Since(now).Seconds())
|
||||||
|
}
|
||||||
|
}
|
||||||
+556
@@ -0,0 +1,556 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/pgp"
|
||||||
|
"github.com/aptly-dev/aptly/query"
|
||||||
|
"github.com/aptly-dev/aptly/task"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getVerifier(ignoreSignatures bool, keyRings []string) (pgp.Verifier, error) {
|
||||||
|
if ignoreSignatures {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
verifier := context.GetVerifier()
|
||||||
|
for _, keyRing := range keyRings {
|
||||||
|
verifier.AddKeyring(keyRing)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := verifier.InitKeyring()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return verifier, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /api/mirrors
|
||||||
|
func apiMirrorsList(c *gin.Context) {
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
collection := collectionFactory.RemoteRepoCollection()
|
||||||
|
|
||||||
|
result := []*deb.RemoteRepo{}
|
||||||
|
collection.ForEach(func(repo *deb.RemoteRepo) error {
|
||||||
|
result = append(result, repo)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
c.JSON(200, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST /api/mirrors
|
||||||
|
func apiMirrorsCreate(c *gin.Context) {
|
||||||
|
var err error
|
||||||
|
var b struct {
|
||||||
|
Name string `binding:"required"`
|
||||||
|
ArchiveURL string `binding:"required"`
|
||||||
|
Distribution string
|
||||||
|
Filter string
|
||||||
|
Components []string
|
||||||
|
Architectures []string
|
||||||
|
Keyrings []string
|
||||||
|
DownloadSources bool
|
||||||
|
DownloadUdebs bool
|
||||||
|
DownloadInstaller bool
|
||||||
|
FilterWithDeps bool
|
||||||
|
SkipComponentCheck bool
|
||||||
|
IgnoreSignatures bool
|
||||||
|
}
|
||||||
|
|
||||||
|
b.DownloadSources = context.Config().DownloadSourcePackages
|
||||||
|
b.IgnoreSignatures = context.Config().GpgDisableVerify
|
||||||
|
b.Architectures = context.ArchitecturesList()
|
||||||
|
|
||||||
|
if c.Bind(&b) != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
collection := collectionFactory.RemoteRepoCollection()
|
||||||
|
|
||||||
|
if strings.HasPrefix(b.ArchiveURL, "ppa:") {
|
||||||
|
b.ArchiveURL, b.Distribution, b.Components, err = deb.ParsePPA(b.ArchiveURL, context.Config())
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(400, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.Filter != "" {
|
||||||
|
_, err = query.Parse(b.Filter)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(400, fmt.Errorf("unable to create mirror: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repo, err := deb.NewRemoteRepo(b.Name, b.ArchiveURL, b.Distribution, b.Components, b.Architectures,
|
||||||
|
b.DownloadSources, b.DownloadUdebs, b.DownloadInstaller)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(400, fmt.Errorf("unable to create mirror: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
repo.Filter = b.Filter
|
||||||
|
repo.FilterWithDeps = b.FilterWithDeps
|
||||||
|
repo.SkipComponentCheck = b.SkipComponentCheck
|
||||||
|
repo.DownloadSources = b.DownloadSources
|
||||||
|
repo.DownloadUdebs = b.DownloadUdebs
|
||||||
|
|
||||||
|
verifier, err := getVerifier(b.IgnoreSignatures, b.Keyrings)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(400, fmt.Errorf("unable to initialize GPG verifier: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
downloader := context.NewDownloader(nil)
|
||||||
|
err = repo.Fetch(downloader, verifier)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(400, fmt.Errorf("unable to fetch mirror: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = collection.Add(repo)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(500, fmt.Errorf("unable to add mirror: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(201, repo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DELETE /api/mirrors/:name
|
||||||
|
func apiMirrorsDrop(c *gin.Context) {
|
||||||
|
name := c.Params.ByName("name")
|
||||||
|
force := c.Request.URL.Query().Get("force") == "1"
|
||||||
|
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
mirrorCollection := collectionFactory.RemoteRepoCollection()
|
||||||
|
snapshotCollection := collectionFactory.SnapshotCollection()
|
||||||
|
|
||||||
|
repo, err := mirrorCollection.ByName(name)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(404, fmt.Errorf("unable to drop: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resources := []string{string(repo.Key())}
|
||||||
|
taskName := fmt.Sprintf("Delete mirror %s", name)
|
||||||
|
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
|
err := repo.CheckLock()
|
||||||
|
if err != nil {
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to drop: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !force {
|
||||||
|
snapshots := snapshotCollection.ByRemoteRepoSource(repo)
|
||||||
|
|
||||||
|
if len(snapshots) > 0 {
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("won't delete mirror with snapshots, use 'force=1' to override")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = mirrorCollection.Drop(repo)
|
||||||
|
if err != nil {
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to drop: %v", err)
|
||||||
|
}
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusNoContent, Value: nil}, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /api/mirrors/:name
|
||||||
|
func apiMirrorsShow(c *gin.Context) {
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
collection := collectionFactory.RemoteRepoCollection()
|
||||||
|
|
||||||
|
name := c.Params.ByName("name")
|
||||||
|
repo, err := collection.ByName(name)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(404, fmt.Errorf("unable to show: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = collection.LoadComplete(repo)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(500, fmt.Errorf("unable to show: %s", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(200, repo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /api/mirrors/:name/packages
|
||||||
|
func apiMirrorsPackages(c *gin.Context) {
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
collection := collectionFactory.RemoteRepoCollection()
|
||||||
|
|
||||||
|
name := c.Params.ByName("name")
|
||||||
|
repo, err := collection.ByName(name)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(404, fmt.Errorf("unable to show: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = collection.LoadComplete(repo)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(500, fmt.Errorf("unable to show: %s", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
if repo.LastDownloadDate.IsZero() {
|
||||||
|
c.AbortWithError(404, fmt.Errorf("unable to show package list, mirror hasn't been downloaded yet"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
reflist := repo.RefList()
|
||||||
|
result := []*deb.Package{}
|
||||||
|
|
||||||
|
list, err := deb.NewPackageListFromRefList(reflist, collectionFactory.PackageCollection(), nil)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(404, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
queryS := c.Request.URL.Query().Get("q")
|
||||||
|
if queryS != "" {
|
||||||
|
q, err := query.Parse(c.Request.URL.Query().Get("q"))
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(400, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
withDeps := c.Request.URL.Query().Get("withDeps") == "1"
|
||||||
|
architecturesList := []string{}
|
||||||
|
|
||||||
|
if withDeps {
|
||||||
|
if len(context.ArchitecturesList()) > 0 {
|
||||||
|
architecturesList = context.ArchitecturesList()
|
||||||
|
} else {
|
||||||
|
architecturesList = list.Architectures(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(architecturesList)
|
||||||
|
|
||||||
|
if len(architecturesList) == 0 {
|
||||||
|
c.AbortWithError(400, fmt.Errorf("unable to determine list of architectures, please specify explicitly"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
list.PrepareIndex()
|
||||||
|
|
||||||
|
list, err = list.Filter([]deb.PackageQuery{q}, withDeps,
|
||||||
|
nil, context.DependencyOptions(), architecturesList)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(500, fmt.Errorf("unable to search: %s", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Request.URL.Query().Get("format") == "details" {
|
||||||
|
list.ForEach(func(p *deb.Package) error {
|
||||||
|
result = append(result, p)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
c.JSON(200, result)
|
||||||
|
} else {
|
||||||
|
c.JSON(200, list.Strings())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PUT /api/mirrors/:name
|
||||||
|
func apiMirrorsUpdate(c *gin.Context) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
remote *deb.RemoteRepo
|
||||||
|
)
|
||||||
|
|
||||||
|
var b struct {
|
||||||
|
Name string
|
||||||
|
ArchiveURL string
|
||||||
|
Filter string
|
||||||
|
Architectures []string
|
||||||
|
Components []string
|
||||||
|
Keyrings []string
|
||||||
|
FilterWithDeps bool
|
||||||
|
DownloadSources bool
|
||||||
|
DownloadUdebs bool
|
||||||
|
SkipComponentCheck bool
|
||||||
|
IgnoreChecksums bool
|
||||||
|
IgnoreSignatures bool
|
||||||
|
ForceUpdate bool
|
||||||
|
SkipExistingPackages bool
|
||||||
|
}
|
||||||
|
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
collection := collectionFactory.RemoteRepoCollection()
|
||||||
|
|
||||||
|
remote, err = collection.ByName(c.Params.ByName("name"))
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(404, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
b.Name = remote.Name
|
||||||
|
b.DownloadUdebs = remote.DownloadUdebs
|
||||||
|
b.DownloadSources = remote.DownloadSources
|
||||||
|
b.SkipComponentCheck = remote.SkipComponentCheck
|
||||||
|
b.FilterWithDeps = remote.FilterWithDeps
|
||||||
|
b.Filter = remote.Filter
|
||||||
|
b.Architectures = remote.Architectures
|
||||||
|
b.Components = remote.Components
|
||||||
|
|
||||||
|
log.Printf("%s: Starting mirror update\n", b.Name)
|
||||||
|
|
||||||
|
if c.Bind(&b) != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.Name != remote.Name {
|
||||||
|
_, err = collection.ByName(b.Name)
|
||||||
|
if err == nil {
|
||||||
|
c.AbortWithError(409, fmt.Errorf("unable to rename: mirror %s already exists", b.Name))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.DownloadUdebs != remote.DownloadUdebs {
|
||||||
|
if remote.IsFlat() && b.DownloadUdebs {
|
||||||
|
c.AbortWithError(400, fmt.Errorf("unable to update: flat mirrors don't support udebs"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.ArchiveURL != "" {
|
||||||
|
remote.SetArchiveRoot(b.ArchiveURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
remote.Name = b.Name
|
||||||
|
remote.DownloadUdebs = b.DownloadUdebs
|
||||||
|
remote.DownloadSources = b.DownloadSources
|
||||||
|
remote.SkipComponentCheck = b.SkipComponentCheck
|
||||||
|
remote.FilterWithDeps = b.FilterWithDeps
|
||||||
|
remote.Filter = b.Filter
|
||||||
|
remote.Architectures = b.Architectures
|
||||||
|
remote.Components = b.Components
|
||||||
|
|
||||||
|
verifier, err := getVerifier(b.IgnoreSignatures, b.Keyrings)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(400, fmt.Errorf("unable to initialize GPG verifier: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resources := []string{string(remote.Key())}
|
||||||
|
maybeRunTaskInBackground(c, "Update mirror "+b.Name, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
|
|
||||||
|
downloader := context.NewDownloader(out)
|
||||||
|
err := remote.Fetch(downloader, verifier)
|
||||||
|
if err != nil {
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !b.ForceUpdate {
|
||||||
|
err = remote.CheckLock()
|
||||||
|
if err != nil {
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = remote.DownloadPackageIndexes(out, downloader, verifier, collectionFactory, b.SkipComponentCheck)
|
||||||
|
if err != nil {
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if remote.Filter != "" {
|
||||||
|
var filterQuery deb.PackageQuery
|
||||||
|
|
||||||
|
filterQuery, err = query.Parse(remote.Filter)
|
||||||
|
if err != nil {
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, err = remote.ApplyFilter(context.DependencyOptions(), filterQuery, out)
|
||||||
|
if err != nil {
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
queue, downloadSize, err := remote.BuildDownloadQueue(context.PackagePool(), collectionFactory.PackageCollection(),
|
||||||
|
collectionFactory.ChecksumCollection(nil), b.SkipExistingPackages)
|
||||||
|
if err != nil {
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
// on any interruption, unlock the mirror
|
||||||
|
e := context.ReOpenDatabase()
|
||||||
|
if e == nil {
|
||||||
|
remote.MarkAsIdle()
|
||||||
|
collection.Update(remote)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
remote.MarkAsUpdating()
|
||||||
|
err = collection.Update(remote)
|
||||||
|
if err != nil {
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
context.GoContextHandleSignals()
|
||||||
|
|
||||||
|
count := len(queue)
|
||||||
|
taskDetail := struct {
|
||||||
|
TotalDownloadSize int64
|
||||||
|
RemainingDownloadSize int64
|
||||||
|
TotalNumberOfPackages int
|
||||||
|
RemainingNumberOfPackages int
|
||||||
|
}{
|
||||||
|
downloadSize, downloadSize, count, count,
|
||||||
|
}
|
||||||
|
detail.Store(taskDetail)
|
||||||
|
|
||||||
|
downloadQueue := make(chan int)
|
||||||
|
taskFinished := make(chan *deb.PackageDownloadTask)
|
||||||
|
|
||||||
|
var (
|
||||||
|
errors []string
|
||||||
|
errLock sync.Mutex
|
||||||
|
)
|
||||||
|
|
||||||
|
pushError := func(err error) {
|
||||||
|
errLock.Lock()
|
||||||
|
errors = append(errors, err.Error())
|
||||||
|
errLock.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for idx := range queue {
|
||||||
|
select {
|
||||||
|
case downloadQueue <- idx:
|
||||||
|
case <-context.Done():
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close(downloadQueue)
|
||||||
|
}()
|
||||||
|
|
||||||
|
// update of task details need to be done in order
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
task, ok := <-taskFinished
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
taskDetail.RemainingDownloadSize -= task.File.Checksums.Size
|
||||||
|
taskDetail.RemainingNumberOfPackages--
|
||||||
|
detail.Store(taskDetail)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
log.Printf("%s: Spawning background processes...\n", b.Name)
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
for i := 0; i < context.Config().DownloadConcurrency; i++ {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case idx, ok := <-downloadQueue:
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
task := &queue[idx]
|
||||||
|
|
||||||
|
var e error
|
||||||
|
|
||||||
|
// provision download location
|
||||||
|
task.TempDownPath, e = context.PackagePool().(aptly.LocalPackagePool).GenerateTempPath(task.File.Filename)
|
||||||
|
if e != nil {
|
||||||
|
pushError(e)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// download file...
|
||||||
|
e = context.Downloader().DownloadWithChecksum(
|
||||||
|
context,
|
||||||
|
remote.PackageURL(task.File.DownloadURL()).String(),
|
||||||
|
task.TempDownPath,
|
||||||
|
&task.File.Checksums,
|
||||||
|
b.IgnoreChecksums)
|
||||||
|
if e != nil {
|
||||||
|
pushError(e)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
task.Done = true
|
||||||
|
taskFinished <- task
|
||||||
|
case <-context.Done():
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for all download goroutines to finish
|
||||||
|
log.Printf("%s: Waiting for background processes to finish...\n", b.Name)
|
||||||
|
wg.Wait()
|
||||||
|
log.Printf("%s: Background processes finished\n", b.Name)
|
||||||
|
close(taskFinished)
|
||||||
|
|
||||||
|
for idx := range queue {
|
||||||
|
|
||||||
|
atask := &queue[idx]
|
||||||
|
|
||||||
|
if !atask.Done {
|
||||||
|
// download not finished yet
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// and import it back to the pool
|
||||||
|
atask.File.PoolPath, err = context.PackagePool().Import(atask.TempDownPath, atask.File.Filename, &atask.File.Checksums, true, collectionFactory.ChecksumCollection(nil))
|
||||||
|
if err != nil {
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to import file: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// update "attached" files if any
|
||||||
|
for _, additionalAtask := range atask.Additional {
|
||||||
|
additionalAtask.File.PoolPath = atask.File.PoolPath
|
||||||
|
additionalAtask.File.Checksums = atask.File.Checksums
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-context.Done():
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: interrupted")
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(errors) > 0 {
|
||||||
|
log.Printf("%s: Unable to update because of previous errors\n", b.Name)
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: download errors:\n %s", strings.Join(errors, "\n "))
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("%s: Finalizing download\n", b.Name)
|
||||||
|
remote.FinalizeDownload(collectionFactory, out)
|
||||||
|
err = collectionFactory.RemoteRepoCollection().Update(remote)
|
||||||
|
if err != nil {
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("%s: Mirror updated successfully!\n", b.Name)
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusNoContent, Value: nil}, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MirrorSuite struct {
|
||||||
|
ApiSuite
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = Suite(&MirrorSuite{})
|
||||||
|
|
||||||
|
func (s *MirrorSuite) TestGetMirrors(c *C) {
|
||||||
|
response, _ := s.HTTPRequest("GET", "/api/mirrors", nil)
|
||||||
|
c.Check(response.Code, Equals, 200)
|
||||||
|
c.Check(response.Body.String(), Equals, "[]")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MirrorSuite) TestDeleteMirrorNonExisting(c *C) {
|
||||||
|
response, _ := s.HTTPRequest("DELETE", "/api/mirrors/does-not-exist", nil)
|
||||||
|
c.Check(response.Code, Equals, 404)
|
||||||
|
c.Check(response.Body.String(), Equals, "{\"error\":\"unable to drop: mirror with name does-not-exist not found\"}")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MirrorSuite) TestCreateMirror(c *C) {
|
||||||
|
c.ExpectFailure("Need to mock downloads")
|
||||||
|
body, err := json.Marshal(gin.H{
|
||||||
|
"Name": "dummy",
|
||||||
|
"ArchiveURL": "foobar",
|
||||||
|
})
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
response, err := s.HTTPRequest("POST", "/api/mirrors", bytes.NewReader(body))
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Check(response.Code, Equals, 400)
|
||||||
|
c.Check(response.Body.String(), Equals, "")
|
||||||
|
}
|
||||||
+3
-2
@@ -6,9 +6,10 @@ import (
|
|||||||
|
|
||||||
// GET /api/packages/:key
|
// GET /api/packages/:key
|
||||||
func apiPackagesShow(c *gin.Context) {
|
func apiPackagesShow(c *gin.Context) {
|
||||||
p, err := context.CollectionFactory().PackageCollection().ByKey([]byte(c.Params.ByName("key")))
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
p, err := collectionFactory.PackageCollection().ByKey([]byte(c.Params.ByName("key")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+151
-92
@@ -2,10 +2,15 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"net/http"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"github.com/smira/aptly/utils"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/pgp"
|
||||||
|
"github.com/aptly-dev/aptly/task"
|
||||||
|
"github.com/aptly-dev/aptly/utils"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SigningOptions is a shared between publish API GPG options structure
|
// SigningOptions is a shared between publish API GPG options structure
|
||||||
@@ -19,12 +24,12 @@ type SigningOptions struct {
|
|||||||
PassphraseFile string
|
PassphraseFile string
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSigner(options *SigningOptions) (utils.Signer, error) {
|
func getSigner(options *SigningOptions) (pgp.Signer, error) {
|
||||||
if options.Skip {
|
if options.Skip {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
signer := &utils.GpgSigner{}
|
signer := context.GetSigner()
|
||||||
signer.SetKey(options.GpgKey)
|
signer.SetKey(options.GpgKey)
|
||||||
signer.SetKeyRing(options.Keyring, options.SecretKeyring)
|
signer.SetKeyRing(options.Keyring, options.SecretKeyring)
|
||||||
signer.SetPassphrase(options.Passphrase, options.PassphraseFile)
|
signer.SetPassphrase(options.Passphrase, options.PassphraseFile)
|
||||||
@@ -49,22 +54,13 @@ func parseEscapedPath(path string) string {
|
|||||||
|
|
||||||
// GET /publish
|
// GET /publish
|
||||||
func apiPublishList(c *gin.Context) {
|
func apiPublishList(c *gin.Context) {
|
||||||
localCollection := context.CollectionFactory().LocalRepoCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
localCollection.RLock()
|
collection := collectionFactory.PublishedRepoCollection()
|
||||||
defer localCollection.RUnlock()
|
|
||||||
|
|
||||||
snapshotCollection := context.CollectionFactory().SnapshotCollection()
|
|
||||||
snapshotCollection.RLock()
|
|
||||||
defer snapshotCollection.RUnlock()
|
|
||||||
|
|
||||||
collection := context.CollectionFactory().PublishedRepoCollection()
|
|
||||||
collection.RLock()
|
|
||||||
defer collection.RUnlock()
|
|
||||||
|
|
||||||
result := make([]*deb.PublishedRepo, 0, collection.Len())
|
result := make([]*deb.PublishedRepo, 0, collection.Len())
|
||||||
|
|
||||||
err := collection.ForEach(func(repo *deb.PublishedRepo) error {
|
err := collection.ForEach(func(repo *deb.PublishedRepo) error {
|
||||||
err := collection.LoadComplete(repo, context.CollectionFactory())
|
err := collection.LoadComplete(repo, collectionFactory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -75,7 +71,7 @@ func apiPublishList(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,112 +92,151 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
|
|||||||
Distribution string
|
Distribution string
|
||||||
Label string
|
Label string
|
||||||
Origin string
|
Origin string
|
||||||
|
NotAutomatic string
|
||||||
|
ButAutomaticUpgrades string
|
||||||
ForceOverwrite bool
|
ForceOverwrite bool
|
||||||
|
SkipContents *bool
|
||||||
|
SkipBz2 *bool
|
||||||
Architectures []string
|
Architectures []string
|
||||||
Signing SigningOptions
|
Signing SigningOptions
|
||||||
|
AcquireByHash *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.Bind(&b) {
|
if c.Bind(&b) != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
signer, err := getSigner(&b.Signing)
|
signer, err := getSigner(&b.Signing)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to initialize GPG signer: %s", err))
|
c.AbortWithError(500, fmt.Errorf("unable to initialize GPG signer: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(b.Sources) == 0 {
|
if len(b.Sources) == 0 {
|
||||||
c.Fail(400, fmt.Errorf("unable to publish: soures are empty"))
|
c.AbortWithError(400, fmt.Errorf("unable to publish: soures are empty"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var components []string
|
var components []string
|
||||||
|
var names []string
|
||||||
var sources []interface{}
|
var sources []interface{}
|
||||||
|
var resources []string
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
|
||||||
if b.SourceKind == "snapshot" {
|
if b.SourceKind == "snapshot" {
|
||||||
var snapshot *deb.Snapshot
|
var snapshot *deb.Snapshot
|
||||||
|
|
||||||
snapshotCollection := context.CollectionFactory().SnapshotCollection()
|
snapshotCollection := collectionFactory.SnapshotCollection()
|
||||||
snapshotCollection.RLock()
|
|
||||||
defer snapshotCollection.RUnlock()
|
|
||||||
|
|
||||||
for _, source := range b.Sources {
|
for _, source := range b.Sources {
|
||||||
components = append(components, source.Component)
|
components = append(components, source.Component)
|
||||||
|
names = append(names, source.Name)
|
||||||
|
|
||||||
snapshot, err = snapshotCollection.ByName(source.Name)
|
snapshot, err = snapshotCollection.ByName(source.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, fmt.Errorf("unable to publish: %s", err))
|
c.AbortWithError(404, fmt.Errorf("unable to publish: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resources = append(resources, string(snapshot.ResourceKey()))
|
||||||
err = snapshotCollection.LoadComplete(snapshot)
|
err = snapshotCollection.LoadComplete(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to publish: %s", err))
|
c.AbortWithError(500, fmt.Errorf("unable to publish: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sources = append(sources, snapshot)
|
sources = append(sources, snapshot)
|
||||||
}
|
}
|
||||||
} else if b.SourceKind == "local" {
|
} else if b.SourceKind == deb.SourceLocalRepo {
|
||||||
var localRepo *deb.LocalRepo
|
var localRepo *deb.LocalRepo
|
||||||
|
|
||||||
localCollection := context.CollectionFactory().LocalRepoCollection()
|
localCollection := collectionFactory.LocalRepoCollection()
|
||||||
localCollection.RLock()
|
|
||||||
defer localCollection.RUnlock()
|
|
||||||
|
|
||||||
for _, source := range b.Sources {
|
for _, source := range b.Sources {
|
||||||
components = append(components, source.Component)
|
components = append(components, source.Component)
|
||||||
|
names = append(names, source.Name)
|
||||||
|
|
||||||
localRepo, err = localCollection.ByName(source.Name)
|
localRepo, err = localCollection.ByName(source.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, fmt.Errorf("unable to publish: %s", err))
|
c.AbortWithError(404, fmt.Errorf("unable to publish: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resources = append(resources, string(localRepo.Key()))
|
||||||
err = localCollection.LoadComplete(localRepo)
|
err = localCollection.LoadComplete(localRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to publish: %s", err))
|
c.AbortWithError(500, fmt.Errorf("unable to publish: %s", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
sources = append(sources, localRepo)
|
sources = append(sources, localRepo)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.Fail(400, fmt.Errorf("unknown SourceKind"))
|
c.AbortWithError(400, fmt.Errorf("unknown SourceKind"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
collection := context.CollectionFactory().PublishedRepoCollection()
|
published, err := deb.NewPublishedRepo(storage, prefix, b.Distribution, b.Architectures, components, sources, collectionFactory)
|
||||||
collection.Lock()
|
|
||||||
defer collection.Unlock()
|
|
||||||
|
|
||||||
published, err := deb.NewPublishedRepo(storage, prefix, b.Distribution, b.Architectures, components, sources, context.CollectionFactory())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to publish: %s", err))
|
c.AbortWithError(500, fmt.Errorf("unable to publish: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resources = append(resources, string(published.Key()))
|
||||||
|
collection := collectionFactory.PublishedRepoCollection()
|
||||||
|
|
||||||
|
taskName := fmt.Sprintf("Publish %s: %s", b.SourceKind, strings.Join(names, ", "))
|
||||||
|
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
|
taskDetail := task.PublishDetail{
|
||||||
|
Detail: detail,
|
||||||
|
}
|
||||||
|
publishOutput := &task.PublishOutput{
|
||||||
|
Progress: out,
|
||||||
|
PublishDetail: taskDetail,
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.Origin != "" {
|
||||||
published.Origin = b.Origin
|
published.Origin = b.Origin
|
||||||
|
}
|
||||||
|
if b.NotAutomatic != "" {
|
||||||
|
published.NotAutomatic = b.NotAutomatic
|
||||||
|
}
|
||||||
|
if b.ButAutomaticUpgrades != "" {
|
||||||
|
published.ButAutomaticUpgrades = b.ButAutomaticUpgrades
|
||||||
|
}
|
||||||
published.Label = b.Label
|
published.Label = b.Label
|
||||||
|
|
||||||
|
published.SkipContents = context.Config().SkipContentsPublishing
|
||||||
|
if b.SkipContents != nil {
|
||||||
|
published.SkipContents = *b.SkipContents
|
||||||
|
}
|
||||||
|
|
||||||
|
published.SkipBz2 = context.Config().SkipBz2Publishing
|
||||||
|
if b.SkipContents != nil {
|
||||||
|
published.SkipBz2 = *b.SkipBz2
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.AcquireByHash != nil {
|
||||||
|
published.AcquireByHash = *b.AcquireByHash
|
||||||
|
}
|
||||||
|
|
||||||
duplicate := collection.CheckDuplicate(published)
|
duplicate := collection.CheckDuplicate(published)
|
||||||
if duplicate != nil {
|
if duplicate != nil {
|
||||||
context.CollectionFactory().PublishedRepoCollection().LoadComplete(duplicate, context.CollectionFactory())
|
collectionFactory.PublishedRepoCollection().LoadComplete(duplicate, collectionFactory)
|
||||||
c.Fail(400, fmt.Errorf("prefix/distribution already used by another published repo: %s", duplicate))
|
return &task.ProcessReturnValue{Code: http.StatusBadRequest, Value: nil}, fmt.Errorf("prefix/distribution already used by another published repo: %s", duplicate)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = published.Publish(context.PackagePool(), context, context.CollectionFactory(), signer, nil, b.ForceOverwrite)
|
err := published.Publish(context.PackagePool(), context, collectionFactory, signer, publishOutput, b.ForceOverwrite)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to publish: %s", err))
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to publish: %s", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = collection.Add(published)
|
err = collection.Add(published)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to save to DB: %s", err))
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to save to DB: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(201, published)
|
return &task.ProcessReturnValue{Code: http.StatusCreated, Value: published}, nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT /publish/:prefix/:distribution
|
// PUT /publish/:prefix/:distribution
|
||||||
@@ -213,51 +248,47 @@ func apiPublishUpdateSwitch(c *gin.Context) {
|
|||||||
var b struct {
|
var b struct {
|
||||||
ForceOverwrite bool
|
ForceOverwrite bool
|
||||||
Signing SigningOptions
|
Signing SigningOptions
|
||||||
|
SkipContents *bool
|
||||||
|
SkipBz2 *bool
|
||||||
|
SkipCleanup *bool
|
||||||
Snapshots []struct {
|
Snapshots []struct {
|
||||||
Component string `binding:"required"`
|
Component string `binding:"required"`
|
||||||
Name string `binding:"required"`
|
Name string `binding:"required"`
|
||||||
}
|
}
|
||||||
|
AcquireByHash *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.Bind(&b) {
|
if c.Bind(&b) != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
signer, err := getSigner(&b.Signing)
|
signer, err := getSigner(&b.Signing)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to initialize GPG signer: %s", err))
|
c.AbortWithError(500, fmt.Errorf("unable to initialize GPG signer: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// published.LoadComplete would touch local repo collection
|
collectionFactory := context.NewCollectionFactory()
|
||||||
localRepoCollection := context.CollectionFactory().LocalRepoCollection()
|
collection := collectionFactory.PublishedRepoCollection()
|
||||||
localRepoCollection.RLock()
|
|
||||||
defer localRepoCollection.RUnlock()
|
|
||||||
|
|
||||||
snapshotCollection := context.CollectionFactory().SnapshotCollection()
|
|
||||||
snapshotCollection.RLock()
|
|
||||||
defer snapshotCollection.RUnlock()
|
|
||||||
|
|
||||||
collection := context.CollectionFactory().PublishedRepoCollection()
|
|
||||||
collection.Lock()
|
|
||||||
defer collection.Unlock()
|
|
||||||
|
|
||||||
published, err := collection.ByStoragePrefixDistribution(storage, prefix, distribution)
|
published, err := collection.ByStoragePrefixDistribution(storage, prefix, distribution)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, fmt.Errorf("unable to update: %s", err))
|
c.AbortWithError(404, fmt.Errorf("unable to update: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = collection.LoadComplete(published, context.CollectionFactory())
|
err = collection.LoadComplete(published, collectionFactory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to update: %s", err))
|
c.AbortWithError(500, fmt.Errorf("unable to update: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var updatedComponents []string
|
var updatedComponents []string
|
||||||
|
var updatedSnapshots []string
|
||||||
|
var resources []string
|
||||||
|
|
||||||
if published.SourceKind == "local" {
|
if published.SourceKind == deb.SourceLocalRepo {
|
||||||
if len(b.Snapshots) > 0 {
|
if len(b.Snapshots) > 0 {
|
||||||
c.Fail(400, fmt.Errorf("snapshots shouldn't be given when updating local repo"))
|
c.AbortWithError(400, fmt.Errorf("snapshots shouldn't be given when updating local repo"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
updatedComponents = published.Components()
|
updatedComponents = published.Components()
|
||||||
@@ -268,69 +299,97 @@ func apiPublishUpdateSwitch(c *gin.Context) {
|
|||||||
publishedComponents := published.Components()
|
publishedComponents := published.Components()
|
||||||
for _, snapshotInfo := range b.Snapshots {
|
for _, snapshotInfo := range b.Snapshots {
|
||||||
if !utils.StrSliceHasItem(publishedComponents, snapshotInfo.Component) {
|
if !utils.StrSliceHasItem(publishedComponents, snapshotInfo.Component) {
|
||||||
c.Fail(404, fmt.Errorf("component %s is not in published repository", snapshotInfo.Component))
|
c.AbortWithError(404, fmt.Errorf("component %s is not in published repository", snapshotInfo.Component))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshot, err := snapshotCollection.ByName(snapshotInfo.Name)
|
snapshotCollection := collectionFactory.SnapshotCollection()
|
||||||
if err != nil {
|
snapshot, err2 := snapshotCollection.ByName(snapshotInfo.Name)
|
||||||
c.Fail(404, err)
|
if err2 != nil {
|
||||||
|
c.AbortWithError(404, err2)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = snapshotCollection.LoadComplete(snapshot)
|
err2 = snapshotCollection.LoadComplete(snapshot)
|
||||||
if err != nil {
|
if err2 != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err2)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
published.UpdateSnapshot(snapshotInfo.Component, snapshot)
|
published.UpdateSnapshot(snapshotInfo.Component, snapshot)
|
||||||
updatedComponents = append(updatedComponents, snapshotInfo.Component)
|
updatedComponents = append(updatedComponents, snapshotInfo.Component)
|
||||||
|
updatedSnapshots = append(updatedSnapshots, snapshot.Name)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.Fail(500, fmt.Errorf("unknown published repository type"))
|
c.AbortWithError(500, fmt.Errorf("unknown published repository type"))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = published.Publish(context.PackagePool(), context, context.CollectionFactory(), signer, nil, b.ForceOverwrite)
|
if b.SkipContents != nil {
|
||||||
|
published.SkipContents = *b.SkipContents
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.SkipBz2 != nil {
|
||||||
|
published.SkipBz2 = *b.SkipBz2
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.AcquireByHash != nil {
|
||||||
|
published.AcquireByHash = *b.AcquireByHash
|
||||||
|
}
|
||||||
|
|
||||||
|
resources = append(resources, string(published.Key()))
|
||||||
|
taskName := fmt.Sprintf("Update published %s (%s): %s", published.SourceKind, strings.Join(updatedComponents, " "), strings.Join(updatedSnapshots, ", "))
|
||||||
|
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
|
err := published.Publish(context.PackagePool(), context, collectionFactory, signer, out, b.ForceOverwrite)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to update: %s", err))
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = collection.Update(published)
|
err = collection.Update(published)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to save to DB: %s", err))
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to save to DB: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.SkipCleanup == nil || !*b.SkipCleanup {
|
||||||
err = collection.CleanupPrefixComponentFiles(published.Prefix, updatedComponents,
|
err = collection.CleanupPrefixComponentFiles(published.Prefix, updatedComponents,
|
||||||
context.GetPublishedStorage(storage), context.CollectionFactory(), nil)
|
context.GetPublishedStorage(storage), collectionFactory, out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to update: %s", err))
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(200, published)
|
return &task.ProcessReturnValue{Code: http.StatusOK, Value: published}, nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE /publish/:prefix/:distribution
|
// DELETE /publish/:prefix/:distribution
|
||||||
func apiPublishDrop(c *gin.Context) {
|
func apiPublishDrop(c *gin.Context) {
|
||||||
|
force := c.Request.URL.Query().Get("force") == "1"
|
||||||
|
skipCleanup := c.Request.URL.Query().Get("SkipCleanup") == "1"
|
||||||
|
|
||||||
param := parseEscapedPath(c.Params.ByName("prefix"))
|
param := parseEscapedPath(c.Params.ByName("prefix"))
|
||||||
storage, prefix := deb.ParsePrefix(param)
|
storage, prefix := deb.ParsePrefix(param)
|
||||||
distribution := c.Params.ByName("distribution")
|
distribution := c.Params.ByName("distribution")
|
||||||
|
|
||||||
// published.LoadComplete would touch local repo collection
|
collectionFactory := context.NewCollectionFactory()
|
||||||
localRepoCollection := context.CollectionFactory().LocalRepoCollection()
|
collection := collectionFactory.PublishedRepoCollection()
|
||||||
localRepoCollection.RLock()
|
|
||||||
defer localRepoCollection.RUnlock()
|
|
||||||
|
|
||||||
collection := context.CollectionFactory().PublishedRepoCollection()
|
published, err := collection.ByStoragePrefixDistribution(storage, prefix, distribution)
|
||||||
collection.Lock()
|
|
||||||
defer collection.Unlock()
|
|
||||||
|
|
||||||
err := collection.Remove(context, storage, prefix, distribution,
|
|
||||||
context.CollectionFactory(), context.Progress())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to drop: %s", err))
|
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("unable to drop: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(200, gin.H{})
|
resources := []string{string(published.Key())}
|
||||||
|
|
||||||
|
taskName := fmt.Sprintf("Delete published %s (%s)", prefix, distribution)
|
||||||
|
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
|
err := collection.Remove(context, storage, prefix, distribution,
|
||||||
|
collectionFactory, out, force, skipCleanup)
|
||||||
|
if err != nil {
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to drop: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusOK, Value: gin.H{}}, nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
+249
-124
@@ -2,24 +2,28 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"net/http"
|
||||||
"github.com/smira/aptly/aptly"
|
|
||||||
"github.com/smira/aptly/database"
|
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"github.com/smira/aptly/utils"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/aptly-dev/aptly/database"
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/query"
|
||||||
|
"github.com/aptly-dev/aptly/task"
|
||||||
|
"github.com/aptly-dev/aptly/utils"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GET /api/repos
|
// GET /api/repos
|
||||||
func apiReposList(c *gin.Context) {
|
func apiReposList(c *gin.Context) {
|
||||||
result := []*deb.LocalRepo{}
|
result := []*deb.LocalRepo{}
|
||||||
|
|
||||||
collection := context.CollectionFactory().LocalRepoCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
collection.RLock()
|
collection := collectionFactory.LocalRepoCollection()
|
||||||
defer collection.RUnlock()
|
collection.ForEach(func(r *deb.LocalRepo) error {
|
||||||
|
|
||||||
context.CollectionFactory().LocalRepoCollection().ForEach(func(r *deb.LocalRepo) error {
|
|
||||||
result = append(result, r)
|
result = append(result, r)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@@ -36,7 +40,7 @@ func apiReposCreate(c *gin.Context) {
|
|||||||
DefaultComponent string
|
DefaultComponent string
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.Bind(&b) {
|
if c.Bind(&b) != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,13 +48,11 @@ func apiReposCreate(c *gin.Context) {
|
|||||||
repo.DefaultComponent = b.DefaultComponent
|
repo.DefaultComponent = b.DefaultComponent
|
||||||
repo.DefaultDistribution = b.DefaultDistribution
|
repo.DefaultDistribution = b.DefaultDistribution
|
||||||
|
|
||||||
collection := context.CollectionFactory().LocalRepoCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
collection.Lock()
|
collection := collectionFactory.LocalRepoCollection()
|
||||||
defer collection.Unlock()
|
err := collection.Add(repo)
|
||||||
|
|
||||||
err := context.CollectionFactory().LocalRepoCollection().Add(repo)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(400, err)
|
c.AbortWithError(400, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,38 +62,47 @@ func apiReposCreate(c *gin.Context) {
|
|||||||
// PUT /api/repos/:name
|
// PUT /api/repos/:name
|
||||||
func apiReposEdit(c *gin.Context) {
|
func apiReposEdit(c *gin.Context) {
|
||||||
var b struct {
|
var b struct {
|
||||||
Comment string
|
Name *string
|
||||||
DefaultDistribution string
|
Comment *string
|
||||||
DefaultComponent string
|
DefaultDistribution *string
|
||||||
|
DefaultComponent *string
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.Bind(&b) {
|
if c.Bind(&b) != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
collection := context.CollectionFactory().LocalRepoCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
collection.Lock()
|
collection := collectionFactory.LocalRepoCollection()
|
||||||
defer collection.Unlock()
|
|
||||||
|
|
||||||
repo, err := collection.ByName(c.Params.ByName("name"))
|
repo, err := collection.ByName(c.Params.ByName("name"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.Comment != "" {
|
if b.Name != nil {
|
||||||
repo.Comment = b.Comment
|
_, err := collection.ByName(*b.Name)
|
||||||
|
if err == nil {
|
||||||
|
// already exists
|
||||||
|
c.AbortWithError(404, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if b.DefaultDistribution != "" {
|
repo.Name = *b.Name
|
||||||
repo.DefaultDistribution = b.DefaultDistribution
|
|
||||||
}
|
}
|
||||||
if b.DefaultComponent != "" {
|
if b.Comment != nil {
|
||||||
repo.DefaultComponent = b.DefaultComponent
|
repo.Comment = *b.Comment
|
||||||
|
}
|
||||||
|
if b.DefaultDistribution != nil {
|
||||||
|
repo.DefaultDistribution = *b.DefaultDistribution
|
||||||
|
}
|
||||||
|
if b.DefaultComponent != nil {
|
||||||
|
repo.DefaultComponent = *b.DefaultComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
err = collection.Update(repo)
|
err = collection.Update(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,13 +111,12 @@ func apiReposEdit(c *gin.Context) {
|
|||||||
|
|
||||||
// GET /api/repos/:name
|
// GET /api/repos/:name
|
||||||
func apiReposShow(c *gin.Context) {
|
func apiReposShow(c *gin.Context) {
|
||||||
collection := context.CollectionFactory().LocalRepoCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
collection.RLock()
|
collection := collectionFactory.LocalRepoCollection()
|
||||||
defer collection.RUnlock()
|
|
||||||
|
|
||||||
repo, err := collection.ByName(c.Params.ByName("name"))
|
repo, err := collection.ByName(c.Params.ByName("name"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,143 +126,131 @@ func apiReposShow(c *gin.Context) {
|
|||||||
// DELETE /api/repos/:name
|
// DELETE /api/repos/:name
|
||||||
func apiReposDrop(c *gin.Context) {
|
func apiReposDrop(c *gin.Context) {
|
||||||
force := c.Request.URL.Query().Get("force") == "1"
|
force := c.Request.URL.Query().Get("force") == "1"
|
||||||
|
name := c.Params.ByName("name")
|
||||||
|
|
||||||
collection := context.CollectionFactory().LocalRepoCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
collection.Lock()
|
collection := collectionFactory.LocalRepoCollection()
|
||||||
defer collection.Unlock()
|
snapshotCollection := collectionFactory.SnapshotCollection()
|
||||||
|
publishedCollection := collectionFactory.PublishedRepoCollection()
|
||||||
|
|
||||||
snapshotCollection := context.CollectionFactory().SnapshotCollection()
|
repo, err := collection.ByName(name)
|
||||||
snapshotCollection.RLock()
|
|
||||||
defer snapshotCollection.RUnlock()
|
|
||||||
|
|
||||||
publishedCollection := context.CollectionFactory().PublishedRepoCollection()
|
|
||||||
publishedCollection.RLock()
|
|
||||||
defer publishedCollection.RUnlock()
|
|
||||||
|
|
||||||
repo, err := collection.ByName(c.Params.ByName("name"))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resources := []string{string(repo.Key())}
|
||||||
|
taskName := fmt.Sprintf("Delete repo %s", name)
|
||||||
|
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
published := publishedCollection.ByLocalRepo(repo)
|
published := publishedCollection.ByLocalRepo(repo)
|
||||||
if len(published) > 0 {
|
if len(published) > 0 {
|
||||||
c.Fail(409, fmt.Errorf("unable to drop, local repo is published"))
|
return &task.ProcessReturnValue{Code: http.StatusConflict, Value: nil}, fmt.Errorf("unable to drop, local repo is published")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !force {
|
if !force {
|
||||||
snapshots := snapshotCollection.ByLocalRepoSource(repo)
|
snapshots := snapshotCollection.ByLocalRepoSource(repo)
|
||||||
if len(snapshots) > 0 {
|
if len(snapshots) > 0 {
|
||||||
c.Fail(409, fmt.Errorf("unable to drop, local repo has snapshots, use ?force=1 to override"))
|
return &task.ProcessReturnValue{Code: http.StatusConflict, Value: nil}, fmt.Errorf("unable to drop, local repo has snapshots, use ?force=1 to override")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = collection.Drop(repo)
|
return &task.ProcessReturnValue{Code: http.StatusOK, Value: gin.H{}}, collection.Drop(repo)
|
||||||
if err != nil {
|
})
|
||||||
c.Fail(500, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(200, gin.H{})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET /api/repos/:name/packages
|
// GET /api/repos/:name/packages
|
||||||
func apiReposPackagesShow(c *gin.Context) {
|
func apiReposPackagesShow(c *gin.Context) {
|
||||||
collection := context.CollectionFactory().LocalRepoCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
collection.RLock()
|
collection := collectionFactory.LocalRepoCollection()
|
||||||
defer collection.RUnlock()
|
|
||||||
|
|
||||||
repo, err := collection.ByName(c.Params.ByName("name"))
|
repo, err := collection.ByName(c.Params.ByName("name"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = collection.LoadComplete(repo)
|
err = collection.LoadComplete(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
showPackages(c, repo.RefList())
|
showPackages(c, repo.RefList(), collectionFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler for both add and delete
|
// Handler for both add and delete
|
||||||
func apiReposPackagesAddDelete(c *gin.Context, cb func(list *deb.PackageList, p *deb.Package) error) {
|
func apiReposPackagesAddDelete(c *gin.Context, taskNamePrefix string, cb func(list *deb.PackageList, p *deb.Package, out aptly.Progress) error) {
|
||||||
var b struct {
|
var b struct {
|
||||||
PackageRefs []string
|
PackageRefs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.Bind(&b) {
|
if c.Bind(&b) != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
collection := context.CollectionFactory().LocalRepoCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
collection.Lock()
|
collection := collectionFactory.LocalRepoCollection()
|
||||||
defer collection.Unlock()
|
|
||||||
|
|
||||||
repo, err := collection.ByName(c.Params.ByName("name"))
|
repo, err := collection.ByName(c.Params.ByName("name"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = collection.LoadComplete(repo)
|
err = collection.LoadComplete(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := deb.NewPackageListFromRefList(repo.RefList(), context.CollectionFactory().PackageCollection(), nil)
|
resources := []string{string(repo.Key())}
|
||||||
|
maybeRunTaskInBackground(c, taskNamePrefix+repo.Name, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
|
out.Printf("Loading packages...\n")
|
||||||
|
list, err := deb.NewPackageListFromRefList(repo.RefList(), collectionFactory.PackageCollection(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify package refs and build package list
|
// verify package refs and build package list
|
||||||
for _, ref := range b.PackageRefs {
|
for _, ref := range b.PackageRefs {
|
||||||
var p *deb.Package
|
var p *deb.Package
|
||||||
|
|
||||||
p, err = context.CollectionFactory().PackageCollection().ByKey([]byte(ref))
|
p, err = collectionFactory.PackageCollection().ByKey([]byte(ref))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == database.ErrNotFound {
|
if err == database.ErrNotFound {
|
||||||
c.Fail(404, fmt.Errorf("package %s: %s", ref, err))
|
return &task.ProcessReturnValue{Code: http.StatusNotFound, Value: nil}, fmt.Errorf("packages %s: %s", ref, err)
|
||||||
} else {
|
|
||||||
c.Fail(500, err)
|
|
||||||
}
|
}
|
||||||
return
|
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, err
|
||||||
}
|
}
|
||||||
err = cb(list, p)
|
err = cb(list, p, out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(400, err)
|
return &task.ProcessReturnValue{Code: http.StatusBadRequest, Value: nil}, err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.UpdateRefList(deb.NewPackageRefListFromPackageList(list))
|
repo.UpdateRefList(deb.NewPackageRefListFromPackageList(list))
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().Update(repo)
|
err = collectionFactory.LocalRepoCollection().Update(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to save: %s", err))
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to save: %s", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusOK, Value: repo}, nil
|
||||||
c.JSON(200, repo)
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST /repos/:name/packages
|
// POST /repos/:name/packages
|
||||||
func apiReposPackagesAdd(c *gin.Context) {
|
func apiReposPackagesAdd(c *gin.Context) {
|
||||||
apiReposPackagesAddDelete(c, func(list *deb.PackageList, p *deb.Package) error {
|
apiReposPackagesAddDelete(c, "Add packages to repo ", func(list *deb.PackageList, p *deb.Package, out aptly.Progress) error {
|
||||||
|
out.Printf("Adding package %s\n", p.Name)
|
||||||
return list.Add(p)
|
return list.Add(p)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE /repos/:name/packages
|
// DELETE /repos/:name/packages
|
||||||
func apiReposPackagesDelete(c *gin.Context) {
|
func apiReposPackagesDelete(c *gin.Context) {
|
||||||
apiReposPackagesAddDelete(c, func(list *deb.PackageList, p *deb.Package) error {
|
apiReposPackagesAddDelete(c, "Delete packages from repo ", func(list *deb.PackageList, p *deb.Package, out aptly.Progress) error {
|
||||||
|
out.Printf("Removing package %s\n", p.Name)
|
||||||
list.Remove(p)
|
list.Remove(p)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@@ -273,33 +271,47 @@ func apiReposPackageFromDir(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dirParam := c.Params.ByName("dir")
|
||||||
fileParam := c.Params.ByName("file")
|
fileParam := c.Params.ByName("file")
|
||||||
if fileParam != "" && !verifyPath(fileParam) {
|
if fileParam != "" && !verifyPath(fileParam) {
|
||||||
c.Fail(400, fmt.Errorf("wrong file"))
|
c.AbortWithError(400, fmt.Errorf("wrong file"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
collection := context.CollectionFactory().LocalRepoCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
collection.Lock()
|
collection := collectionFactory.LocalRepoCollection()
|
||||||
defer collection.Unlock()
|
|
||||||
|
|
||||||
repo, err := collection.ByName(c.Params.ByName("name"))
|
name := c.Params.ByName("name")
|
||||||
|
repo, err := collection.ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = collection.LoadComplete(repo)
|
err = collection.LoadComplete(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
verifier := &utils.GpgVerifier{}
|
var taskName string
|
||||||
|
var sources []string
|
||||||
|
if fileParam == "" {
|
||||||
|
taskName = fmt.Sprintf("Add packages from dir %s to repo %s", dirParam, name)
|
||||||
|
sources = []string{filepath.Join(context.UploadPath(), dirParam)}
|
||||||
|
} else {
|
||||||
|
sources = []string{filepath.Join(context.UploadPath(), dirParam, fileParam)}
|
||||||
|
taskName = fmt.Sprintf("Add package %s from dir %s to repo %s", fileParam, dirParam, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
resources := []string{string(repo.Key())}
|
||||||
|
resources = append(resources, sources...)
|
||||||
|
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
|
verifier := context.GetVerifier()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
sources []string
|
|
||||||
packageFiles, failedFiles []string
|
packageFiles, failedFiles []string
|
||||||
|
otherFiles []string
|
||||||
processedFiles, failedFiles2 []string
|
processedFiles, failedFiles2 []string
|
||||||
reporter = &aptly.RecordingResultReporter{
|
reporter = &aptly.RecordingResultReporter{
|
||||||
Warnings: []string{},
|
Warnings: []string{},
|
||||||
@@ -309,40 +321,27 @@ func apiReposPackageFromDir(c *gin.Context) {
|
|||||||
list *deb.PackageList
|
list *deb.PackageList
|
||||||
)
|
)
|
||||||
|
|
||||||
if fileParam == "" {
|
packageFiles, otherFiles, failedFiles = deb.CollectPackageFiles(sources, reporter)
|
||||||
sources = []string{filepath.Join(context.UploadPath(), c.Params.ByName("dir"))}
|
|
||||||
} else {
|
|
||||||
sources = []string{filepath.Join(context.UploadPath(), c.Params.ByName("dir"), c.Params.ByName("file"))}
|
|
||||||
}
|
|
||||||
|
|
||||||
packageFiles, failedFiles, err = deb.CollectPackageFiles(sources, reporter)
|
|
||||||
|
|
||||||
|
list, err := deb.NewPackageListFromRefList(repo.RefList(), collectionFactory.PackageCollection(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to collect package files: %s", err))
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to load packages: %s", err)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
list, err = deb.NewPackageListFromRefList(repo.RefList(), context.CollectionFactory().PackageCollection(), nil)
|
|
||||||
if err != nil {
|
|
||||||
c.Fail(500, fmt.Errorf("unable to load packages: %s", err))
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
processedFiles, failedFiles2, err = deb.ImportPackageFiles(list, packageFiles, forceReplace, verifier, context.PackagePool(),
|
processedFiles, failedFiles2, err = deb.ImportPackageFiles(list, packageFiles, forceReplace, verifier, context.PackagePool(),
|
||||||
context.CollectionFactory().PackageCollection(), reporter)
|
collectionFactory.PackageCollection(), reporter, nil, collectionFactory.ChecksumCollection)
|
||||||
failedFiles = append(failedFiles, failedFiles2...)
|
failedFiles = append(failedFiles, failedFiles2...)
|
||||||
|
processedFiles = append(processedFiles, otherFiles...)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to import package files: %s", err))
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to import package files: %s", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.UpdateRefList(deb.NewPackageRefListFromPackageList(list))
|
repo.UpdateRefList(deb.NewPackageRefListFromPackageList(list))
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().Update(repo)
|
err = collectionFactory.LocalRepoCollection().Update(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, fmt.Errorf("unable to save: %s", err))
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to save: %s", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !noRemove {
|
if !noRemove {
|
||||||
@@ -356,15 +355,141 @@ func apiReposPackageFromDir(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// atempt to remove dir, if it fails, that's fine: probably it's not empty
|
// atempt to remove dir, if it fails, that's fine: probably it's not empty
|
||||||
os.Remove(filepath.Join(context.UploadPath(), c.Params.ByName("dir")))
|
os.Remove(filepath.Join(context.UploadPath(), dirParam))
|
||||||
}
|
}
|
||||||
|
|
||||||
if failedFiles == nil {
|
if failedFiles == nil {
|
||||||
failedFiles = []string{}
|
failedFiles = []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(200, gin.H{
|
if len(reporter.AddedLines) > 0 {
|
||||||
|
out.Printf("Added: %s\n", strings.Join(reporter.AddedLines, ", "))
|
||||||
|
}
|
||||||
|
if len(reporter.RemovedLines) > 0 {
|
||||||
|
out.Printf("Removed: %s\n", strings.Join(reporter.RemovedLines, ", "))
|
||||||
|
}
|
||||||
|
if len(reporter.Warnings) > 0 {
|
||||||
|
out.Printf("Warnings: %s\n", strings.Join(reporter.Warnings, ", "))
|
||||||
|
}
|
||||||
|
if len(failedFiles) > 0 {
|
||||||
|
out.Printf("Failed files: %s\n", strings.Join(failedFiles, ", "))
|
||||||
|
}
|
||||||
|
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusOK, Value: gin.H{
|
||||||
"Report": reporter,
|
"Report": reporter,
|
||||||
"FailedFiles": failedFiles,
|
"FailedFiles": failedFiles,
|
||||||
|
}}, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST /repos/:name/include/:dir/:file
|
||||||
|
func apiReposIncludePackageFromFile(c *gin.Context) {
|
||||||
|
// redirect all work to dir method
|
||||||
|
apiReposIncludePackageFromDir(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST /repos/:name/include/:dir
|
||||||
|
func apiReposIncludePackageFromDir(c *gin.Context) {
|
||||||
|
forceReplace := c.Request.URL.Query().Get("forceReplace") == "1"
|
||||||
|
noRemoveFiles := c.Request.URL.Query().Get("noRemoveFiles") == "1"
|
||||||
|
acceptUnsigned := c.Request.URL.Query().Get("acceptUnsigned") == "1"
|
||||||
|
ignoreSignature := c.Request.URL.Query().Get("ignoreSignature") == "1"
|
||||||
|
|
||||||
|
repoTemplateString := c.Params.ByName("name")
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
|
||||||
|
if !verifyDir(c) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var sources []string
|
||||||
|
var taskName string
|
||||||
|
dirParam := c.Params.ByName("dir")
|
||||||
|
fileParam := c.Params.ByName("file")
|
||||||
|
if fileParam != "" && !verifyPath(fileParam) {
|
||||||
|
c.AbortWithError(400, fmt.Errorf("wrong file"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if fileParam == "" {
|
||||||
|
taskName = fmt.Sprintf("Include packages from changes files in dir %s to repo matching template %s", dirParam, repoTemplateString)
|
||||||
|
sources = []string{filepath.Join(context.UploadPath(), dirParam)}
|
||||||
|
} else {
|
||||||
|
taskName = fmt.Sprintf("Include packages from changes file %s from dir %s to repo matching template %s", fileParam, dirParam, repoTemplateString)
|
||||||
|
sources = []string{filepath.Join(context.UploadPath(), dirParam, fileParam)}
|
||||||
|
}
|
||||||
|
|
||||||
|
repoTemplate, err := template.New("repo").Parse(repoTemplateString)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(400, fmt.Errorf("error parsing repo template: %s", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var resources []string
|
||||||
|
if len(repoTemplate.Tree.Root.Nodes) > 1 {
|
||||||
|
resources = append(resources, task.AllLocalReposResourcesKey)
|
||||||
|
} else {
|
||||||
|
// repo template string is simple text so only use resource key of specific repository
|
||||||
|
repo, err := collectionFactory.LocalRepoCollection().ByName(repoTemplateString)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(404, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resources = append(resources, string(repo.Key()))
|
||||||
|
}
|
||||||
|
resources = append(resources, sources...)
|
||||||
|
|
||||||
|
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
verifier = context.GetVerifier()
|
||||||
|
changesFiles []string
|
||||||
|
failedFiles, failedFiles2 []string
|
||||||
|
reporter = &aptly.RecordingResultReporter{
|
||||||
|
Warnings: []string{},
|
||||||
|
AddedLines: []string{},
|
||||||
|
RemovedLines: []string{},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
changesFiles, failedFiles = deb.CollectChangesFiles(sources, reporter)
|
||||||
|
_, failedFiles2, err = deb.ImportChangesFiles(
|
||||||
|
changesFiles, reporter, acceptUnsigned, ignoreSignature, forceReplace, noRemoveFiles, verifier,
|
||||||
|
repoTemplate, context.Progress(), collectionFactory.LocalRepoCollection(), collectionFactory.PackageCollection(),
|
||||||
|
context.PackagePool(), collectionFactory.ChecksumCollection, nil, query.Parse)
|
||||||
|
failedFiles = append(failedFiles, failedFiles2...)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to import changes files: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !noRemoveFiles {
|
||||||
|
// atempt to remove dir, if it fails, that's fine: probably it's not empty
|
||||||
|
os.Remove(filepath.Join(context.UploadPath(), dirParam))
|
||||||
|
}
|
||||||
|
|
||||||
|
if failedFiles == nil {
|
||||||
|
failedFiles = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(reporter.AddedLines) > 0 {
|
||||||
|
out.Printf("Added: %s\n", strings.Join(reporter.AddedLines, ", "))
|
||||||
|
}
|
||||||
|
if len(reporter.RemovedLines) > 0 {
|
||||||
|
out.Printf("Removed: %s\n", strings.Join(reporter.RemovedLines, ", "))
|
||||||
|
}
|
||||||
|
if len(reporter.Warnings) > 0 {
|
||||||
|
out.Printf("Warnings: %s\n", strings.Join(reporter.Warnings, ", "))
|
||||||
|
}
|
||||||
|
if len(failedFiles) > 0 {
|
||||||
|
out.Printf("Failed files: %s\n", strings.Join(failedFiles, ", "))
|
||||||
|
}
|
||||||
|
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusOK, Value: gin.H{
|
||||||
|
"Report": reporter,
|
||||||
|
"FailedFiles": failedFiles,
|
||||||
|
}}, nil
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
+85
-4
@@ -1,25 +1,75 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
ctx "github.com/smira/aptly/context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
ctx "github.com/aptly-dev/aptly/context"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var context *ctx.AptlyContext
|
var context *ctx.AptlyContext
|
||||||
|
|
||||||
|
func apiMetricsGet() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
promhttp.Handler().ServeHTTP(c.Writer, c.Request)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Router returns prebuilt with routes http.Handler
|
// Router returns prebuilt with routes http.Handler
|
||||||
func Router(c *ctx.AptlyContext) http.Handler {
|
func Router(c *ctx.AptlyContext) http.Handler {
|
||||||
context = c
|
context = c
|
||||||
|
|
||||||
go cacheFlusher()
|
|
||||||
|
|
||||||
router := gin.Default()
|
router := gin.Default()
|
||||||
|
router.UseRawPath = true
|
||||||
router.Use(gin.ErrorLogger())
|
router.Use(gin.ErrorLogger())
|
||||||
|
|
||||||
|
if c.Config().EnableMetricsEndpoint {
|
||||||
|
router.Use(instrumentHandlerInFlight(apiRequestsInFlightGauge, getBasePath))
|
||||||
|
router.Use(instrumentHandlerCounter(apiRequestsTotalCounter, getBasePath))
|
||||||
|
router.Use(instrumentHandlerRequestSize(apiRequestSizeSummary, getBasePath))
|
||||||
|
router.Use(instrumentHandlerResponseSize(apiResponseSizeSummary, getBasePath))
|
||||||
|
router.Use(instrumentHandlerDuration(apiRequestsDurationSummary, getBasePath))
|
||||||
|
}
|
||||||
|
|
||||||
|
if context.Flags().Lookup("no-lock").Value.Get().(bool) {
|
||||||
|
// We use a goroutine to count the number of
|
||||||
|
// concurrent requests. When no more requests are
|
||||||
|
// running, we close the database to free the lock.
|
||||||
|
dbRequests = make(chan dbRequest)
|
||||||
|
|
||||||
|
go acquireDatabase()
|
||||||
|
|
||||||
|
router.Use(func(c *gin.Context) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
errCh := make(chan error)
|
||||||
|
dbRequests <- dbRequest{acquiredb, errCh}
|
||||||
|
|
||||||
|
err = <-errCh
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(500, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
dbRequests <- dbRequest{releasedb, errCh}
|
||||||
|
err = <-errCh
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(500, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
c.Next()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
root := router.Group("/api")
|
root := router.Group("/api")
|
||||||
|
|
||||||
{
|
{
|
||||||
|
if c.Config().EnableMetricsEndpoint {
|
||||||
|
root.GET("/metrics", apiMetricsGet())
|
||||||
|
}
|
||||||
root.GET("/version", apiVersion)
|
root.GET("/version", apiVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,6 +87,9 @@ func Router(c *ctx.AptlyContext) http.Handler {
|
|||||||
root.POST("/repos/:name/file/:dir/:file", apiReposPackageFromFile)
|
root.POST("/repos/:name/file/:dir/:file", apiReposPackageFromFile)
|
||||||
root.POST("/repos/:name/file/:dir", apiReposPackageFromDir)
|
root.POST("/repos/:name/file/:dir", apiReposPackageFromDir)
|
||||||
|
|
||||||
|
root.POST("/repos/:name/include/:dir/:file", apiReposIncludePackageFromFile)
|
||||||
|
root.POST("/repos/:name/include/:dir", apiReposIncludePackageFromDir)
|
||||||
|
|
||||||
root.POST("/repos/:name/snapshots", apiSnapshotsCreateFromRepository)
|
root.POST("/repos/:name/snapshots", apiSnapshotsCreateFromRepository)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,6 +97,19 @@ func Router(c *ctx.AptlyContext) http.Handler {
|
|||||||
root.POST("/mirrors/:name/snapshots", apiSnapshotsCreateFromMirror)
|
root.POST("/mirrors/:name/snapshots", apiSnapshotsCreateFromMirror)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
root.GET("/mirrors", apiMirrorsList)
|
||||||
|
root.GET("/mirrors/:name", apiMirrorsShow)
|
||||||
|
root.GET("/mirrors/:name/packages", apiMirrorsPackages)
|
||||||
|
root.POST("/mirrors", apiMirrorsCreate)
|
||||||
|
root.PUT("/mirrors/:name", apiMirrorsUpdate)
|
||||||
|
root.DELETE("/mirrors/:name", apiMirrorsDrop)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
root.POST("/gpg/key", apiGPGAddKey)
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
root.GET("/files", apiFilesListDirs)
|
root.GET("/files", apiFilesListDirs)
|
||||||
root.POST("/files/:dir", apiFilesUpload)
|
root.POST("/files/:dir", apiFilesUpload)
|
||||||
@@ -77,6 +143,21 @@ func Router(c *ctx.AptlyContext) http.Handler {
|
|||||||
{
|
{
|
||||||
root.GET("/graph.:ext", apiGraph)
|
root.GET("/graph.:ext", apiGraph)
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
root.POST("/db/cleanup", apiDbCleanup)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
root.GET("/tasks", apiTasksList)
|
||||||
|
root.POST("/tasks-clear", apiTasksClear)
|
||||||
|
root.GET("/tasks-wait", apiTasksWait)
|
||||||
|
root.GET("/tasks/:id/wait", apiTasksWaitForTaskByID)
|
||||||
|
root.GET("/tasks/:id/output", apiTasksOutputShow)
|
||||||
|
root.GET("/tasks/:id/detail", apiTasksDetailShow)
|
||||||
|
root.GET("/tasks/:id/return_value", apiTasksReturnValueShow)
|
||||||
|
root.GET("/tasks/:id", apiTasksShow)
|
||||||
|
root.DELETE("/tasks/:id", apiTasksDelete)
|
||||||
|
root.POST("/tasks-dummy", apiTasksDummy)
|
||||||
|
}
|
||||||
|
|
||||||
return router
|
return router
|
||||||
}
|
}
|
||||||
|
|||||||
+103
-114
@@ -2,18 +2,21 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/aptly-dev/aptly/database"
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/task"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/smira/aptly/database"
|
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// GET /api/snapshots
|
// GET /api/snapshots
|
||||||
func apiSnapshotsList(c *gin.Context) {
|
func apiSnapshotsList(c *gin.Context) {
|
||||||
SortMethodString := c.Request.URL.Query().Get("sort")
|
SortMethodString := c.Request.URL.Query().Get("sort")
|
||||||
|
|
||||||
collection := context.CollectionFactory().SnapshotCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
collection.RLock()
|
collection := collectionFactory.SnapshotCollection()
|
||||||
defer collection.RUnlock()
|
|
||||||
|
|
||||||
if SortMethodString == "" {
|
if SortMethodString == "" {
|
||||||
SortMethodString = "name"
|
SortMethodString = "name"
|
||||||
@@ -41,40 +44,38 @@ func apiSnapshotsCreateFromMirror(c *gin.Context) {
|
|||||||
Description string
|
Description string
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.Bind(&b) {
|
if c.Bind(&b) != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
collection := context.CollectionFactory().RemoteRepoCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
collection.RLock()
|
collection := collectionFactory.RemoteRepoCollection()
|
||||||
defer collection.RUnlock()
|
snapshotCollection := collectionFactory.SnapshotCollection()
|
||||||
|
name := c.Params.ByName("name")
|
||||||
|
|
||||||
snapshotCollection := context.CollectionFactory().SnapshotCollection()
|
repo, err = collection.ByName(name)
|
||||||
snapshotCollection.Lock()
|
|
||||||
defer snapshotCollection.Unlock()
|
|
||||||
|
|
||||||
repo, err = collection.ByName(c.Params.ByName("name"))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = repo.CheckLock()
|
// including snapshot resource key
|
||||||
|
resources := []string{string(repo.Key()), "S" + b.Name}
|
||||||
|
taskName := fmt.Sprintf("Create snapshot of mirror %s", name)
|
||||||
|
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
|
err := repo.CheckLock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(409, err)
|
return &task.ProcessReturnValue{Code: http.StatusConflict, Value: nil}, err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = collection.LoadComplete(repo)
|
err = collection.LoadComplete(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshot, err = deb.NewSnapshotFromRepository(b.Name, repo)
|
snapshot, err = deb.NewSnapshotFromRepository(b.Name, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(400, err)
|
return &task.ProcessReturnValue{Code: http.StatusBadRequest, Value: nil}, err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.Description != "" {
|
if b.Description != "" {
|
||||||
@@ -83,11 +84,10 @@ func apiSnapshotsCreateFromMirror(c *gin.Context) {
|
|||||||
|
|
||||||
err = snapshotCollection.Add(snapshot)
|
err = snapshotCollection.Add(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(400, err)
|
return &task.ProcessReturnValue{Code: http.StatusBadRequest, Value: nil}, err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusCreated, Value: snapshot}, nil
|
||||||
c.JSON(201, snapshot)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST /api/snapshots
|
// POST /api/snapshots
|
||||||
@@ -104,7 +104,7 @@ func apiSnapshotsCreate(c *gin.Context) {
|
|||||||
PackageRefs []string
|
PackageRefs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.Bind(&b) {
|
if c.Bind(&b) != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,45 +114,43 @@ func apiSnapshotsCreate(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshotCollection := context.CollectionFactory().SnapshotCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
snapshotCollection.Lock()
|
snapshotCollection := collectionFactory.SnapshotCollection()
|
||||||
defer snapshotCollection.Unlock()
|
var resources []string
|
||||||
|
|
||||||
sources := make([]*deb.Snapshot, len(b.SourceSnapshots))
|
sources := make([]*deb.Snapshot, len(b.SourceSnapshots))
|
||||||
|
|
||||||
for i := range b.SourceSnapshots {
|
for i := range b.SourceSnapshots {
|
||||||
sources[i], err = snapshotCollection.ByName(b.SourceSnapshots[i])
|
sources[i], err = snapshotCollection.ByName(b.SourceSnapshots[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = snapshotCollection.LoadComplete(sources[i])
|
err = snapshotCollection.LoadComplete(sources[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resources = append(resources, string(sources[i].ResourceKey()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maybeRunTaskInBackground(c, "Create snapshot "+b.Name, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
list := deb.NewPackageList()
|
list := deb.NewPackageList()
|
||||||
|
|
||||||
// verify package refs and build package list
|
// verify package refs and build package list
|
||||||
for _, ref := range b.PackageRefs {
|
for _, ref := range b.PackageRefs {
|
||||||
var p *deb.Package
|
p, err := collectionFactory.PackageCollection().ByKey([]byte(ref))
|
||||||
|
|
||||||
p, err = context.CollectionFactory().PackageCollection().ByKey([]byte(ref))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == database.ErrNotFound {
|
if err == database.ErrNotFound {
|
||||||
c.Fail(404, fmt.Errorf("package %s: %s", ref, err))
|
return &task.ProcessReturnValue{Code: http.StatusNotFound, Value: nil}, fmt.Errorf("package %s: %s", ref, err)
|
||||||
} else {
|
|
||||||
c.Fail(500, err)
|
|
||||||
}
|
}
|
||||||
return
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, err
|
||||||
}
|
}
|
||||||
err = list.Add(p)
|
err = list.Add(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(400, err)
|
return &task.ProcessReturnValue{Code: http.StatusBadRequest, Value: nil}, err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,11 +158,10 @@ func apiSnapshotsCreate(c *gin.Context) {
|
|||||||
|
|
||||||
err = snapshotCollection.Add(snapshot)
|
err = snapshotCollection.Add(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(400, err)
|
return &task.ProcessReturnValue{Code: http.StatusBadRequest, Value: nil}, err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusCreated, Value: nil}, nil
|
||||||
c.JSON(201, snapshot)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST /api/repos/:name/snapshots
|
// POST /api/repos/:name/snapshots
|
||||||
@@ -180,34 +177,33 @@ func apiSnapshotsCreateFromRepository(c *gin.Context) {
|
|||||||
Description string
|
Description string
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.Bind(&b) {
|
if c.Bind(&b) != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
collection := context.CollectionFactory().LocalRepoCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
collection.RLock()
|
collection := collectionFactory.LocalRepoCollection()
|
||||||
defer collection.RUnlock()
|
snapshotCollection := collectionFactory.SnapshotCollection()
|
||||||
|
name := c.Params.ByName("name")
|
||||||
|
|
||||||
snapshotCollection := context.CollectionFactory().SnapshotCollection()
|
repo, err = collection.ByName(name)
|
||||||
snapshotCollection.Lock()
|
|
||||||
defer snapshotCollection.Unlock()
|
|
||||||
|
|
||||||
repo, err = collection.ByName(c.Params.ByName("name"))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = collection.LoadComplete(repo)
|
// including snapshot resource key
|
||||||
|
resources := []string{string(repo.Key()), "S" + b.Name}
|
||||||
|
taskName := fmt.Sprintf("Create snapshot of repo %s", name)
|
||||||
|
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
|
err := collection.LoadComplete(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshot, err = deb.NewSnapshotFromLocalRepo(b.Name, repo)
|
snapshot, err = deb.NewSnapshotFromLocalRepo(b.Name, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(400, err)
|
return &task.ProcessReturnValue{Code: http.StatusNotFound, Value: nil}, err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.Description != "" {
|
if b.Description != "" {
|
||||||
@@ -216,11 +212,10 @@ func apiSnapshotsCreateFromRepository(c *gin.Context) {
|
|||||||
|
|
||||||
err = snapshotCollection.Add(snapshot)
|
err = snapshotCollection.Add(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(400, err)
|
return &task.ProcessReturnValue{Code: http.StatusBadRequest, Value: nil}, err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusCreated, Value: snapshot}, nil
|
||||||
c.JSON(201, snapshot)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT /api/snapshots/:name
|
// PUT /api/snapshots/:name
|
||||||
@@ -235,24 +230,26 @@ func apiSnapshotsUpdate(c *gin.Context) {
|
|||||||
Description string
|
Description string
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.Bind(&b) {
|
if c.Bind(&b) != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
collection := context.CollectionFactory().SnapshotCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
collection.Lock()
|
collection := collectionFactory.SnapshotCollection()
|
||||||
defer collection.Unlock()
|
name := c.Params.ByName("name")
|
||||||
|
|
||||||
snapshot, err = collection.ByName(c.Params.ByName("name"))
|
snapshot, err = collection.ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = collection.ByName(b.Name)
|
resources := []string{string(snapshot.ResourceKey()), "S" + b.Name}
|
||||||
|
taskName := fmt.Sprintf("Update snapshot %s", name)
|
||||||
|
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
|
_, err := collection.ByName(b.Name)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
c.Fail(409, fmt.Errorf("unable to rename: snapshot %s already exists", b.Name))
|
return &task.ProcessReturnValue{Code: http.StatusConflict, Value: nil}, fmt.Errorf("unable to rename: snapshot %s already exists", b.Name)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.Name != "" {
|
if b.Name != "" {
|
||||||
@@ -263,30 +260,28 @@ func apiSnapshotsUpdate(c *gin.Context) {
|
|||||||
snapshot.Description = b.Description
|
snapshot.Description = b.Description
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().Update(snapshot)
|
err = collectionFactory.SnapshotCollection().Update(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusOK, Value: snapshot}, nil
|
||||||
c.JSON(200, snapshot)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET /api/snapshots/:name
|
// GET /api/snapshots/:name
|
||||||
func apiSnapshotsShow(c *gin.Context) {
|
func apiSnapshotsShow(c *gin.Context) {
|
||||||
collection := context.CollectionFactory().SnapshotCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
collection.RLock()
|
collection := collectionFactory.SnapshotCollection()
|
||||||
defer collection.RUnlock()
|
|
||||||
|
|
||||||
snapshot, err := collection.ByName(c.Params.ByName("name"))
|
snapshot, err := collection.ByName(c.Params.ByName("name"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = collection.LoadComplete(snapshot)
|
err = collection.LoadComplete(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,80 +293,75 @@ func apiSnapshotsDrop(c *gin.Context) {
|
|||||||
name := c.Params.ByName("name")
|
name := c.Params.ByName("name")
|
||||||
force := c.Request.URL.Query().Get("force") == "1"
|
force := c.Request.URL.Query().Get("force") == "1"
|
||||||
|
|
||||||
snapshotCollection := context.CollectionFactory().SnapshotCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
snapshotCollection.Lock()
|
snapshotCollection := collectionFactory.SnapshotCollection()
|
||||||
defer snapshotCollection.Unlock()
|
publishedCollection := collectionFactory.PublishedRepoCollection()
|
||||||
|
|
||||||
publishedCollection := context.CollectionFactory().PublishedRepoCollection()
|
|
||||||
publishedCollection.RLock()
|
|
||||||
defer publishedCollection.RUnlock()
|
|
||||||
|
|
||||||
snapshot, err := snapshotCollection.ByName(name)
|
snapshot, err := snapshotCollection.ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resources := []string{string(snapshot.ResourceKey())}
|
||||||
|
taskName := fmt.Sprintf("Delete snapshot %s", name)
|
||||||
|
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
published := publishedCollection.BySnapshot(snapshot)
|
published := publishedCollection.BySnapshot(snapshot)
|
||||||
|
|
||||||
if len(published) > 0 {
|
if len(published) > 0 {
|
||||||
c.Fail(409, fmt.Errorf("unable to drop: snapshot is published"))
|
return &task.ProcessReturnValue{Code: http.StatusConflict, Value: nil}, fmt.Errorf("unable to drop: snapshot is published")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !force {
|
if !force {
|
||||||
snapshots := snapshotCollection.BySnapshotSource(snapshot)
|
snapshots := snapshotCollection.BySnapshotSource(snapshot)
|
||||||
if len(snapshots) > 0 {
|
if len(snapshots) > 0 {
|
||||||
c.Fail(409, fmt.Errorf("won't delete snapshot that was used as source for other snapshots, use ?force=1 to override"))
|
return &task.ProcessReturnValue{Code: http.StatusConflict, Value: nil}, fmt.Errorf("won't delete snapshot that was used as source for other snapshots, use ?force=1 to override")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = snapshotCollection.Drop(snapshot)
|
err = snapshotCollection.Drop(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusOK, Value: gin.H{}}, nil
|
||||||
c.JSON(200, gin.H{})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET /api/snapshots/:name/diff/:withSnapshot
|
// GET /api/snapshots/:name/diff/:withSnapshot
|
||||||
func apiSnapshotsDiff(c *gin.Context) {
|
func apiSnapshotsDiff(c *gin.Context) {
|
||||||
onlyMatching := c.Request.URL.Query().Get("onlyMatching") == "1"
|
onlyMatching := c.Request.URL.Query().Get("onlyMatching") == "1"
|
||||||
|
|
||||||
collection := context.CollectionFactory().SnapshotCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
collection.RLock()
|
collection := collectionFactory.SnapshotCollection()
|
||||||
defer collection.RUnlock()
|
|
||||||
|
|
||||||
snapshotA, err := collection.ByName(c.Params.ByName("name"))
|
snapshotA, err := collection.ByName(c.Params.ByName("name"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshotB, err := collection.ByName(c.Params.ByName("withSnapshot"))
|
snapshotB, err := collection.ByName(c.Params.ByName("withSnapshot"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = collection.LoadComplete(snapshotA)
|
err = collection.LoadComplete(snapshotA)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = collection.LoadComplete(snapshotB)
|
err = collection.LoadComplete(snapshotB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate diff
|
// Calculate diff
|
||||||
diff, err := snapshotA.RefList().Diff(snapshotB.RefList(), context.CollectionFactory().PackageCollection())
|
diff, err := snapshotA.RefList().Diff(snapshotB.RefList(), collectionFactory.PackageCollection())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,21 +380,20 @@ func apiSnapshotsDiff(c *gin.Context) {
|
|||||||
|
|
||||||
// GET /api/snapshots/:name/packages
|
// GET /api/snapshots/:name/packages
|
||||||
func apiSnapshotsSearchPackages(c *gin.Context) {
|
func apiSnapshotsSearchPackages(c *gin.Context) {
|
||||||
collection := context.CollectionFactory().SnapshotCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
collection.RLock()
|
collection := collectionFactory.SnapshotCollection()
|
||||||
defer collection.RUnlock()
|
|
||||||
|
|
||||||
snapshot, err := collection.ByName(c.Params.ByName("name"))
|
snapshot, err := collection.ByName(c.Params.ByName("name"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(404, err)
|
c.AbortWithError(404, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = collection.LoadComplete(snapshot)
|
err = collection.LoadComplete(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fail(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
showPackages(c, snapshot.RefList())
|
showPackages(c, snapshot.RefList(), collectionFactory)
|
||||||
}
|
}
|
||||||
|
|||||||
+155
@@ -0,0 +1,155 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/aptly-dev/aptly/task"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GET /tasks
|
||||||
|
func apiTasksList(c *gin.Context) {
|
||||||
|
list := context.TaskList()
|
||||||
|
c.JSON(200, list.GetTasks())
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST /tasks-clear
|
||||||
|
func apiTasksClear(c *gin.Context) {
|
||||||
|
list := context.TaskList()
|
||||||
|
list.Clear()
|
||||||
|
c.JSON(200, gin.H{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /tasks-wait
|
||||||
|
func apiTasksWait(c *gin.Context) {
|
||||||
|
list := context.TaskList()
|
||||||
|
list.Wait()
|
||||||
|
c.JSON(200, gin.H{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /tasks/:id/wait
|
||||||
|
func apiTasksWaitForTaskByID(c *gin.Context) {
|
||||||
|
list := context.TaskList()
|
||||||
|
id, err := strconv.ParseInt(c.Params.ByName("id"), 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(500, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
task, err := list.WaitForTaskByID(int(id))
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(400, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(200, task)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /tasks/:id
|
||||||
|
func apiTasksShow(c *gin.Context) {
|
||||||
|
list := context.TaskList()
|
||||||
|
id, err := strconv.ParseInt(c.Params.ByName("id"), 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(500, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var task task.Task
|
||||||
|
task, err = list.GetTaskByID(int(id))
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(404, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(200, task)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /tasks/:id/output
|
||||||
|
func apiTasksOutputShow(c *gin.Context) {
|
||||||
|
list := context.TaskList()
|
||||||
|
id, err := strconv.ParseInt(c.Params.ByName("id"), 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(500, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var output string
|
||||||
|
output, err = list.GetTaskOutputByID(int(id))
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(404, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(200, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /tasks/:id/detail
|
||||||
|
func apiTasksDetailShow(c *gin.Context) {
|
||||||
|
list := context.TaskList()
|
||||||
|
id, err := strconv.ParseInt(c.Params.ByName("id"), 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(500, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var detail interface{}
|
||||||
|
detail, err = list.GetTaskDetailByID(int(id))
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(404, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(200, detail)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /tasks/:id/return_value
|
||||||
|
func apiTasksReturnValueShow(c *gin.Context) {
|
||||||
|
list := context.TaskList()
|
||||||
|
id, err := strconv.ParseInt(c.Params.ByName("id"), 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(500, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err := list.GetTaskReturnValueByID(int(id))
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(404, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(200, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DELETE /tasks/:id
|
||||||
|
func apiTasksDelete(c *gin.Context) {
|
||||||
|
list := context.TaskList()
|
||||||
|
id, err := strconv.ParseInt(c.Params.ByName("id"), 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(500, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var delTask task.Task
|
||||||
|
delTask, err = list.DeleteTaskByID(int(id))
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(400, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(200, delTask)
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST /tasks-dummy
|
||||||
|
func apiTasksDummy(c *gin.Context) {
|
||||||
|
resources := []string{"dummy"}
|
||||||
|
taskName := fmt.Sprintf("Dummy task")
|
||||||
|
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) {
|
||||||
|
out.Printf("Dummy task started\n")
|
||||||
|
detail.Store([]int{1, 2, 3})
|
||||||
|
out.Printf("Dummy task finished\n")
|
||||||
|
return &task.ProcessReturnValue{Code: http.StatusTeapot, Value: []int{1, 2, 3}}, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/task"
|
||||||
|
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TaskSuite struct {
|
||||||
|
ApiSuite
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = Suite(&TaskSuite{})
|
||||||
|
|
||||||
|
func (s *TaskSuite) TestTasksDummy(c *C) {
|
||||||
|
response, _ := s.HTTPRequest("POST", "/api/tasks-dummy", nil)
|
||||||
|
c.Check(response.Code, Equals, 418)
|
||||||
|
c.Check(response.Body.String(), Equals, "[1,2,3]")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TaskSuite) TestTasksDummyAsync(c *C) {
|
||||||
|
response, _ := s.HTTPRequest("POST", "/api/tasks-dummy?_async=true", nil)
|
||||||
|
c.Check(response.Code, Equals, 202)
|
||||||
|
var t task.Task
|
||||||
|
err := json.Unmarshal(response.Body.Bytes(), &t)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Check(t.Name, Equals, "Dummy task")
|
||||||
|
response, _ = s.HTTPRequest("GET", fmt.Sprintf("/api/tasks/%d/wait", t.ID), nil)
|
||||||
|
err = json.Unmarshal(response.Body.Bytes(), &t)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Check(t.State, Equals, task.SUCCEEDED)
|
||||||
|
response, _ = s.HTTPRequest("GET", fmt.Sprintf("/api/tasks/%d/detail", t.ID), nil)
|
||||||
|
c.Check(response.Code, Equals, 200)
|
||||||
|
c.Check(response.Body.String(), Equals, "[1,2,3]")
|
||||||
|
response, _ = s.HTTPRequest("GET", fmt.Sprintf("/api/tasks/%d/output", t.ID), nil)
|
||||||
|
c.Check(response.Code, Equals, 200)
|
||||||
|
c.Check(response.Body.String(), Matches, "\"Dummy task started.*")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TaskSuite) TestTaskDelete(c *C) {
|
||||||
|
response, _ := s.HTTPRequest("POST", "/api/tasks-dummy?_async=true", nil)
|
||||||
|
c.Check(response.Code, Equals, 202)
|
||||||
|
c.Check(response.Body.String(), Equals, "{\"Name\":\"Dummy task\",\"ID\":1,\"State\":0}")
|
||||||
|
// Give the task time to start
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
response, _ = s.HTTPRequest("DELETE", "/api/tasks/1", nil)
|
||||||
|
c.Check(response.Code, Equals, 200)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TaskSuite) TestTasksClear(c *C) {
|
||||||
|
response, _ := s.HTTPRequest("POST", "/api/tasks-dummy?_async=true", nil)
|
||||||
|
c.Check(response.Code, Equals, 202)
|
||||||
|
var t task.Task
|
||||||
|
err := json.Unmarshal(response.Body.Bytes(), &t)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Check(t.Name, Equals, "Dummy task")
|
||||||
|
response, _ = s.HTTPRequest("GET", "/api/tasks-wait", nil)
|
||||||
|
c.Check(response.Code, Equals, 200)
|
||||||
|
response, _ = s.HTTPRequest("GET", "/api/tasks", nil)
|
||||||
|
c.Check(response.Code, Equals, 200)
|
||||||
|
var ts []task.Task
|
||||||
|
err = json.Unmarshal(response.Body.Bytes(), &ts)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Check(len(ts), Equals, 1)
|
||||||
|
c.Check(ts[0].State, Equals, task.SUCCEEDED)
|
||||||
|
response, _ = s.HTTPRequest("POST", "/api/tasks-clear", nil)
|
||||||
|
c.Check(response.Code, Equals, 200)
|
||||||
|
response, _ = s.HTTPRequest("GET", "/api/tasks", nil)
|
||||||
|
c.Check(response.Code, Equals, 200)
|
||||||
|
c.Check(response.Body.String(), Equals, "null")
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=APT repository API
|
||||||
|
After=network.target
|
||||||
|
Documentation=man:aptly(1)
|
||||||
|
Documentation=https://www.aptly.info/doc/api/
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/bin/aptly api serve -no-lock -listen=127.0.0.1:8081
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=APT repository server
|
||||||
|
After=network.target
|
||||||
|
Documentation=man:aptly(1)
|
||||||
|
Documentation=https://www.aptly.info/doc/commands/
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/bin/aptly serve -listen=127.0.0.1:8080
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
+102
-22
@@ -3,24 +3,60 @@
|
|||||||
package aptly
|
package aptly
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/smira/aptly/utils"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/database"
|
||||||
|
"github.com/aptly-dev/aptly/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ReadSeekerCloser = ReadSeeker + Closer
|
||||||
|
type ReadSeekerCloser interface {
|
||||||
|
io.ReadSeeker
|
||||||
|
io.Closer
|
||||||
|
}
|
||||||
|
|
||||||
// PackagePool is asbtraction of package pool storage.
|
// PackagePool is asbtraction of package pool storage.
|
||||||
//
|
//
|
||||||
// PackagePool stores all the package files, deduplicating them.
|
// PackagePool stores all the package files, deduplicating them.
|
||||||
type PackagePool interface {
|
type PackagePool interface {
|
||||||
// Path returns full path to package file in pool given any name and hash of file contents
|
// Verify checks whether file exists in the pool and fills back checksum info
|
||||||
Path(filename string, hashMD5 string) (string, error)
|
//
|
||||||
// RelativePath returns path relative to pool's root for package files given MD5 and original filename
|
// if poolPath is empty, poolPath is generated automatically based on checksum info (if available)
|
||||||
RelativePath(filename string, hashMD5 string) (string, error)
|
// in any case, if function returns true, it also fills back checksums with complete information about the file in the pool
|
||||||
|
Verify(poolPath, basename string, checksums *utils.ChecksumInfo, checksumStorage ChecksumStorage) (string, bool, error)
|
||||||
|
// Import copies file into package pool
|
||||||
|
//
|
||||||
|
// - srcPath is full path to source file as it is now
|
||||||
|
// - basename is desired human-readable name (canonical filename)
|
||||||
|
// - checksums are used to calculate file placement
|
||||||
|
// - move indicates whether srcPath can be removed
|
||||||
|
Import(srcPath, basename string, checksums *utils.ChecksumInfo, move bool, storage ChecksumStorage) (path string, err error)
|
||||||
|
// LegacyPath returns legacy (pre 1.1) path to package file (relative to root)
|
||||||
|
LegacyPath(filename string, checksums *utils.ChecksumInfo) (string, error)
|
||||||
|
// Stat returns Unix stat(2) info
|
||||||
|
Stat(path string) (os.FileInfo, error)
|
||||||
|
// Open returns ReadSeekerCloser to access the file
|
||||||
|
Open(path string) (ReadSeekerCloser, error)
|
||||||
// FilepathList returns file paths of all the files in the pool
|
// FilepathList returns file paths of all the files in the pool
|
||||||
FilepathList(progress Progress) ([]string, error)
|
FilepathList(progress Progress) ([]string, error)
|
||||||
// Remove deletes file in package pool returns its size
|
// Remove deletes file in package pool returns its size
|
||||||
Remove(path string) (size int64, err error)
|
Remove(path string) (size int64, err error)
|
||||||
// Import copies file into package pool
|
}
|
||||||
Import(path string, hashMD5 string) error
|
|
||||||
|
// LocalPackagePool is implemented by PackagePools residing on the same filesystem
|
||||||
|
type LocalPackagePool interface {
|
||||||
|
// GenerateTempPath generates temporary path for download (which is fast to import into package pool later on)
|
||||||
|
GenerateTempPath(filename string) (string, error)
|
||||||
|
// Link generates hardlink to destination path
|
||||||
|
Link(path, dstPath string) error
|
||||||
|
// Symlink generates symlink to destination path
|
||||||
|
Symlink(path, dstPath string) error
|
||||||
|
// FullPath generates full path to the file in pool
|
||||||
|
//
|
||||||
|
// Please use with care: it's not supposed to be used to access files
|
||||||
|
FullPath(path string) string
|
||||||
}
|
}
|
||||||
|
|
||||||
// PublishedStorage is abstraction of filesystem storing all published repositories
|
// PublishedStorage is abstraction of filesystem storing all published repositories
|
||||||
@@ -34,15 +70,23 @@ type PublishedStorage interface {
|
|||||||
// Remove removes single file under public path
|
// Remove removes single file under public path
|
||||||
Remove(path string) error
|
Remove(path string) error
|
||||||
// LinkFromPool links package file from pool to dist's pool location
|
// LinkFromPool links package file from pool to dist's pool location
|
||||||
LinkFromPool(publishedDirectory string, sourcePool PackagePool, sourcePath, sourceMD5 string, force bool) error
|
LinkFromPool(publishedDirectory, fileName string, sourcePool PackagePool, sourcePath string, sourceChecksums utils.ChecksumInfo, force bool) error
|
||||||
// Filelist returns list of files under prefix
|
// Filelist returns list of files under prefix
|
||||||
Filelist(prefix string) ([]string, error)
|
Filelist(prefix string) ([]string, error)
|
||||||
// RenameFile renames (moves) file
|
// RenameFile renames (moves) file
|
||||||
RenameFile(oldName, newName string) error
|
RenameFile(oldName, newName string) error
|
||||||
|
// SymLink creates a symbolic link, which can be read with ReadLink
|
||||||
|
SymLink(src string, dst string) error
|
||||||
|
// HardLink creates a hardlink of a file
|
||||||
|
HardLink(src string, dst string) error
|
||||||
|
// FileExists returns true if path exists
|
||||||
|
FileExists(path string) (bool, error)
|
||||||
|
// ReadLink returns the symbolic link pointed to by path
|
||||||
|
ReadLink(path string) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocalPublishedStorage is published storage on local filesystem
|
// FileSystemPublishedStorage is published storage on filesystem
|
||||||
type LocalPublishedStorage interface {
|
type FileSystemPublishedStorage interface {
|
||||||
// PublicPath returns root of public part
|
// PublicPath returns root of public part
|
||||||
PublicPath() string
|
PublicPath() string
|
||||||
}
|
}
|
||||||
@@ -53,6 +97,36 @@ type PublishedStorageProvider interface {
|
|||||||
GetPublishedStorage(name string) PublishedStorage
|
GetPublishedStorage(name string) PublishedStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BarType used to differentiate between different progress bars
|
||||||
|
type BarType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
// BarGeneralBuildPackageList identifies bar for building package list
|
||||||
|
BarGeneralBuildPackageList BarType = iota
|
||||||
|
// BarGeneralVerifyDependencies identifies bar for verifying dependencies
|
||||||
|
BarGeneralVerifyDependencies
|
||||||
|
// BarGeneralBuildFileList identifies bar for building file list
|
||||||
|
BarGeneralBuildFileList
|
||||||
|
// BarCleanupBuildList identifies bar for building list to cleanup
|
||||||
|
BarCleanupBuildList
|
||||||
|
// BarCleanupDeleteUnreferencedFiles identifies bar for deleting unreferenced files
|
||||||
|
BarCleanupDeleteUnreferencedFiles
|
||||||
|
// BarMirrorUpdateDownloadIndexes identifies bar for downloading index files
|
||||||
|
BarMirrorUpdateDownloadIndexes
|
||||||
|
// BarMirrorUpdateDownloadPackages identifies bar for downloading packages
|
||||||
|
BarMirrorUpdateDownloadPackages
|
||||||
|
// BarMirrorUpdateBuildPackageList identifies bar for building package list of downloaded files
|
||||||
|
BarMirrorUpdateBuildPackageList
|
||||||
|
// BarMirrorUpdateImportFiles identifies bar for importing package files
|
||||||
|
BarMirrorUpdateImportFiles
|
||||||
|
// BarMirrorUpdateFinalizeDownload identifies bar for finalizing downloads
|
||||||
|
BarMirrorUpdateFinalizeDownload
|
||||||
|
// BarPublishGeneratePackageFiles identifies bar for generating package files to publish
|
||||||
|
BarPublishGeneratePackageFiles
|
||||||
|
// BarPublishFinalizeIndexes identifies bar for finalizing index files
|
||||||
|
BarPublishFinalizeIndexes
|
||||||
|
)
|
||||||
|
|
||||||
// Progress is a progress displaying entity, it allows progress bars & simple prints
|
// Progress is a progress displaying entity, it allows progress bars & simple prints
|
||||||
type Progress interface {
|
type Progress interface {
|
||||||
// Writer interface to support progress bar ticking
|
// Writer interface to support progress bar ticking
|
||||||
@@ -64,7 +138,7 @@ type Progress interface {
|
|||||||
// Flush returns when all queued messages are sent
|
// Flush returns when all queued messages are sent
|
||||||
Flush()
|
Flush()
|
||||||
// InitBar starts progressbar for count bytes or count items
|
// InitBar starts progressbar for count bytes or count items
|
||||||
InitBar(count int64, isBytes bool)
|
InitBar(count int64, isBytes bool, barType BarType)
|
||||||
// ShutdownBar stops progress bar and hides it
|
// ShutdownBar stops progress bar and hides it
|
||||||
ShutdownBar()
|
ShutdownBar()
|
||||||
// AddBar increments progress for progress bar
|
// AddBar increments progress for progress bar
|
||||||
@@ -75,23 +149,29 @@ type Progress interface {
|
|||||||
Printf(msg string, a ...interface{})
|
Printf(msg string, a ...interface{})
|
||||||
// ColoredPrintf does printf in colored way + newline
|
// ColoredPrintf does printf in colored way + newline
|
||||||
ColoredPrintf(msg string, a ...interface{})
|
ColoredPrintf(msg string, a ...interface{})
|
||||||
|
// PrintfStdErr does printf but in safe manner to stderr
|
||||||
|
PrintfStdErr(msg string, a ...interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Downloader is parallel HTTP fetcher
|
// Downloader is parallel HTTP fetcher
|
||||||
type Downloader interface {
|
type Downloader interface {
|
||||||
// Download starts new download task
|
// Download starts new download task
|
||||||
Download(url string, destination string, result chan<- error)
|
Download(ctx context.Context, url string, destination string) error
|
||||||
// DownloadWithChecksum starts new download task with checksum verification
|
// DownloadWithChecksum starts new download task with checksum verification
|
||||||
DownloadWithChecksum(url string, destination string, result chan<- error, expected utils.ChecksumInfo, ignoreMismatch bool)
|
DownloadWithChecksum(ctx context.Context, url string, destination string, expected *utils.ChecksumInfo, ignoreMismatch bool) error
|
||||||
// Pause pauses task processing
|
|
||||||
Pause()
|
|
||||||
// Resume resumes task processing
|
|
||||||
Resume()
|
|
||||||
// Shutdown stops downloader after current tasks are finished,
|
|
||||||
// but doesn't process rest of queue
|
|
||||||
Shutdown()
|
|
||||||
// Abort stops downloader without waiting for shutdown
|
|
||||||
Abort()
|
|
||||||
// GetProgress returns Progress object
|
// GetProgress returns Progress object
|
||||||
GetProgress() Progress
|
GetProgress() Progress
|
||||||
|
// GetLength returns size by heading object with url
|
||||||
|
GetLength(ctx context.Context, url string) (int64, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChecksumStorageProvider creates ChecksumStorage based on DB
|
||||||
|
type ChecksumStorageProvider func(db database.ReaderWriter) ChecksumStorage
|
||||||
|
|
||||||
|
// ChecksumStorage is stores checksums in some (persistent) storage
|
||||||
|
type ChecksumStorage interface {
|
||||||
|
// Get finds checksums in DB by path
|
||||||
|
Get(path string) (*utils.ChecksumInfo, error)
|
||||||
|
// Update adds or updates information about checksum in DB
|
||||||
|
Update(path string, c *utils.ChecksumInfo) error
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
package aptly
|
package aptly
|
||||||
|
|
||||||
// Version of aptly
|
// Version of aptly (filled in at link time)
|
||||||
const Version = "0.9.1"
|
var Version string
|
||||||
|
|
||||||
// Enable debugging features?
|
// EnableDebug triggers some debugging features
|
||||||
const EnableDebug = false
|
const EnableDebug = false
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// Package azure handles publishing to Azure Storage
|
||||||
|
package azure
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package azure
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Launch gocheck tests
|
||||||
|
func Test(t *testing.T) {
|
||||||
|
TestingT(t)
|
||||||
|
}
|
||||||
+375
@@ -0,0 +1,375 @@
|
|||||||
|
package azure
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/Azure/azure-storage-blob-go/azblob"
|
||||||
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/aptly-dev/aptly/utils"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PublishedStorage abstract file system with published files (actually hosted on Azure)
|
||||||
|
type PublishedStorage struct {
|
||||||
|
container azblob.ContainerURL
|
||||||
|
prefix string
|
||||||
|
pathCache map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check interface
|
||||||
|
var (
|
||||||
|
_ aptly.PublishedStorage = (*PublishedStorage)(nil)
|
||||||
|
)
|
||||||
|
|
||||||
|
func isEmulatorEndpoint(endpoint string) bool {
|
||||||
|
if h, _, err := net.SplitHostPort(endpoint); err == nil {
|
||||||
|
endpoint = h
|
||||||
|
}
|
||||||
|
if endpoint == "localhost" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// For IPv6, there could be case where SplitHostPort fails for cannot finding port.
|
||||||
|
// In this case, eliminate the '[' and ']' in the URL.
|
||||||
|
// For details about IPv6 URL, please refer to https://tools.ietf.org/html/rfc2732
|
||||||
|
if endpoint[0] == '[' && endpoint[len(endpoint)-1] == ']' {
|
||||||
|
endpoint = endpoint[1 : len(endpoint)-1]
|
||||||
|
}
|
||||||
|
return net.ParseIP(endpoint) != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPublishedStorage creates published storage from Azure storage credentials
|
||||||
|
func NewPublishedStorage(accountName, accountKey, container, prefix, endpoint string) (*PublishedStorage, error) {
|
||||||
|
credential, err := azblob.NewSharedKeyCredential(accountName, accountKey)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if endpoint == "" {
|
||||||
|
endpoint = "blob.core.windows.net"
|
||||||
|
}
|
||||||
|
|
||||||
|
var url *url.URL
|
||||||
|
if isEmulatorEndpoint(endpoint) {
|
||||||
|
url, err = url.Parse(fmt.Sprintf("http://%s/%s/%s", endpoint, accountName, container))
|
||||||
|
} else {
|
||||||
|
url, err = url.Parse(fmt.Sprintf("https://%s.%s/%s", accountName, endpoint, container))
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
containerURL := azblob.NewContainerURL(*url, azblob.NewPipeline(credential, azblob.PipelineOptions{}))
|
||||||
|
|
||||||
|
result := &PublishedStorage{
|
||||||
|
container: containerURL,
|
||||||
|
prefix: prefix,
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// String
|
||||||
|
func (storage *PublishedStorage) String() string {
|
||||||
|
return fmt.Sprintf("Azure: %s/%s", storage.container, storage.prefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MkDir creates directory recursively under public path
|
||||||
|
func (storage *PublishedStorage) MkDir(path string) error {
|
||||||
|
// no op for Azure
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutFile puts file into published storage at specified path
|
||||||
|
func (storage *PublishedStorage) PutFile(path string, sourceFilename string) error {
|
||||||
|
var (
|
||||||
|
source *os.File
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
sourceMD5, err := utils.MD5ChecksumForFile(sourceFilename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
source, err = os.Open(sourceFilename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer source.Close()
|
||||||
|
|
||||||
|
err = storage.putFile(path, source, sourceMD5)
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Wrap(err, fmt.Sprintf("error uploading %s to %s", sourceFilename, storage))
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// putFile uploads file-like object to
|
||||||
|
func (storage *PublishedStorage) putFile(path string, source io.Reader, sourceMD5 string) error {
|
||||||
|
path = filepath.Join(storage.prefix, path)
|
||||||
|
|
||||||
|
blob := storage.container.NewBlockBlobURL(path)
|
||||||
|
|
||||||
|
uploadOptions := azblob.UploadStreamToBlockBlobOptions{
|
||||||
|
BufferSize: 4 * 1024 * 1024,
|
||||||
|
MaxBuffers: 8,
|
||||||
|
}
|
||||||
|
if len(sourceMD5) > 0 {
|
||||||
|
decodedMD5, err := hex.DecodeString(sourceMD5)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
uploadOptions.BlobHTTPHeaders = azblob.BlobHTTPHeaders{
|
||||||
|
ContentMD5: decodedMD5,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := azblob.UploadStreamToBlockBlob(
|
||||||
|
context.Background(),
|
||||||
|
source,
|
||||||
|
blob,
|
||||||
|
uploadOptions,
|
||||||
|
)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveDirs removes directory structure under public path
|
||||||
|
func (storage *PublishedStorage) RemoveDirs(path string, progress aptly.Progress) error {
|
||||||
|
filelist, err := storage.Filelist(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, filename := range filelist {
|
||||||
|
blob := storage.container.NewBlobURL(filepath.Join(storage.prefix, path, filename))
|
||||||
|
_, err := blob.Delete(context.Background(), azblob.DeleteSnapshotsOptionNone, azblob.BlobAccessConditions{})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error deleting path %s from %s: %s", filename, storage, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove removes single file under public path
|
||||||
|
func (storage *PublishedStorage) Remove(path string) error {
|
||||||
|
blob := storage.container.NewBlobURL(filepath.Join(storage.prefix, path))
|
||||||
|
_, err := blob.Delete(context.Background(), azblob.DeleteSnapshotsOptionNone, azblob.BlobAccessConditions{})
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Wrap(err, fmt.Sprintf("error deleting %s from %s: %s", path, storage, err))
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkFromPool links package file from pool to dist's pool location
|
||||||
|
//
|
||||||
|
// publishedDirectory is desired location in pool (like prefix/pool/component/liba/libav/)
|
||||||
|
// sourcePool is instance of aptly.PackagePool
|
||||||
|
// sourcePath is filepath to package file in package pool
|
||||||
|
//
|
||||||
|
// LinkFromPool returns relative path for the published file to be included in package index
|
||||||
|
func (storage *PublishedStorage) LinkFromPool(publishedDirectory, fileName string, sourcePool aptly.PackagePool,
|
||||||
|
sourcePath string, sourceChecksums utils.ChecksumInfo, force bool) error {
|
||||||
|
|
||||||
|
relPath := filepath.Join(publishedDirectory, fileName)
|
||||||
|
poolPath := filepath.Join(storage.prefix, relPath)
|
||||||
|
|
||||||
|
if storage.pathCache == nil {
|
||||||
|
paths, md5s, err := storage.internalFilelist("")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error caching paths under prefix: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
storage.pathCache = make(map[string]string, len(paths))
|
||||||
|
|
||||||
|
for i := range paths {
|
||||||
|
storage.pathCache[paths[i]] = md5s[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
destinationMD5, exists := storage.pathCache[relPath]
|
||||||
|
sourceMD5 := sourceChecksums.MD5
|
||||||
|
|
||||||
|
if exists {
|
||||||
|
if sourceMD5 == "" {
|
||||||
|
return fmt.Errorf("unable to compare object, MD5 checksum missing")
|
||||||
|
}
|
||||||
|
|
||||||
|
if destinationMD5 == sourceMD5 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if !force && destinationMD5 != sourceMD5 {
|
||||||
|
return fmt.Errorf("error putting file to %s: file already exists and is different: %s", poolPath, storage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
source, err := sourcePool.Open(sourcePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer source.Close()
|
||||||
|
|
||||||
|
err = storage.putFile(relPath, source, sourceMD5)
|
||||||
|
if err == nil {
|
||||||
|
storage.pathCache[relPath] = sourceMD5
|
||||||
|
} else {
|
||||||
|
err = errors.Wrap(err, fmt.Sprintf("error uploading %s to %s: %s", sourcePath, storage, poolPath))
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (storage *PublishedStorage) internalFilelist(prefix string) (paths []string, md5s []string, err error) {
|
||||||
|
const delimiter = "/"
|
||||||
|
paths = make([]string, 0, 1024)
|
||||||
|
md5s = make([]string, 0, 1024)
|
||||||
|
prefix = filepath.Join(storage.prefix, prefix)
|
||||||
|
if prefix != "" {
|
||||||
|
prefix += delimiter
|
||||||
|
}
|
||||||
|
|
||||||
|
for marker := (azblob.Marker{}); marker.NotDone(); {
|
||||||
|
listBlob, err := storage.container.ListBlobsFlatSegment(
|
||||||
|
context.Background(), marker, azblob.ListBlobsSegmentOptions{
|
||||||
|
Prefix: prefix,
|
||||||
|
MaxResults: 1000,
|
||||||
|
Details: azblob.BlobListingDetails{Metadata: true}})
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, fmt.Errorf("error listing under prefix %s in %s: %s", prefix, storage, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
marker = listBlob.NextMarker
|
||||||
|
|
||||||
|
for _, blob := range listBlob.Segment.BlobItems {
|
||||||
|
if prefix == "" {
|
||||||
|
paths = append(paths, blob.Name)
|
||||||
|
} else {
|
||||||
|
paths = append(paths, blob.Name[len(prefix):])
|
||||||
|
}
|
||||||
|
md5s = append(md5s, fmt.Sprintf("%x", blob.Properties.ContentMD5))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return paths, md5s, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filelist returns list of files under prefix
|
||||||
|
func (storage *PublishedStorage) Filelist(prefix string) ([]string, error) {
|
||||||
|
paths, _, err := storage.internalFilelist(prefix)
|
||||||
|
return paths, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Internal copy or move implementation
|
||||||
|
func (storage *PublishedStorage) internalCopyOrMoveBlob(src, dst string, metadata azblob.Metadata, move bool) error {
|
||||||
|
const leaseDuration = 30
|
||||||
|
|
||||||
|
dstBlobURL := storage.container.NewBlobURL(filepath.Join(storage.prefix, dst))
|
||||||
|
srcBlobURL := storage.container.NewBlobURL(filepath.Join(storage.prefix, src))
|
||||||
|
leaseResp, err := srcBlobURL.AcquireLease(context.Background(), "", leaseDuration, azblob.ModifiedAccessConditions{})
|
||||||
|
if err != nil || leaseResp.StatusCode() != http.StatusCreated {
|
||||||
|
return fmt.Errorf("error acquiring lease on source blob %s", srcBlobURL)
|
||||||
|
}
|
||||||
|
defer srcBlobURL.BreakLease(context.Background(), azblob.LeaseBreakNaturally, azblob.ModifiedAccessConditions{})
|
||||||
|
srcBlobLeaseID := leaseResp.LeaseID()
|
||||||
|
|
||||||
|
copyResp, err := dstBlobURL.StartCopyFromURL(
|
||||||
|
context.Background(),
|
||||||
|
srcBlobURL.URL(),
|
||||||
|
metadata,
|
||||||
|
azblob.ModifiedAccessConditions{},
|
||||||
|
azblob.BlobAccessConditions{},
|
||||||
|
azblob.DefaultAccessTier,
|
||||||
|
nil)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error copying %s -> %s in %s: %s", src, dst, storage, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
copyStatus := copyResp.CopyStatus()
|
||||||
|
for {
|
||||||
|
if copyStatus == azblob.CopyStatusSuccess {
|
||||||
|
if move {
|
||||||
|
_, err = srcBlobURL.Delete(
|
||||||
|
context.Background(),
|
||||||
|
azblob.DeleteSnapshotsOptionNone,
|
||||||
|
azblob.BlobAccessConditions{
|
||||||
|
LeaseAccessConditions: azblob.LeaseAccessConditions{LeaseID: srcBlobLeaseID},
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
} else if copyStatus == azblob.CopyStatusPending {
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
blobPropsResp, err := dstBlobURL.GetProperties(
|
||||||
|
context.Background(),
|
||||||
|
azblob.BlobAccessConditions{LeaseAccessConditions: azblob.LeaseAccessConditions{LeaseID: srcBlobLeaseID}},
|
||||||
|
azblob.ClientProvidedKeyOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error getting destination blob properties %s", dstBlobURL)
|
||||||
|
}
|
||||||
|
copyStatus = blobPropsResp.CopyStatus()
|
||||||
|
|
||||||
|
_, err = srcBlobURL.RenewLease(context.Background(), srcBlobLeaseID, azblob.ModifiedAccessConditions{})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error renewing source blob lease %s", srcBlobURL)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("error copying %s -> %s in %s: %s", dst, src, storage, copyStatus)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RenameFile renames (moves) file
|
||||||
|
func (storage *PublishedStorage) RenameFile(oldName, newName string) error {
|
||||||
|
return storage.internalCopyOrMoveBlob(oldName, newName, nil, true /* move */)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SymLink creates a copy of src file and adds link information as meta data
|
||||||
|
func (storage *PublishedStorage) SymLink(src string, dst string) error {
|
||||||
|
return storage.internalCopyOrMoveBlob(src, dst, azblob.Metadata{"SymLink": src}, false /* move */)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HardLink using symlink functionality as hard links do not exist
|
||||||
|
func (storage *PublishedStorage) HardLink(src string, dst string) error {
|
||||||
|
return storage.SymLink(src, dst)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FileExists returns true if path exists
|
||||||
|
func (storage *PublishedStorage) FileExists(path string) (bool, error) {
|
||||||
|
blob := storage.container.NewBlobURL(filepath.Join(storage.prefix, path))
|
||||||
|
resp, err := blob.GetProperties(context.Background(), azblob.BlobAccessConditions{}, azblob.ClientProvidedKeyOptions{})
|
||||||
|
if err != nil {
|
||||||
|
storageError, ok := err.(azblob.StorageError)
|
||||||
|
if ok && string(storageError.ServiceCode()) == string(azblob.StorageErrorCodeBlobNotFound) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return false, err
|
||||||
|
} else if resp.StatusCode() == http.StatusOK {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return false, fmt.Errorf("error checking if blob %s exists %d", blob, resp.StatusCode())
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadLink returns the symbolic link pointed to by path.
|
||||||
|
// This simply reads text file created with SymLink
|
||||||
|
func (storage *PublishedStorage) ReadLink(path string) (string, error) {
|
||||||
|
blob := storage.container.NewBlobURL(filepath.Join(storage.prefix, path))
|
||||||
|
resp, err := blob.GetProperties(context.Background(), azblob.BlobAccessConditions{}, azblob.ClientProvidedKeyOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
} else if resp.StatusCode() != http.StatusOK {
|
||||||
|
return "", fmt.Errorf("error checking if blob %s exists %d", blob, resp.StatusCode())
|
||||||
|
}
|
||||||
|
return resp.NewMetadata()["SymLink"], nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,371 @@
|
|||||||
|
package azure
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/md5"
|
||||||
|
"crypto/rand"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/Azure/azure-storage-blob-go/azblob"
|
||||||
|
"github.com/aptly-dev/aptly/files"
|
||||||
|
"github.com/aptly-dev/aptly/utils"
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PublishedStorageSuite struct {
|
||||||
|
accountName, accountKey, endpoint string
|
||||||
|
storage, prefixedStorage *PublishedStorage
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = Suite(&PublishedStorageSuite{})
|
||||||
|
|
||||||
|
const testContainerPrefix = "aptlytest-"
|
||||||
|
|
||||||
|
func randContainer() string {
|
||||||
|
return testContainerPrefix + randString(32-len(testContainerPrefix))
|
||||||
|
}
|
||||||
|
|
||||||
|
func randString(n int) string {
|
||||||
|
if n <= 0 {
|
||||||
|
panic("negative number")
|
||||||
|
}
|
||||||
|
const alphanum = "0123456789abcdefghijklmnopqrstuvwxyz"
|
||||||
|
var bytes = make([]byte, n)
|
||||||
|
rand.Read(bytes)
|
||||||
|
for i, b := range bytes {
|
||||||
|
bytes[i] = alphanum[b%byte(len(alphanum))]
|
||||||
|
}
|
||||||
|
return string(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) SetUpSuite(c *C) {
|
||||||
|
s.accountName = os.Getenv("AZURE_STORAGE_ACCOUNT")
|
||||||
|
if s.accountName == "" {
|
||||||
|
println("Please set the the following two environment variables to run the Azure storage tests.")
|
||||||
|
println(" 1. AZURE_STORAGE_ACCOUNT")
|
||||||
|
println(" 2. AZURE_STORAGE_ACCESS_KEY")
|
||||||
|
c.Skip("AZURE_STORAGE_ACCOUNT not set.")
|
||||||
|
}
|
||||||
|
s.accountKey = os.Getenv("AZURE_STORAGE_ACCESS_KEY")
|
||||||
|
if s.accountKey == "" {
|
||||||
|
println("Please set the the following two environment variables to run the Azure storage tests.")
|
||||||
|
println(" 1. AZURE_STORAGE_ACCOUNT")
|
||||||
|
println(" 2. AZURE_STORAGE_ACCESS_KEY")
|
||||||
|
c.Skip("AZURE_STORAGE_ACCESS_KEY not set.")
|
||||||
|
}
|
||||||
|
s.endpoint = os.Getenv("AZURE_STORAGE_ENDPOINT")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) SetUpTest(c *C) {
|
||||||
|
container := randContainer()
|
||||||
|
prefix := "lala"
|
||||||
|
|
||||||
|
var err error
|
||||||
|
|
||||||
|
s.storage, err = NewPublishedStorage(s.accountName, s.accountKey, container, "", s.endpoint)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
cnt := s.storage.container
|
||||||
|
_, err = cnt.Create(context.Background(), azblob.Metadata{}, azblob.PublicAccessContainer)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
s.prefixedStorage, err = NewPublishedStorage(s.accountName, s.accountKey, container, prefix, s.endpoint)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) TearDownTest(c *C) {
|
||||||
|
cnt := s.storage.container
|
||||||
|
_, err := cnt.Delete(context.Background(), azblob.ContainerAccessConditions{})
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) GetFile(c *C, path string) []byte {
|
||||||
|
blob := s.storage.container.NewBlobURL(path)
|
||||||
|
resp, err := blob.Download(context.Background(), 0, azblob.CountToEnd, azblob.BlobAccessConditions{}, false, azblob.ClientProvidedKeyOptions{})
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
body := resp.Body(azblob.RetryReaderOptions{MaxRetryRequests: 3})
|
||||||
|
data, err := ioutil.ReadAll(body)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) AssertNoFile(c *C, path string) {
|
||||||
|
_, err := s.storage.container.NewBlobURL(path).GetProperties(
|
||||||
|
context.Background(), azblob.BlobAccessConditions{}, azblob.ClientProvidedKeyOptions{})
|
||||||
|
c.Assert(err, NotNil)
|
||||||
|
storageError, ok := err.(azblob.StorageError)
|
||||||
|
c.Assert(ok, Equals, true)
|
||||||
|
c.Assert(string(storageError.ServiceCode()), Equals, string(string(azblob.StorageErrorCodeBlobNotFound)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) PutFile(c *C, path string, data []byte) {
|
||||||
|
hash := md5.Sum(data)
|
||||||
|
_, err := azblob.UploadBufferToBlockBlob(
|
||||||
|
context.Background(),
|
||||||
|
data,
|
||||||
|
s.storage.container.NewBlockBlobURL(path),
|
||||||
|
azblob.UploadToBlockBlobOptions{
|
||||||
|
BlobHTTPHeaders: azblob.BlobHTTPHeaders{
|
||||||
|
ContentMD5: hash[:],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) TestPutFile(c *C) {
|
||||||
|
content := []byte("Welcome to Azure!")
|
||||||
|
filename := "a/b.txt"
|
||||||
|
|
||||||
|
dir := c.MkDir()
|
||||||
|
err := ioutil.WriteFile(filepath.Join(dir, "a"), content, 0644)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
err = s.storage.PutFile(filename, filepath.Join(dir, "a"))
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
c.Check(s.GetFile(c, filename), DeepEquals, content)
|
||||||
|
|
||||||
|
err = s.prefixedStorage.PutFile(filename, filepath.Join(dir, "a"))
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
c.Check(s.GetFile(c, filepath.Join(s.prefixedStorage.prefix, filename)), DeepEquals, content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) TestPutFilePlus(c *C) {
|
||||||
|
content := []byte("Welcome to Azure!")
|
||||||
|
filename := "a/b+c.txt"
|
||||||
|
|
||||||
|
dir := c.MkDir()
|
||||||
|
err := ioutil.WriteFile(filepath.Join(dir, "a"), content, 0644)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
err = s.storage.PutFile(filename, filepath.Join(dir, "a"))
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
c.Check(s.GetFile(c, filename), DeepEquals, content)
|
||||||
|
s.AssertNoFile(c, "a/b c.txt")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) TestFilelist(c *C) {
|
||||||
|
paths := []string{"a", "b", "c", "testa", "test/a", "test/b", "lala/a", "lala/b", "lala/c"}
|
||||||
|
for _, path := range paths {
|
||||||
|
s.PutFile(c, path, []byte("test"))
|
||||||
|
}
|
||||||
|
|
||||||
|
list, err := s.storage.Filelist("")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
c.Check(list, DeepEquals, []string{"a", "b", "c", "lala/a", "lala/b", "lala/c", "test/a", "test/b", "testa"})
|
||||||
|
|
||||||
|
list, err = s.storage.Filelist("test")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
c.Check(list, DeepEquals, []string{"a", "b"})
|
||||||
|
|
||||||
|
list, err = s.storage.Filelist("test2")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
c.Check(list, DeepEquals, []string{})
|
||||||
|
|
||||||
|
list, err = s.prefixedStorage.Filelist("")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
c.Check(list, DeepEquals, []string{"a", "b", "c"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) TestFilelistPlus(c *C) {
|
||||||
|
paths := []string{"a", "b", "c", "testa", "test/a+1", "test/a 1", "lala/a+b", "lala/a b", "lala/c"}
|
||||||
|
for _, path := range paths {
|
||||||
|
s.PutFile(c, path, []byte("test"))
|
||||||
|
}
|
||||||
|
|
||||||
|
list, err := s.storage.Filelist("")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
c.Check(list, DeepEquals, []string{"a", "b", "c", "lala/a b", "lala/a+b", "lala/c", "test/a 1", "test/a+1", "testa"})
|
||||||
|
|
||||||
|
list, err = s.storage.Filelist("test")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
c.Check(list, DeepEquals, []string{"a 1", "a+1"})
|
||||||
|
|
||||||
|
list, err = s.storage.Filelist("test2")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
c.Check(list, DeepEquals, []string{})
|
||||||
|
|
||||||
|
list, err = s.prefixedStorage.Filelist("")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
c.Check(list, DeepEquals, []string{"a b", "a+b", "c"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) TestRemove(c *C) {
|
||||||
|
s.PutFile(c, "a/b", []byte("test"))
|
||||||
|
|
||||||
|
err := s.storage.Remove("a/b")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
s.AssertNoFile(c, "a/b")
|
||||||
|
|
||||||
|
s.PutFile(c, "lala/xyz", []byte("test"))
|
||||||
|
|
||||||
|
err = s.prefixedStorage.Remove("xyz")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
s.AssertNoFile(c, "lala/xyz")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) TestRemovePlus(c *C) {
|
||||||
|
s.PutFile(c, "a/b+c", []byte("test"))
|
||||||
|
s.PutFile(c, "a/b", []byte("test"))
|
||||||
|
|
||||||
|
err := s.storage.Remove("a/b+c")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
s.AssertNoFile(c, "a/b+c")
|
||||||
|
s.AssertNoFile(c, "a/b c")
|
||||||
|
|
||||||
|
err = s.storage.Remove("a/b")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
s.AssertNoFile(c, "a/b")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) TestRemoveDirs(c *C) {
|
||||||
|
paths := []string{"a", "b", "c", "testa", "test/a", "test/b", "lala/a", "lala/b", "lala/c"}
|
||||||
|
for _, path := range paths {
|
||||||
|
s.PutFile(c, path, []byte("test"))
|
||||||
|
}
|
||||||
|
|
||||||
|
err := s.storage.RemoveDirs("test", nil)
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
list, err := s.storage.Filelist("")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
c.Check(list, DeepEquals, []string{"a", "b", "c", "lala/a", "lala/b", "lala/c", "testa"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) TestRemoveDirsPlus(c *C) {
|
||||||
|
paths := []string{"a", "b", "c", "testa", "test/a+1", "test/a 1", "lala/a+b", "lala/a b", "lala/c"}
|
||||||
|
for _, path := range paths {
|
||||||
|
s.PutFile(c, path, []byte("test"))
|
||||||
|
}
|
||||||
|
|
||||||
|
err := s.storage.RemoveDirs("test", nil)
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
list, err := s.storage.Filelist("")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
c.Check(list, DeepEquals, []string{"a", "b", "c", "lala/a b", "lala/a+b", "lala/c", "testa"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) TestRenameFile(c *C) {
|
||||||
|
dir := c.MkDir()
|
||||||
|
err := ioutil.WriteFile(filepath.Join(dir, "a"), []byte("Welcome to Azure!"), 0644)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
err = s.storage.PutFile("source.txt", filepath.Join(dir, "a"))
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
err = s.storage.RenameFile("source.txt", "dest.txt")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
c.Check(s.GetFile(c, "dest.txt"), DeepEquals, []byte("Welcome to Azure!"))
|
||||||
|
|
||||||
|
exists, err := s.storage.FileExists("source.txt")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
c.Check(exists, Equals, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) TestLinkFromPool(c *C) {
|
||||||
|
root := c.MkDir()
|
||||||
|
pool := files.NewPackagePool(root, false)
|
||||||
|
cs := files.NewMockChecksumStorage()
|
||||||
|
|
||||||
|
tmpFile1 := filepath.Join(c.MkDir(), "mars-invaders_1.03.deb")
|
||||||
|
err := ioutil.WriteFile(tmpFile1, []byte("Contents"), 0644)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
cksum1 := utils.ChecksumInfo{MD5: "c1df1da7a1ce305a3b60af9d5733ac1d"}
|
||||||
|
|
||||||
|
tmpFile2 := filepath.Join(c.MkDir(), "mars-invaders_1.03.deb")
|
||||||
|
err = ioutil.WriteFile(tmpFile2, []byte("Spam"), 0644)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
cksum2 := utils.ChecksumInfo{MD5: "e9dfd31cc505d51fc26975250750deab"}
|
||||||
|
|
||||||
|
tmpFile3 := filepath.Join(c.MkDir(), "netboot/boot.img.gz")
|
||||||
|
os.MkdirAll(filepath.Dir(tmpFile3), 0777)
|
||||||
|
err = ioutil.WriteFile(tmpFile3, []byte("Contents"), 0644)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
cksum3 := utils.ChecksumInfo{MD5: "c1df1da7a1ce305a3b60af9d5733ac1d"}
|
||||||
|
|
||||||
|
src1, err := pool.Import(tmpFile1, "mars-invaders_1.03.deb", &cksum1, true, cs)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
src2, err := pool.Import(tmpFile2, "mars-invaders_1.03.deb", &cksum2, true, cs)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
src3, err := pool.Import(tmpFile3, "netboot/boot.img.gz", &cksum3, true, cs)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
|
// first link from pool
|
||||||
|
err = s.storage.LinkFromPool(filepath.Join("", "pool", "main", "m/mars-invaders"), "mars-invaders_1.03.deb", pool, src1, cksum1, false)
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
c.Check(s.GetFile(c, "pool/main/m/mars-invaders/mars-invaders_1.03.deb"), DeepEquals, []byte("Contents"))
|
||||||
|
|
||||||
|
// duplicate link from pool
|
||||||
|
err = s.storage.LinkFromPool(filepath.Join("", "pool", "main", "m/mars-invaders"), "mars-invaders_1.03.deb", pool, src1, cksum1, false)
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
c.Check(s.GetFile(c, "pool/main/m/mars-invaders/mars-invaders_1.03.deb"), DeepEquals, []byte("Contents"))
|
||||||
|
|
||||||
|
// link from pool with conflict
|
||||||
|
err = s.storage.LinkFromPool(filepath.Join("", "pool", "main", "m/mars-invaders"), "mars-invaders_1.03.deb", pool, src2, cksum2, false)
|
||||||
|
c.Check(err, ErrorMatches, ".*file already exists and is different.*")
|
||||||
|
|
||||||
|
c.Check(s.GetFile(c, "pool/main/m/mars-invaders/mars-invaders_1.03.deb"), DeepEquals, []byte("Contents"))
|
||||||
|
|
||||||
|
// link from pool with conflict and force
|
||||||
|
err = s.storage.LinkFromPool(filepath.Join("", "pool", "main", "m/mars-invaders"), "mars-invaders_1.03.deb", pool, src2, cksum2, true)
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
c.Check(s.GetFile(c, "pool/main/m/mars-invaders/mars-invaders_1.03.deb"), DeepEquals, []byte("Spam"))
|
||||||
|
|
||||||
|
// for prefixed storage:
|
||||||
|
// first link from pool
|
||||||
|
err = s.prefixedStorage.LinkFromPool(filepath.Join("", "pool", "main", "m/mars-invaders"), "mars-invaders_1.03.deb", pool, src1, cksum1, false)
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
// 2nd link from pool, providing wrong path for source file
|
||||||
|
//
|
||||||
|
// this test should check that file already exists in S3 and skip upload (which would fail if not skipped)
|
||||||
|
s.prefixedStorage.pathCache = nil
|
||||||
|
err = s.prefixedStorage.LinkFromPool(filepath.Join("", "pool", "main", "m/mars-invaders"), "mars-invaders_1.03.deb", pool, "wrong-looks-like-pathcache-doesnt-work", cksum1, false)
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
c.Check(s.GetFile(c, "lala/pool/main/m/mars-invaders/mars-invaders_1.03.deb"), DeepEquals, []byte("Contents"))
|
||||||
|
|
||||||
|
// link from pool with nested file name
|
||||||
|
err = s.storage.LinkFromPool("dists/jessie/non-free/installer-i386/current/images", "netboot/boot.img.gz", pool, src3, cksum3, false)
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
c.Check(s.GetFile(c, "dists/jessie/non-free/installer-i386/current/images/netboot/boot.img.gz"), DeepEquals, []byte("Contents"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) TestSymLink(c *C) {
|
||||||
|
s.PutFile(c, "a/b", []byte("test"))
|
||||||
|
|
||||||
|
err := s.storage.SymLink("a/b", "a/b.link")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
|
||||||
|
var link string
|
||||||
|
link, err = s.storage.ReadLink("a/b.link")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
c.Check(link, Equals, "a/b")
|
||||||
|
|
||||||
|
c.Skip("copy not available in azure test")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PublishedStorageSuite) TestFileExists(c *C) {
|
||||||
|
s.PutFile(c, "a/b", []byte("test"))
|
||||||
|
|
||||||
|
exists, err := s.storage.FileExists("a/b")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
c.Check(exists, Equals, true)
|
||||||
|
|
||||||
|
exists, _ = s.storage.FileExists("a/b.invalid")
|
||||||
|
c.Check(err, IsNil)
|
||||||
|
c.Check(exists, Equals, false)
|
||||||
|
}
|
||||||
+62
-5
@@ -2,10 +2,16 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/api"
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/api"
|
||||||
|
"github.com/aptly-dev/aptly/systemd/activation"
|
||||||
|
"github.com/aptly-dev/aptly/utils"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyAPIServe(cmd *commander.Command, args []string) error {
|
func aptlyAPIServe(cmd *commander.Command, args []string) error {
|
||||||
@@ -18,10 +24,56 @@ func aptlyAPIServe(cmd *commander.Command, args []string) error {
|
|||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
listen := context.Flags().Lookup("listen").Value.String()
|
// There are only two working options for aptly's rootDir:
|
||||||
|
// 1. rootDir does not exist, then we'll create it
|
||||||
|
// 2. rootDir exists and is writable
|
||||||
|
// anything else must fail.
|
||||||
|
// E.g.: Running the service under a different user may lead to a rootDir
|
||||||
|
// that exists but is not usable due to access permissions.
|
||||||
|
err = utils.DirIsAccessible(context.Config().RootDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to recycle systemd fds for listening
|
||||||
|
listeners, err := activation.Listeners(true)
|
||||||
|
if len(listeners) > 1 {
|
||||||
|
panic("Got more than 1 listener from systemd. This is currently not supported!")
|
||||||
|
}
|
||||||
|
if err == nil && len(listeners) == 1 {
|
||||||
|
listener := listeners[0]
|
||||||
|
defer listener.Close()
|
||||||
|
fmt.Printf("\nTaking over web server at: %s (press Ctrl+C to quit)...\n", listener.Addr().String())
|
||||||
|
err = http.Serve(listener, api.Router(context))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to serve: %s", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there are none: use the listen argument.
|
||||||
|
listen := context.Flags().Lookup("listen").Value.String()
|
||||||
fmt.Printf("\nStarting web server at: %s (press Ctrl+C to quit)...\n", listen)
|
fmt.Printf("\nStarting web server at: %s (press Ctrl+C to quit)...\n", listen)
|
||||||
|
|
||||||
|
listenURL, err := url.Parse(listen)
|
||||||
|
if err == nil && listenURL.Scheme == "unix" {
|
||||||
|
file := listenURL.Path
|
||||||
|
os.Remove(file)
|
||||||
|
|
||||||
|
var listener net.Listener
|
||||||
|
listener, err = net.Listen("unix", file)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to listen on: %s\n%s", file, err)
|
||||||
|
}
|
||||||
|
defer listener.Close()
|
||||||
|
|
||||||
|
err = http.Serve(listener, api.Router(context))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to serve: %s", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
err = http.ListenAndServe(listen, api.Router(context))
|
err = http.ListenAndServe(listen, api.Router(context))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to serve: %s", err)
|
return fmt.Errorf("unable to serve: %s", err)
|
||||||
@@ -36,16 +88,21 @@ func makeCmdAPIServe() *commander.Command {
|
|||||||
UsageLine: "serve",
|
UsageLine: "serve",
|
||||||
Short: "start API HTTP service",
|
Short: "start API HTTP service",
|
||||||
Long: `
|
Long: `
|
||||||
Stat HTTP server with aptly REST API.
|
Start HTTP server with aptly REST API. The server can listen to either a port
|
||||||
|
or Unix domain socket. When using a socket, Aptly will fully manage the socket
|
||||||
|
file. This command also supports taking over from a systemd file descriptors to
|
||||||
|
enable systemd socket activation.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
$ aptly api serve -listen=:8080
|
$ aptly api serve -listen=:8080
|
||||||
|
$ aptly api serve -listen=unix:///tmp/aptly.sock
|
||||||
`,
|
`,
|
||||||
Flag: *flag.NewFlagSet("aptly-serve", flag.ExitOnError),
|
Flag: *flag.NewFlagSet("aptly-serve", flag.ExitOnError),
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flag.String("listen", ":8080", "host:port for HTTP listening")
|
cmd.Flag.String("listen", ":8080", "host:port for HTTP listening or unix://path to listen on a Unix domain socket")
|
||||||
|
cmd.Flag.Bool("no-lock", false, "don't lock the database")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
|||||||
+49
-15
@@ -2,36 +2,67 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/aptly"
|
"os"
|
||||||
"github.com/smira/aptly/deb"
|
"text/template"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
"os"
|
)
|
||||||
"time"
|
|
||||||
|
// Various command flags/UI things
|
||||||
|
const (
|
||||||
|
Yes = "yes"
|
||||||
|
No = "no"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ListPackagesRefList shows list of packages in PackageRefList
|
// ListPackagesRefList shows list of packages in PackageRefList
|
||||||
func ListPackagesRefList(reflist *deb.PackageRefList) (err error) {
|
func ListPackagesRefList(reflist *deb.PackageRefList, collectionFactory *deb.CollectionFactory) (err error) {
|
||||||
fmt.Printf("Packages:\n")
|
fmt.Printf("Packages:\n")
|
||||||
|
|
||||||
if reflist == nil {
|
if reflist == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = reflist.ForEach(func(key []byte) error {
|
list, err := deb.NewPackageListFromRefList(reflist, collectionFactory.PackageCollection(), context.Progress())
|
||||||
p, err2 := context.CollectionFactory().PackageCollection().ByKey(key)
|
|
||||||
if err2 != nil {
|
|
||||||
return err2
|
|
||||||
}
|
|
||||||
fmt.Printf(" %s\n", p)
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to load packages: %s", err)
|
return fmt.Errorf("unable to load packages: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return PrintPackageList(list, "", " ")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrintPackageList shows package list with specified format or default representation
|
||||||
|
func PrintPackageList(result *deb.PackageList, format, prefix string) error {
|
||||||
|
result.PrepareIndex()
|
||||||
|
|
||||||
|
if format == "" {
|
||||||
|
return result.ForEachIndexed(func(p *deb.Package) error {
|
||||||
|
context.Progress().Printf(prefix+"%s\n", p)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
formatTemplate, err := template.New("format").Parse(format)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error parsing -format template: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.ForEachIndexed(func(p *deb.Package) error {
|
||||||
|
b := &bytes.Buffer{}
|
||||||
|
err = formatTemplate.Execute(b, p.ExtendedStanza())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error applying template: %s", err)
|
||||||
|
}
|
||||||
|
context.Progress().Printf(prefix+"%s\n", b.String())
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// LookupOption checks boolean flag with default (usually config) and command-line
|
// LookupOption checks boolean flag with default (usually config) and command-line
|
||||||
@@ -80,12 +111,15 @@ package environment to new version.`,
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.Flag.Int("db-open-attempts", 10, "number of attempts to open DB if it's locked by other instance")
|
||||||
cmd.Flag.Bool("dep-follow-suggests", false, "when processing dependencies, follow Suggests")
|
cmd.Flag.Bool("dep-follow-suggests", false, "when processing dependencies, follow Suggests")
|
||||||
cmd.Flag.Bool("dep-follow-source", false, "when processing dependencies, follow from binary to Source packages")
|
cmd.Flag.Bool("dep-follow-source", false, "when processing dependencies, follow from binary to Source packages")
|
||||||
cmd.Flag.Bool("dep-follow-recommends", false, "when processing dependencies, follow Recommends")
|
cmd.Flag.Bool("dep-follow-recommends", false, "when processing dependencies, follow Recommends")
|
||||||
cmd.Flag.Bool("dep-follow-all-variants", false, "when processing dependencies, follow a & b if depdency is 'a|b'")
|
cmd.Flag.Bool("dep-follow-all-variants", false, "when processing dependencies, follow a & b if dependency is 'a|b'")
|
||||||
|
cmd.Flag.Bool("dep-verbose-resolve", false, "when processing dependencies, print detailed logs")
|
||||||
cmd.Flag.String("architectures", "", "list of architectures to consider during (comma-separated), default to all available")
|
cmd.Flag.String("architectures", "", "list of architectures to consider during (comma-separated), default to all available")
|
||||||
cmd.Flag.String("config", "", "location of configuration file (default locations are /etc/aptly.conf, ~/.aptly.conf)")
|
cmd.Flag.String("config", "", "location of configuration file (default locations are /etc/aptly.conf, ~/.aptly.conf)")
|
||||||
|
cmd.Flag.String("gpg-provider", "", "PGP implementation (\"gpg\", \"gpg1\", \"gpg2\" for external gpg or \"internal\" for Go internal implementation)")
|
||||||
|
|
||||||
if aptly.EnableDebug {
|
if aptly.EnableDebug {
|
||||||
cmd.Flag.String("cpuprofile", "", "write cpu profile to file")
|
cmd.Flag.String("cpuprofile", "", "write cpu profile to file")
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -1,7 +1,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ctx "github.com/smira/aptly/context"
|
ctx "github.com/aptly-dev/aptly/context"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,3 +29,8 @@ func InitContext(flags *flag.FlagSet) error {
|
|||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetContext gives access to the context
|
||||||
|
func GetContext() *ctx.AptlyContext {
|
||||||
|
return context
|
||||||
|
}
|
||||||
|
|||||||
+166
-38
@@ -2,10 +2,13 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"github.com/smira/aptly/utils"
|
|
||||||
"github.com/smira/commander"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/utils"
|
||||||
|
"github.com/smira/commander"
|
||||||
)
|
)
|
||||||
|
|
||||||
// aptly db cleanup
|
// aptly db cleanup
|
||||||
@@ -17,61 +20,137 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
|||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
verbose := context.Flags().Lookup("verbose").Value.Get().(bool)
|
||||||
|
dryRun := context.Flags().Lookup("dry-run").Value.Get().(bool)
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
|
||||||
// collect information about references packages...
|
// collect information about references packages...
|
||||||
existingPackageRefs := deb.NewPackageRefList()
|
existingPackageRefs := deb.NewPackageRefList()
|
||||||
|
|
||||||
context.Progress().Printf("Loading mirrors, local repos, snapshots and published repos...\n")
|
// used only in verbose mode to report package use source
|
||||||
err = context.CollectionFactory().RemoteRepoCollection().ForEach(func(repo *deb.RemoteRepo) error {
|
packageRefSources := map[string][]string{}
|
||||||
err := context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo)
|
|
||||||
if err != nil {
|
context.Progress().ColoredPrintf("@{w!}Loading mirrors, local repos, snapshots and published repos...@|")
|
||||||
return err
|
if verbose {
|
||||||
|
context.Progress().ColoredPrintf("@{y}Loading mirrors:@|")
|
||||||
|
}
|
||||||
|
err = collectionFactory.RemoteRepoCollection().ForEach(func(repo *deb.RemoteRepo) error {
|
||||||
|
if verbose {
|
||||||
|
context.Progress().ColoredPrintf("- @{g}%s@|", repo.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
e := collectionFactory.RemoteRepoCollection().LoadComplete(repo)
|
||||||
|
if e != nil {
|
||||||
|
return e
|
||||||
}
|
}
|
||||||
if repo.RefList() != nil {
|
if repo.RefList() != nil {
|
||||||
existingPackageRefs = existingPackageRefs.Merge(repo.RefList(), false, true)
|
existingPackageRefs = existingPackageRefs.Merge(repo.RefList(), false, true)
|
||||||
|
|
||||||
|
if verbose {
|
||||||
|
description := fmt.Sprintf("mirror %s", repo.Name)
|
||||||
|
repo.RefList().ForEach(func(key []byte) error {
|
||||||
|
packageRefSources[string(key)] = append(packageRefSources[string(key)], description)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().ForEach(func(repo *deb.LocalRepo) error {
|
collectionFactory.Flush()
|
||||||
err := context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
|
||||||
if err != nil {
|
if verbose {
|
||||||
return err
|
context.Progress().ColoredPrintf("@{y}Loading local repos:@|")
|
||||||
}
|
}
|
||||||
|
err = collectionFactory.LocalRepoCollection().ForEach(func(repo *deb.LocalRepo) error {
|
||||||
|
if verbose {
|
||||||
|
context.Progress().ColoredPrintf("- @{g}%s@|", repo.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
e := collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||||
|
if e != nil {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
if repo.RefList() != nil {
|
if repo.RefList() != nil {
|
||||||
existingPackageRefs = existingPackageRefs.Merge(repo.RefList(), false, true)
|
existingPackageRefs = existingPackageRefs.Merge(repo.RefList(), false, true)
|
||||||
|
|
||||||
|
if verbose {
|
||||||
|
description := fmt.Sprintf("local repo %s", repo.Name)
|
||||||
|
repo.RefList().ForEach(func(key []byte) error {
|
||||||
|
packageRefSources[string(key)] = append(packageRefSources[string(key)], description)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().ForEach(func(snapshot *deb.Snapshot) error {
|
collectionFactory.Flush()
|
||||||
err := context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot)
|
|
||||||
if err != nil {
|
if verbose {
|
||||||
return err
|
context.Progress().ColoredPrintf("@{y}Loading snapshots:@|")
|
||||||
}
|
}
|
||||||
|
err = collectionFactory.SnapshotCollection().ForEach(func(snapshot *deb.Snapshot) error {
|
||||||
|
if verbose {
|
||||||
|
context.Progress().ColoredPrintf("- @{g}%s@|", snapshot.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
e := collectionFactory.SnapshotCollection().LoadComplete(snapshot)
|
||||||
|
if e != nil {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
existingPackageRefs = existingPackageRefs.Merge(snapshot.RefList(), false, true)
|
existingPackageRefs = existingPackageRefs.Merge(snapshot.RefList(), false, true)
|
||||||
|
|
||||||
|
if verbose {
|
||||||
|
description := fmt.Sprintf("snapshot %s", snapshot.Name)
|
||||||
|
snapshot.RefList().ForEach(func(key []byte) error {
|
||||||
|
packageRefSources[string(key)] = append(packageRefSources[string(key)], description)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().PublishedRepoCollection().ForEach(func(published *deb.PublishedRepo) error {
|
collectionFactory.Flush()
|
||||||
if published.SourceKind != "local" {
|
|
||||||
|
if verbose {
|
||||||
|
context.Progress().ColoredPrintf("@{y}Loading published repositories:@|")
|
||||||
|
}
|
||||||
|
err = collectionFactory.PublishedRepoCollection().ForEach(func(published *deb.PublishedRepo) error {
|
||||||
|
if verbose {
|
||||||
|
context.Progress().ColoredPrintf("- @{g}%s:%s/%s{|}", published.Storage, published.Prefix, published.Distribution)
|
||||||
|
}
|
||||||
|
if published.SourceKind != deb.SourceLocalRepo {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
err := context.CollectionFactory().PublishedRepoCollection().LoadComplete(published, context.CollectionFactory())
|
e := collectionFactory.PublishedRepoCollection().LoadComplete(published, collectionFactory)
|
||||||
if err != nil {
|
if e != nil {
|
||||||
return err
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, component := range published.Components() {
|
for _, component := range published.Components() {
|
||||||
existingPackageRefs = existingPackageRefs.Merge(published.RefList(component), false, true)
|
existingPackageRefs = existingPackageRefs.Merge(published.RefList(component), false, true)
|
||||||
|
if verbose {
|
||||||
|
description := fmt.Sprintf("published repository %s:%s/%s component %s",
|
||||||
|
published.Storage, published.Prefix, published.Distribution, component)
|
||||||
|
published.RefList(component).ForEach(func(key []byte) error {
|
||||||
|
packageRefSources[string(key)] = append(packageRefSources[string(key)], description)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@@ -79,39 +158,70 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ... and compare it to the list of all packages
|
collectionFactory.Flush()
|
||||||
context.Progress().Printf("Loading list of all packages...\n")
|
|
||||||
allPackageRefs := context.CollectionFactory().PackageCollection().AllPackageRefs()
|
|
||||||
|
|
||||||
toDelete := allPackageRefs.Substract(existingPackageRefs)
|
// ... and compare it to the list of all packages
|
||||||
|
context.Progress().ColoredPrintf("@{w!}Loading list of all packages...@|")
|
||||||
|
allPackageRefs := collectionFactory.PackageCollection().AllPackageRefs()
|
||||||
|
|
||||||
|
toDelete := allPackageRefs.Subtract(existingPackageRefs)
|
||||||
|
|
||||||
// delete packages that are no longer referenced
|
// delete packages that are no longer referenced
|
||||||
context.Progress().Printf("Deleting unreferenced packages (%d)...\n", toDelete.Len())
|
context.Progress().ColoredPrintf("@{r!}Deleting unreferenced packages (%d)...@|", toDelete.Len())
|
||||||
|
|
||||||
// database can't err as collection factory already constructed
|
// database can't err as collection factory already constructed
|
||||||
db, _ := context.Database()
|
db, _ := context.Database()
|
||||||
db.StartBatch()
|
|
||||||
|
if toDelete.Len() > 0 {
|
||||||
|
if verbose {
|
||||||
|
context.Progress().ColoredPrintf("@{r}List of package keys to delete:@|")
|
||||||
err = toDelete.ForEach(func(ref []byte) error {
|
err = toDelete.ForEach(func(ref []byte) error {
|
||||||
return context.CollectionFactory().PackageCollection().DeleteByKey(ref)
|
context.Progress().ColoredPrintf(" - @{r}%s@|", string(ref))
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = db.FinishBatch()
|
if !dryRun {
|
||||||
|
batch := db.CreateBatch()
|
||||||
|
err = toDelete.ForEach(func(ref []byte) error {
|
||||||
|
return collectionFactory.PackageCollection().DeleteByKey(ref, batch)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to delete by key: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = batch.Write()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to write to DB: %s", err)
|
return fmt.Errorf("unable to write to DB: %s", err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
context.Progress().ColoredPrintf("@{y!}Skipped deletion, as -dry-run has been requested.@|")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
collectionFactory.Flush()
|
||||||
|
|
||||||
// now, build a list of files that should be present in Repository (package pool)
|
// now, build a list of files that should be present in Repository (package pool)
|
||||||
context.Progress().Printf("Building list of files referenced by packages...\n")
|
context.Progress().ColoredPrintf("@{w!}Building list of files referenced by packages...@|")
|
||||||
referencedFiles := make([]string, 0, existingPackageRefs.Len())
|
referencedFiles := make([]string, 0, existingPackageRefs.Len())
|
||||||
context.Progress().InitBar(int64(existingPackageRefs.Len()), false)
|
context.Progress().InitBar(int64(existingPackageRefs.Len()), false, aptly.BarCleanupBuildList)
|
||||||
|
|
||||||
err = existingPackageRefs.ForEach(func(key []byte) error {
|
err = existingPackageRefs.ForEach(func(key []byte) error {
|
||||||
pkg, err2 := context.CollectionFactory().PackageCollection().ByKey(key)
|
pkg, err2 := collectionFactory.PackageCollection().ByKey(key)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
return err2
|
tail := ""
|
||||||
|
if verbose {
|
||||||
|
tail = fmt.Sprintf(" (sources: %s)", strings.Join(packageRefSources[string(key)], ", "))
|
||||||
|
}
|
||||||
|
if dryRun {
|
||||||
|
context.Progress().ColoredPrintf("@{r!}Unresolvable package reference, skipping (-dry-run): %s: %s%s",
|
||||||
|
string(key), err2, tail)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unable to load package %s: %s%s", string(key), err2, tail)
|
||||||
}
|
}
|
||||||
paths, err2 := pkg.FilepathList(context.PackagePool())
|
paths, err2 := pkg.FilepathList(context.PackagePool())
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
@@ -130,7 +240,7 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
|||||||
context.Progress().ShutdownBar()
|
context.Progress().ShutdownBar()
|
||||||
|
|
||||||
// build a list of files in the package pool
|
// build a list of files in the package pool
|
||||||
context.Progress().Printf("Building list of files in package pool...\n")
|
context.Progress().ColoredPrintf("@{w!}Building list of files in package pool...@|")
|
||||||
existingFiles, err := context.PackagePool().FilepathList(context.Progress())
|
existingFiles, err := context.PackagePool().FilepathList(context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to collect file paths: %s", err)
|
return fmt.Errorf("unable to collect file paths: %s", err)
|
||||||
@@ -140,10 +250,18 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
|||||||
filesToDelete := utils.StrSlicesSubstract(existingFiles, referencedFiles)
|
filesToDelete := utils.StrSlicesSubstract(existingFiles, referencedFiles)
|
||||||
|
|
||||||
// delete files that are no longer referenced
|
// delete files that are no longer referenced
|
||||||
context.Progress().Printf("Deleting unreferenced files (%d)...\n", len(filesToDelete))
|
context.Progress().ColoredPrintf("@{r!}Deleting unreferenced files (%d)...@|", len(filesToDelete))
|
||||||
|
|
||||||
if len(filesToDelete) > 0 {
|
if len(filesToDelete) > 0 {
|
||||||
context.Progress().InitBar(int64(len(filesToDelete)), false)
|
if verbose {
|
||||||
|
context.Progress().ColoredPrintf("@{r}List of files to be deleted:@|")
|
||||||
|
for _, file := range filesToDelete {
|
||||||
|
context.Progress().ColoredPrintf(" - @{r}%s@|", file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !dryRun {
|
||||||
|
context.Progress().InitBar(int64(len(filesToDelete)), false, aptly.BarCleanupDeleteUnreferencedFiles)
|
||||||
|
|
||||||
var size, totalSize int64
|
var size, totalSize int64
|
||||||
for _, file := range filesToDelete {
|
for _, file := range filesToDelete {
|
||||||
@@ -157,11 +275,18 @@ func aptlyDbCleanup(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
context.Progress().ShutdownBar()
|
context.Progress().ShutdownBar()
|
||||||
|
|
||||||
context.Progress().Printf("Disk space freed: %s...\n", utils.HumanBytes(totalSize))
|
context.Progress().ColoredPrintf("@{w!}Disk space freed: %s...@|", utils.HumanBytes(totalSize))
|
||||||
|
} else {
|
||||||
|
context.Progress().ColoredPrintf("@{y!}Skipped file deletion, as -dry-run has been requested.@|")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Progress().Printf("Compacting database...\n")
|
if !dryRun {
|
||||||
|
context.Progress().ColoredPrintf("@{w!}Compacting database...@|")
|
||||||
err = db.CompactDB()
|
err = db.CompactDB()
|
||||||
|
} else {
|
||||||
|
context.Progress().ColoredPrintf("@{y!}Skipped DB compaction, as -dry-run has been requested.@|")
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -181,5 +306,8 @@ Example:
|
|||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.Flag.Bool("verbose", false, "be verbose when loading objects/removing them")
|
||||||
|
cmd.Flag.Bool("dry-run", false, "don't delete anything")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -1,8 +1,9 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/smira/aptly/database"
|
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/database/goleveldb"
|
||||||
)
|
)
|
||||||
|
|
||||||
// aptly db recover
|
// aptly db recover
|
||||||
@@ -15,7 +16,7 @@ func aptlyDbRecover(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
context.Progress().Printf("Recovering database...\n")
|
context.Progress().Printf("Recovering database...\n")
|
||||||
err = database.RecoverDB(context.DBPath())
|
err = goleveldb.RecoverDB(context.DBPath())
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+64
-8
@@ -3,12 +3,18 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"github.com/smira/commander"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/utils"
|
||||||
|
"github.com/smira/commander"
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyGraph(cmd *commander.Command, args []string) error {
|
func aptlyGraph(cmd *commander.Command, args []string) error {
|
||||||
@@ -19,8 +25,11 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
|
|||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
layout := context.Flags().Lookup("layout").Value.String()
|
||||||
|
|
||||||
fmt.Printf("Generating graph...\n")
|
fmt.Printf("Generating graph...\n")
|
||||||
graph, err := deb.BuildGraph(context.CollectionFactory())
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
graph, err := deb.BuildGraph(collectionFactory, layout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -34,9 +43,16 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
|
|||||||
tempfile.Close()
|
tempfile.Close()
|
||||||
os.Remove(tempfile.Name())
|
os.Remove(tempfile.Name())
|
||||||
|
|
||||||
tempfilename := tempfile.Name() + ".png"
|
format := context.Flags().Lookup("format").Value.String()
|
||||||
|
output := context.Flags().Lookup("output").Value.String()
|
||||||
|
|
||||||
command := exec.Command("dot", "-Tpng", "-o"+tempfilename)
|
if filepath.Ext(output) != "" {
|
||||||
|
format = filepath.Ext(output)[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
tempfilename := tempfile.Name() + "." + format
|
||||||
|
|
||||||
|
command := exec.Command("dot", "-T"+format, "-o"+tempfilename)
|
||||||
command.Stderr = os.Stderr
|
command.Stderr = os.Stderr
|
||||||
|
|
||||||
stdin, err := command.StdinPipe()
|
stdin, err := command.StdinPipe()
|
||||||
@@ -64,15 +80,51 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = exec.Command("open", tempfilename).Run()
|
defer func() {
|
||||||
|
_ = os.Remove(tempfilename)
|
||||||
|
}()
|
||||||
|
|
||||||
|
if output != "" {
|
||||||
|
err = utils.CopyFile(tempfilename, output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Rendered to PNG file: %s\n", tempfilename)
|
return fmt.Errorf("unable to copy %s -> %s: %s", tempfilename, output, err)
|
||||||
err = nil
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Output saved to %s\n", output)
|
||||||
|
} else {
|
||||||
|
command := getOpenCommand()
|
||||||
|
fmt.Printf("Rendered to %s file: %s, trying to open it with: %s %s...\n", format, tempfilename, command, tempfilename)
|
||||||
|
|
||||||
|
args := strings.Split(command, " ")
|
||||||
|
|
||||||
|
viewer := exec.Command(args[0], append(args[1:], tempfilename)...)
|
||||||
|
viewer.Stderr = os.Stderr
|
||||||
|
if err = viewer.Start(); err == nil {
|
||||||
|
// Wait for a second so that the visualizer has a chance to
|
||||||
|
// open the input file. This needs to be done even if we're
|
||||||
|
// waiting for the visualizer as it can be just a wrapper that
|
||||||
|
// spawns a browser tab and returns right away.
|
||||||
|
defer func(t <-chan time.Time) {
|
||||||
|
<-t
|
||||||
|
}(time.After(time.Second))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getOpenCommand tries to guess command to open image for OS
|
||||||
|
func getOpenCommand() string {
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "darwin":
|
||||||
|
return "/usr/bin/open"
|
||||||
|
case "windows":
|
||||||
|
return "cmd /c start"
|
||||||
|
default:
|
||||||
|
return "xdg-open"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func makeCmdGraph() *commander.Command {
|
func makeCmdGraph() *commander.Command {
|
||||||
cmd := &commander.Command{
|
cmd := &commander.Command{
|
||||||
Run: aptlyGraph,
|
Run: aptlyGraph,
|
||||||
@@ -89,5 +141,9 @@ Example:
|
|||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.Flag.String("format", "png", "render graph to specified format (png, svg, pdf, etc.)")
|
||||||
|
cmd.Flag.String("output", "", "specify output filename, default is to open result in viewer")
|
||||||
|
cmd.Flag.String("layout", "horizontal", "create a more 'vertical' or a more 'horizontal' graph layout")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -1,20 +1,21 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/smira/aptly/utils"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/pgp"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func getVerifier(flags *flag.FlagSet) (utils.Verifier, error) {
|
func getVerifier(flags *flag.FlagSet) (pgp.Verifier, error) {
|
||||||
if LookupOption(context.Config().GpgDisableVerify, flags, "ignore-signatures") {
|
if LookupOption(context.Config().GpgDisableVerify, flags, "ignore-signatures") {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
keyRings := flags.Lookup("keyring").Value.Get().([]string)
|
keyRings := flags.Lookup("keyring").Value.Get().([]string)
|
||||||
|
|
||||||
verifier := &utils.GpgVerifier{}
|
verifier := context.GetVerifier()
|
||||||
for _, keyRing := range keyRings {
|
for _, keyRing := range keyRings {
|
||||||
verifier.AddKeyring(keyRing)
|
verifier.AddKeyring(keyRing)
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-5
@@ -2,11 +2,12 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
"strings"
|
||||||
"github.com/smira/aptly/query"
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/query"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyMirrorCreate(cmd *commander.Command, args []string) error {
|
func aptlyMirrorCreate(cmd *commander.Command, args []string) error {
|
||||||
@@ -18,6 +19,7 @@ func aptlyMirrorCreate(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
downloadSources := LookupOption(context.Config().DownloadSourcePackages, context.Flags(), "with-sources")
|
downloadSources := LookupOption(context.Config().DownloadSourcePackages, context.Flags(), "with-sources")
|
||||||
downloadUdebs := context.Flags().Lookup("with-udebs").Value.Get().(bool)
|
downloadUdebs := context.Flags().Lookup("with-udebs").Value.Get().(bool)
|
||||||
|
downloadInstaller := context.Flags().Lookup("with-installer").Value.Get().(bool)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
mirrorName, archiveURL, distribution string
|
mirrorName, archiveURL, distribution string
|
||||||
@@ -35,7 +37,7 @@ func aptlyMirrorCreate(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
repo, err := deb.NewRemoteRepo(mirrorName, archiveURL, distribution, components, context.ArchitecturesList(),
|
repo, err := deb.NewRemoteRepo(mirrorName, archiveURL, distribution, components, context.ArchitecturesList(),
|
||||||
downloadSources, downloadUdebs)
|
downloadSources, downloadUdebs, downloadInstaller)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create mirror: %s", err)
|
return fmt.Errorf("unable to create mirror: %s", err)
|
||||||
}
|
}
|
||||||
@@ -43,6 +45,7 @@ func aptlyMirrorCreate(cmd *commander.Command, args []string) error {
|
|||||||
repo.Filter = context.Flags().Lookup("filter").Value.String()
|
repo.Filter = context.Flags().Lookup("filter").Value.String()
|
||||||
repo.FilterWithDeps = context.Flags().Lookup("filter-with-deps").Value.Get().(bool)
|
repo.FilterWithDeps = context.Flags().Lookup("filter-with-deps").Value.Get().(bool)
|
||||||
repo.SkipComponentCheck = context.Flags().Lookup("force-components").Value.Get().(bool)
|
repo.SkipComponentCheck = context.Flags().Lookup("force-components").Value.Get().(bool)
|
||||||
|
repo.SkipArchitectureCheck = context.Flags().Lookup("force-architectures").Value.Get().(bool)
|
||||||
|
|
||||||
if repo.Filter != "" {
|
if repo.Filter != "" {
|
||||||
_, err = query.Parse(repo.Filter)
|
_, err = query.Parse(repo.Filter)
|
||||||
@@ -61,7 +64,8 @@ func aptlyMirrorCreate(cmd *commander.Command, args []string) error {
|
|||||||
return fmt.Errorf("unable to fetch mirror: %s", err)
|
return fmt.Errorf("unable to fetch mirror: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().RemoteRepoCollection().Add(repo)
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
err = collectionFactory.RemoteRepoCollection().Add(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to add mirror: %s", err)
|
return fmt.Errorf("unable to add mirror: %s", err)
|
||||||
}
|
}
|
||||||
@@ -92,11 +96,14 @@ Example:
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flag.Bool("ignore-signatures", false, "disable verification of Release file signatures")
|
cmd.Flag.Bool("ignore-signatures", false, "disable verification of Release file signatures")
|
||||||
|
cmd.Flag.Bool("with-installer", false, "download additional not packaged installer files")
|
||||||
cmd.Flag.Bool("with-sources", false, "download source packages in addition to binary packages")
|
cmd.Flag.Bool("with-sources", false, "download source packages in addition to binary packages")
|
||||||
cmd.Flag.Bool("with-udebs", false, "download .udeb packages (Debian installer support)")
|
cmd.Flag.Bool("with-udebs", false, "download .udeb packages (Debian installer support)")
|
||||||
cmd.Flag.String("filter", "", "filter packages in mirror")
|
cmd.Flag.String("filter", "", "filter packages in mirror")
|
||||||
cmd.Flag.Bool("filter-with-deps", false, "when filtering, include dependencies of matching packages as well")
|
cmd.Flag.Bool("filter-with-deps", false, "when filtering, include dependencies of matching packages as well")
|
||||||
cmd.Flag.Bool("force-components", false, "(only with component list) skip check that requested components are listed in Release file")
|
cmd.Flag.Bool("force-components", false, "(only with component list) skip check that requested components are listed in Release file")
|
||||||
|
cmd.Flag.Bool("force-architectures", false, "(only with architecture list) skip check that requested architectures are listed in Release file")
|
||||||
|
cmd.Flag.Int("max-tries", 1, "max download tries till process fails with download error")
|
||||||
cmd.Flag.Var(&keyRingsFlag{}, "keyring", "gpg keyring to use when verifying Release file (could be specified multiple times)")
|
cmd.Flag.Var(&keyRingsFlag{}, "keyring", "gpg keyring to use when verifying Release file (could be specified multiple times)")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|||||||
+5
-3
@@ -2,6 +2,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
@@ -14,8 +15,9 @@ func aptlyMirrorDrop(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
|
||||||
repo, err := context.CollectionFactory().RemoteRepoCollection().ByName(name)
|
repo, err := collectionFactory.RemoteRepoCollection().ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to drop: %s", err)
|
return fmt.Errorf("unable to drop: %s", err)
|
||||||
}
|
}
|
||||||
@@ -27,7 +29,7 @@ func aptlyMirrorDrop(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
force := context.Flags().Lookup("force").Value.Get().(bool)
|
force := context.Flags().Lookup("force").Value.Get().(bool)
|
||||||
if !force {
|
if !force {
|
||||||
snapshots := context.CollectionFactory().SnapshotCollection().ByRemoteRepoSource(repo)
|
snapshots := collectionFactory.SnapshotCollection().ByRemoteRepoSource(repo)
|
||||||
|
|
||||||
if len(snapshots) > 0 {
|
if len(snapshots) > 0 {
|
||||||
fmt.Printf("Mirror `%s` was used to create following snapshots:\n", repo.Name)
|
fmt.Printf("Mirror `%s` was used to create following snapshots:\n", repo.Name)
|
||||||
@@ -39,7 +41,7 @@ func aptlyMirrorDrop(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().RemoteRepoCollection().Drop(repo)
|
err = collectionFactory.RemoteRepoCollection().Drop(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to drop: %s", err)
|
return fmt.Errorf("unable to drop: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-4
@@ -2,7 +2,9 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/query"
|
|
||||||
|
"github.com/aptly-dev/aptly/pgp"
|
||||||
|
"github.com/aptly-dev/aptly/query"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
@@ -14,7 +16,8 @@ func aptlyMirrorEdit(cmd *commander.Command, args []string) error {
|
|||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := context.CollectionFactory().RemoteRepoCollection().ByName(args[0])
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
repo, err := collectionFactory.RemoteRepoCollection().ByName(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to edit: %s", err)
|
return fmt.Errorf("unable to edit: %s", err)
|
||||||
}
|
}
|
||||||
@@ -24,16 +27,22 @@ func aptlyMirrorEdit(cmd *commander.Command, args []string) error {
|
|||||||
return fmt.Errorf("unable to edit: %s", err)
|
return fmt.Errorf("unable to edit: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fetchMirror := false
|
||||||
context.Flags().Visit(func(flag *flag.Flag) {
|
context.Flags().Visit(func(flag *flag.Flag) {
|
||||||
switch flag.Name {
|
switch flag.Name {
|
||||||
case "filter":
|
case "filter":
|
||||||
repo.Filter = flag.Value.String()
|
repo.Filter = flag.Value.String()
|
||||||
case "filter-with-deps":
|
case "filter-with-deps":
|
||||||
repo.FilterWithDeps = flag.Value.Get().(bool)
|
repo.FilterWithDeps = flag.Value.Get().(bool)
|
||||||
|
case "with-installer":
|
||||||
|
repo.DownloadInstaller = flag.Value.Get().(bool)
|
||||||
case "with-sources":
|
case "with-sources":
|
||||||
repo.DownloadSources = flag.Value.Get().(bool)
|
repo.DownloadSources = flag.Value.Get().(bool)
|
||||||
case "with-udebs":
|
case "with-udebs":
|
||||||
repo.DownloadUdebs = flag.Value.Get().(bool)
|
repo.DownloadUdebs = flag.Value.Get().(bool)
|
||||||
|
case "archive-url":
|
||||||
|
repo.SetArchiveRoot(flag.Value.String())
|
||||||
|
fetchMirror = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -50,14 +59,23 @@ func aptlyMirrorEdit(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
if context.GlobalFlags().Lookup("architectures").Value.String() != "" {
|
if context.GlobalFlags().Lookup("architectures").Value.String() != "" {
|
||||||
repo.Architectures = context.ArchitecturesList()
|
repo.Architectures = context.ArchitecturesList()
|
||||||
|
fetchMirror = true
|
||||||
|
}
|
||||||
|
|
||||||
err = repo.Fetch(context.Downloader(), nil)
|
if fetchMirror {
|
||||||
|
var verifier pgp.Verifier
|
||||||
|
verifier, err = getVerifier(context.Flags())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to initialize GPG verifier: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = repo.Fetch(context.Downloader(), verifier)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to edit: %s", err)
|
return fmt.Errorf("unable to edit: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().RemoteRepoCollection().Update(repo)
|
err = collectionFactory.RemoteRepoCollection().Update(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to edit: %s", err)
|
return fmt.Errorf("unable to edit: %s", err)
|
||||||
}
|
}
|
||||||
@@ -82,10 +100,14 @@ Example:
|
|||||||
Flag: *flag.NewFlagSet("aptly-mirror-edit", flag.ExitOnError),
|
Flag: *flag.NewFlagSet("aptly-mirror-edit", flag.ExitOnError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.Flag.String("archive-url", "", "archive url is the root of archive")
|
||||||
cmd.Flag.String("filter", "", "filter packages in mirror")
|
cmd.Flag.String("filter", "", "filter packages in mirror")
|
||||||
cmd.Flag.Bool("filter-with-deps", false, "when filtering, include dependencies of matching packages as well")
|
cmd.Flag.Bool("filter-with-deps", false, "when filtering, include dependencies of matching packages as well")
|
||||||
|
cmd.Flag.Bool("ignore-signatures", false, "disable verification of Release file signatures")
|
||||||
|
cmd.Flag.Bool("with-installer", false, "download additional not packaged installer files")
|
||||||
cmd.Flag.Bool("with-sources", false, "download source packages in addition to binary packages")
|
cmd.Flag.Bool("with-sources", false, "download source packages in addition to binary packages")
|
||||||
cmd.Flag.Bool("with-udebs", false, "download .udeb packages (Debian installer support)")
|
cmd.Flag.Bool("with-udebs", false, "download .udeb packages (Debian installer support)")
|
||||||
|
cmd.Flag.Var(&keyRingsFlag{}, "keyring", "gpg keyring to use when verifying Release file (could be specified multiple times)")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
+47
-6
@@ -1,24 +1,38 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"github.com/smira/commander"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/smira/commander"
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyMirrorList(cmd *commander.Command, args []string) error {
|
func aptlyMirrorList(cmd *commander.Command, args []string) error {
|
||||||
var err error
|
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
|
jsonFlag := cmd.Flag.Lookup("json").Value.Get().(bool)
|
||||||
|
|
||||||
repos := make([]string, context.CollectionFactory().RemoteRepoCollection().Len())
|
if jsonFlag {
|
||||||
|
return aptlyMirrorListJSON(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
return aptlyMirrorListTxt(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func aptlyMirrorListTxt(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
|
||||||
|
repos := make([]string, collectionFactory.RemoteRepoCollection().Len())
|
||||||
i := 0
|
i := 0
|
||||||
context.CollectionFactory().RemoteRepoCollection().ForEach(func(repo *deb.RemoteRepo) error {
|
collectionFactory.RemoteRepoCollection().ForEach(func(repo *deb.RemoteRepo) error {
|
||||||
if raw {
|
if raw {
|
||||||
repos[i] = repo.Name
|
repos[i] = repo.Name
|
||||||
} else {
|
} else {
|
||||||
@@ -51,6 +65,32 @@ func aptlyMirrorList(cmd *commander.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func aptlyMirrorListJSON(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
repos := make([]*deb.RemoteRepo, context.NewCollectionFactory().RemoteRepoCollection().Len())
|
||||||
|
i := 0
|
||||||
|
context.NewCollectionFactory().RemoteRepoCollection().ForEach(func(repo *deb.RemoteRepo) error {
|
||||||
|
repos[i] = repo
|
||||||
|
i++
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
context.CloseDatabase()
|
||||||
|
|
||||||
|
sort.Slice(repos, func(i, j int) bool {
|
||||||
|
return repos[i].Name < repos[j].Name
|
||||||
|
})
|
||||||
|
|
||||||
|
if output, e := json.MarshalIndent(repos, "", " "); e == nil {
|
||||||
|
fmt.Println(string(output))
|
||||||
|
} else {
|
||||||
|
err = e
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func makeCmdMirrorList() *commander.Command {
|
func makeCmdMirrorList() *commander.Command {
|
||||||
cmd := &commander.Command{
|
cmd := &commander.Command{
|
||||||
Run: aptlyMirrorList,
|
Run: aptlyMirrorList,
|
||||||
@@ -65,6 +105,7 @@ Example:
|
|||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.Flag.Bool("json", false, "display list in JSON format")
|
||||||
cmd.Flag.Bool("raw", false, "display list in machine-readable format")
|
cmd.Flag.Bool("raw", false, "display list in machine-readable format")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,7 +20,8 @@ func aptlyMirrorRename(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
oldName, newName := args[0], args[1]
|
oldName, newName := args[0], args[1]
|
||||||
|
|
||||||
repo, err = context.CollectionFactory().RemoteRepoCollection().ByName(oldName)
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
repo, err = collectionFactory.RemoteRepoCollection().ByName(oldName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to rename: %s", err)
|
return fmt.Errorf("unable to rename: %s", err)
|
||||||
}
|
}
|
||||||
@@ -29,13 +31,13 @@ func aptlyMirrorRename(cmd *commander.Command, args []string) error {
|
|||||||
return fmt.Errorf("unable to rename: %s", err)
|
return fmt.Errorf("unable to rename: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = context.CollectionFactory().RemoteRepoCollection().ByName(newName)
|
_, err = collectionFactory.RemoteRepoCollection().ByName(newName)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return fmt.Errorf("unable to rename: mirror %s already exists", newName)
|
return fmt.Errorf("unable to rename: mirror %s already exists", newName)
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.Name = newName
|
repo.Name = newName
|
||||||
err = context.CollectionFactory().RemoteRepoCollection().Update(repo)
|
err = collectionFactory.RemoteRepoCollection().Update(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to rename: %s", err)
|
return fmt.Errorf("unable to rename: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,13 @@ import (
|
|||||||
func makeCmdMirrorSearch() *commander.Command {
|
func makeCmdMirrorSearch() *commander.Command {
|
||||||
cmd := &commander.Command{
|
cmd := &commander.Command{
|
||||||
Run: aptlySnapshotMirrorRepoSearch,
|
Run: aptlySnapshotMirrorRepoSearch,
|
||||||
UsageLine: "search <name> <package-query>",
|
UsageLine: "search <name> [<package-query>]",
|
||||||
Short: "search mirror for packages matching query",
|
Short: "search mirror for packages matching query",
|
||||||
Long: `
|
Long: `
|
||||||
Command search displays list of packages in mirror that match package query
|
Command search displays list of packages in mirror that match package query
|
||||||
|
|
||||||
|
If query is not specified, all the packages are displayed.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
$ aptly mirror search wheezy-main '$Architecture (i386), Name (% *-dev)'
|
$ aptly mirror search wheezy-main '$Architecture (i386), Name (% *-dev)'
|
||||||
@@ -21,6 +23,7 @@ Example:
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flag.Bool("with-deps", false, "include dependencies into search results")
|
cmd.Flag.Bool("with-deps", false, "include dependencies into search results")
|
||||||
|
cmd.Flag.String("format", "", "custom format for result printing")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
+72
-13
@@ -1,29 +1,44 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
"sort"
|
||||||
"github.com/smira/aptly/utils"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/utils"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyMirrorShow(cmd *commander.Command, args []string) error {
|
func aptlyMirrorShow(cmd *commander.Command, args []string) error {
|
||||||
var err error
|
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jsonFlag := cmd.Flag.Lookup("json").Value.Get().(bool)
|
||||||
|
|
||||||
|
if jsonFlag {
|
||||||
|
return aptlyMirrorShowJSON(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
return aptlyMirrorShowTxt(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func aptlyMirrorShowTxt(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
repo, err := context.CollectionFactory().RemoteRepoCollection().ByName(name)
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
repo, err := collectionFactory.RemoteRepoCollection().ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to show: %s", err)
|
return fmt.Errorf("unable to show: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo)
|
err = collectionFactory.RemoteRepoCollection().LoadComplete(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to show: %s", err)
|
return fmt.Errorf("unable to show: %s", err)
|
||||||
}
|
}
|
||||||
@@ -36,21 +51,21 @@ func aptlyMirrorShow(cmd *commander.Command, args []string) error {
|
|||||||
fmt.Printf("Distribution: %s\n", repo.Distribution)
|
fmt.Printf("Distribution: %s\n", repo.Distribution)
|
||||||
fmt.Printf("Components: %s\n", strings.Join(repo.Components, ", "))
|
fmt.Printf("Components: %s\n", strings.Join(repo.Components, ", "))
|
||||||
fmt.Printf("Architectures: %s\n", strings.Join(repo.Architectures, ", "))
|
fmt.Printf("Architectures: %s\n", strings.Join(repo.Architectures, ", "))
|
||||||
downloadSources := "no"
|
downloadSources := No
|
||||||
if repo.DownloadSources {
|
if repo.DownloadSources {
|
||||||
downloadSources = "yes"
|
downloadSources = Yes
|
||||||
}
|
}
|
||||||
fmt.Printf("Download Sources: %s\n", downloadSources)
|
fmt.Printf("Download Sources: %s\n", downloadSources)
|
||||||
downloadUdebs := "no"
|
downloadUdebs := No
|
||||||
if repo.DownloadUdebs {
|
if repo.DownloadUdebs {
|
||||||
downloadUdebs = "yes"
|
downloadUdebs = Yes
|
||||||
}
|
}
|
||||||
fmt.Printf("Download .udebs: %s\n", downloadUdebs)
|
fmt.Printf("Download .udebs: %s\n", downloadUdebs)
|
||||||
if repo.Filter != "" {
|
if repo.Filter != "" {
|
||||||
fmt.Printf("Filter: %s\n", repo.Filter)
|
fmt.Printf("Filter: %s\n", repo.Filter)
|
||||||
filterWithDeps := "no"
|
filterWithDeps := No
|
||||||
if repo.FilterWithDeps {
|
if repo.FilterWithDeps {
|
||||||
filterWithDeps = "yes"
|
filterWithDeps = Yes
|
||||||
}
|
}
|
||||||
fmt.Printf("Filter With Deps: %s\n", filterWithDeps)
|
fmt.Printf("Filter With Deps: %s\n", filterWithDeps)
|
||||||
}
|
}
|
||||||
@@ -71,13 +86,56 @@ func aptlyMirrorShow(cmd *commander.Command, args []string) error {
|
|||||||
if repo.LastDownloadDate.IsZero() {
|
if repo.LastDownloadDate.IsZero() {
|
||||||
fmt.Printf("Unable to show package list, mirror hasn't been downloaded yet.\n")
|
fmt.Printf("Unable to show package list, mirror hasn't been downloaded yet.\n")
|
||||||
} else {
|
} else {
|
||||||
ListPackagesRefList(repo.RefList())
|
ListPackagesRefList(repo.RefList(), collectionFactory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func aptlyMirrorShowJSON(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
name := args[0]
|
||||||
|
|
||||||
|
repo, err := context.NewCollectionFactory().RemoteRepoCollection().ByName(name)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to show: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = context.NewCollectionFactory().RemoteRepoCollection().LoadComplete(repo)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to show: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// include packages if requested
|
||||||
|
withPackages := context.Flags().Lookup("with-packages").Value.Get().(bool)
|
||||||
|
if withPackages {
|
||||||
|
if repo.RefList() != nil {
|
||||||
|
var list *deb.PackageList
|
||||||
|
list, err = deb.NewPackageListFromRefList(repo.RefList(), context.NewCollectionFactory().PackageCollection(), context.Progress())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to get package list: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
list.PrepareIndex()
|
||||||
|
list.ForEachIndexed(func(p *deb.Package) error {
|
||||||
|
repo.Packages = append(repo.Packages, p.GetFullName())
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
sort.Strings(repo.Packages)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var output []byte
|
||||||
|
if output, err = json.MarshalIndent(repo, "", " "); err == nil {
|
||||||
|
fmt.Println(string(output))
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func makeCmdMirrorShow() *commander.Command {
|
func makeCmdMirrorShow() *commander.Command {
|
||||||
cmd := &commander.Command{
|
cmd := &commander.Command{
|
||||||
Run: aptlyMirrorShow,
|
Run: aptlyMirrorShow,
|
||||||
@@ -93,6 +151,7 @@ Example:
|
|||||||
Flag: *flag.NewFlagSet("aptly-mirror-show", flag.ExitOnError),
|
Flag: *flag.NewFlagSet("aptly-mirror-show", flag.ExitOnError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.Flag.Bool("json", false, "display record in JSON format")
|
||||||
cmd.Flag.Bool("with-packages", false, "show detailed list of packages and versions stored in the mirror")
|
cmd.Flag.Bool("with-packages", false, "show detailed list of packages and versions stored in the mirror")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|||||||
+125
-43
@@ -2,14 +2,15 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
"strings"
|
||||||
"github.com/smira/aptly/query"
|
"sync"
|
||||||
"github.com/smira/aptly/utils"
|
|
||||||
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/query"
|
||||||
|
"github.com/aptly-dev/aptly/utils"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
|
func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
|
||||||
@@ -21,12 +22,13 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
repo, err := context.CollectionFactory().RemoteRepoCollection().ByName(name)
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
repo, err := collectionFactory.RemoteRepoCollection().ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to update: %s", err)
|
return fmt.Errorf("unable to update: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo)
|
err = collectionFactory.RemoteRepoCollection().LoadComplete(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to update: %s", err)
|
return fmt.Errorf("unable to update: %s", err)
|
||||||
}
|
}
|
||||||
@@ -52,7 +54,7 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
context.Progress().Printf("Downloading & parsing package files...\n")
|
context.Progress().Printf("Downloading & parsing package files...\n")
|
||||||
err = repo.DownloadPackageIndexes(context.Progress(), context.Downloader(), context.CollectionFactory(), ignoreMismatch)
|
err = repo.DownloadPackageIndexes(context.Progress(), context.Downloader(), verifier, collectionFactory, ignoreMismatch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to update: %s", err)
|
return fmt.Errorf("unable to update: %s", err)
|
||||||
}
|
}
|
||||||
@@ -67,7 +69,7 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var oldLen, newLen int
|
var oldLen, newLen int
|
||||||
oldLen, newLen, err = repo.ApplyFilter(context.DependencyOptions(), filterQuery)
|
oldLen, newLen, err = repo.ApplyFilter(context.DependencyOptions(), filterQuery, context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to update: %s", err)
|
return fmt.Errorf("unable to update: %s", err)
|
||||||
}
|
}
|
||||||
@@ -79,23 +81,27 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
|
|||||||
queue []deb.PackageDownloadTask
|
queue []deb.PackageDownloadTask
|
||||||
)
|
)
|
||||||
|
|
||||||
|
skipExistingPackages := context.Flags().Lookup("skip-existing-packages").Value.Get().(bool)
|
||||||
|
|
||||||
context.Progress().Printf("Building download queue...\n")
|
context.Progress().Printf("Building download queue...\n")
|
||||||
queue, downloadSize, err = repo.BuildDownloadQueue(context.PackagePool())
|
queue, downloadSize, err = repo.BuildDownloadQueue(context.PackagePool(), collectionFactory.PackageCollection(),
|
||||||
|
collectionFactory.ChecksumCollection(nil), skipExistingPackages)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to update: %s", err)
|
return fmt.Errorf("unable to update: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
// on any interruption, unlock the mirror
|
// on any interruption, unlock the mirror
|
||||||
err := context.ReOpenDatabase()
|
err = context.ReOpenDatabase()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
repo.MarkAsIdle()
|
repo.MarkAsIdle()
|
||||||
context.CollectionFactory().RemoteRepoCollection().Update(repo)
|
collectionFactory.RemoteRepoCollection().Update(repo)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
repo.MarkAsUpdating()
|
repo.MarkAsUpdating()
|
||||||
err = context.CollectionFactory().RemoteRepoCollection().Update(repo)
|
err = collectionFactory.RemoteRepoCollection().Update(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to update: %s", err)
|
return fmt.Errorf("unable to update: %s", err)
|
||||||
}
|
}
|
||||||
@@ -105,59 +111,132 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
|
|||||||
return fmt.Errorf("unable to update: %s", err)
|
return fmt.Errorf("unable to update: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Catch ^C
|
context.GoContextHandleSignals()
|
||||||
sigch := make(chan os.Signal)
|
|
||||||
signal.Notify(sigch, os.Interrupt)
|
|
||||||
|
|
||||||
count := len(queue)
|
count := len(queue)
|
||||||
context.Progress().Printf("Download queue: %d items (%s)\n", count, utils.HumanBytes(downloadSize))
|
context.Progress().Printf("Download queue: %d items (%s)\n", count, utils.HumanBytes(downloadSize))
|
||||||
|
|
||||||
// Download from the queue
|
// Download from the queue
|
||||||
context.Progress().InitBar(downloadSize, true)
|
context.Progress().InitBar(downloadSize, true, aptly.BarMirrorUpdateDownloadPackages)
|
||||||
|
|
||||||
// Download all package files
|
downloadQueue := make(chan int)
|
||||||
ch := make(chan error, count)
|
|
||||||
|
|
||||||
// In separate goroutine (to avoid blocking main), push queue to downloader
|
var (
|
||||||
go func() {
|
errors []string
|
||||||
for _, task := range queue {
|
errLock sync.Mutex
|
||||||
context.Downloader().DownloadWithChecksum(repo.PackageURL(task.RepoURI).String(), task.DestinationPath, ch, task.Checksums, ignoreMismatch)
|
)
|
||||||
|
|
||||||
|
pushError := func(err error) {
|
||||||
|
errLock.Lock()
|
||||||
|
errors = append(errors, err.Error())
|
||||||
|
errLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't need queue after this point
|
go func() {
|
||||||
queue = nil
|
for idx := range queue {
|
||||||
|
select {
|
||||||
|
case downloadQueue <- idx:
|
||||||
|
case <-context.Done():
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(downloadQueue)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Wait for all downloads to finish
|
var wg sync.WaitGroup
|
||||||
errors := make([]string, 0)
|
|
||||||
|
|
||||||
for count > 0 {
|
for i := 0; i < context.Config().DownloadConcurrency; i++ {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
for {
|
||||||
select {
|
select {
|
||||||
case <-sigch:
|
case idx, ok := <-downloadQueue:
|
||||||
signal.Stop(sigch)
|
if !ok {
|
||||||
return fmt.Errorf("unable to update: interrupted")
|
return
|
||||||
case err = <-ch:
|
|
||||||
if err != nil {
|
|
||||||
errors = append(errors, err.Error())
|
|
||||||
}
|
}
|
||||||
count--
|
|
||||||
|
task := &queue[idx]
|
||||||
|
|
||||||
|
var e error
|
||||||
|
|
||||||
|
// provision download location
|
||||||
|
task.TempDownPath, e = context.PackagePool().(aptly.LocalPackagePool).GenerateTempPath(task.File.Filename)
|
||||||
|
if e != nil {
|
||||||
|
pushError(e)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// download file...
|
||||||
|
e = context.Downloader().DownloadWithChecksum(
|
||||||
|
context,
|
||||||
|
repo.PackageURL(task.File.DownloadURL()).String(),
|
||||||
|
task.TempDownPath,
|
||||||
|
&task.File.Checksums,
|
||||||
|
ignoreMismatch)
|
||||||
|
if e != nil {
|
||||||
|
pushError(e)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
task.Done = true
|
||||||
|
case <-context.Done():
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for all download goroutines to finish
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
context.Progress().ShutdownBar()
|
context.Progress().ShutdownBar()
|
||||||
signal.Stop(sigch)
|
|
||||||
|
|
||||||
if len(errors) > 0 {
|
|
||||||
return fmt.Errorf("unable to update: download errors:\n %s\n", strings.Join(errors, "\n "))
|
|
||||||
}
|
|
||||||
|
|
||||||
err = context.ReOpenDatabase()
|
err = context.ReOpenDatabase()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to update: %s", err)
|
return fmt.Errorf("unable to update: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.FinalizeDownload()
|
// Import downloaded files
|
||||||
err = context.CollectionFactory().RemoteRepoCollection().Update(repo)
|
context.Progress().InitBar(int64(len(queue)), false, aptly.BarMirrorUpdateImportFiles)
|
||||||
|
|
||||||
|
for idx := range queue {
|
||||||
|
context.Progress().AddBar(1)
|
||||||
|
|
||||||
|
task := &queue[idx]
|
||||||
|
|
||||||
|
if !task.Done {
|
||||||
|
// download not finished yet
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// and import it back to the pool
|
||||||
|
task.File.PoolPath, err = context.PackagePool().Import(task.TempDownPath, task.File.Filename, &task.File.Checksums, true, collectionFactory.ChecksumCollection(nil))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to import file: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// update "attached" files if any
|
||||||
|
for _, additionalTask := range task.Additional {
|
||||||
|
additionalTask.File.PoolPath = task.File.PoolPath
|
||||||
|
additionalTask.File.Checksums = task.File.Checksums
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Progress().ShutdownBar()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-context.Done():
|
||||||
|
return fmt.Errorf("unable to update: interrupted")
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(errors) > 0 {
|
||||||
|
return fmt.Errorf("unable to update: download errors:\n %s", strings.Join(errors, "\n "))
|
||||||
|
}
|
||||||
|
|
||||||
|
repo.FinalizeDownload(collectionFactory, context.Progress())
|
||||||
|
err = collectionFactory.RemoteRepoCollection().Update(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to update: %s", err)
|
return fmt.Errorf("unable to update: %s", err)
|
||||||
}
|
}
|
||||||
@@ -186,7 +265,10 @@ Example:
|
|||||||
cmd.Flag.Bool("force", false, "force update mirror even if it is locked by another process")
|
cmd.Flag.Bool("force", false, "force update mirror even if it is locked by another process")
|
||||||
cmd.Flag.Bool("ignore-checksums", false, "ignore checksum mismatches while downloading package files and metadata")
|
cmd.Flag.Bool("ignore-checksums", false, "ignore checksum mismatches while downloading package files and metadata")
|
||||||
cmd.Flag.Bool("ignore-signatures", false, "disable verification of Release file signatures")
|
cmd.Flag.Bool("ignore-signatures", false, "disable verification of Release file signatures")
|
||||||
|
cmd.Flag.Bool("skip-existing-packages", false, "do not check file existence for packages listed in the internal database of the mirror")
|
||||||
cmd.Flag.Int64("download-limit", 0, "limit download speed (kbytes/sec)")
|
cmd.Flag.Int64("download-limit", 0, "limit download speed (kbytes/sec)")
|
||||||
|
cmd.Flag.String("downloader", "default", "downloader to use (e.g. grab)")
|
||||||
|
cmd.Flag.Int("max-tries", 1, "max download tries till process fails with download error")
|
||||||
cmd.Flag.Var(&keyRingsFlag{}, "keyring", "gpg keyring to use when verifying Release file (could be specified multiple times)")
|
cmd.Flag.Var(&keyRingsFlag{}, "keyring", "gpg keyring to use when verifying Release file (could be specified multiple times)")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|||||||
+24
-12
@@ -2,33 +2,41 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"github.com/smira/aptly/query"
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/query"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyPackageSearch(cmd *commander.Command, args []string) error {
|
func aptlyPackageSearch(cmd *commander.Command, args []string) error {
|
||||||
var err error
|
var (
|
||||||
if len(args) != 1 {
|
err error
|
||||||
|
q deb.PackageQuery
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(args) > 1 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
q, err := query.Parse(args[0])
|
if len(args) == 1 {
|
||||||
|
q, err = query.Parse(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to search: %s", err)
|
return fmt.Errorf("unable to search: %s", err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
q = &deb.MatchAllQuery{}
|
||||||
|
}
|
||||||
|
|
||||||
result := q.Query(context.CollectionFactory().PackageCollection())
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
result := q.Query(collectionFactory.PackageCollection())
|
||||||
if result.Len() == 0 {
|
if result.Len() == 0 {
|
||||||
return fmt.Errorf("no results")
|
return fmt.Errorf("no results")
|
||||||
}
|
}
|
||||||
|
|
||||||
result.ForEach(func(p *deb.Package) error {
|
format := context.Flags().Lookup("format").Value.String()
|
||||||
context.Progress().Printf("%s\n", p)
|
PrintPackageList(result, format, "")
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -36,10 +44,12 @@ func aptlyPackageSearch(cmd *commander.Command, args []string) error {
|
|||||||
func makeCmdPackageSearch() *commander.Command {
|
func makeCmdPackageSearch() *commander.Command {
|
||||||
cmd := &commander.Command{
|
cmd := &commander.Command{
|
||||||
Run: aptlyPackageSearch,
|
Run: aptlyPackageSearch,
|
||||||
UsageLine: "search <package-query>",
|
UsageLine: "search [<package-query>]",
|
||||||
Short: "search for packages matching query",
|
Short: "search for packages matching query",
|
||||||
Long: `
|
Long: `
|
||||||
Command search displays list of packages in whole DB that match package query
|
Command search displays list of packages in whole DB that match package query.
|
||||||
|
|
||||||
|
If query is not specified, all the packages are displayed.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@@ -48,5 +58,7 @@ Example:
|
|||||||
Flag: *flag.NewFlagSet("aptly-package-search", flag.ExitOnError),
|
Flag: *flag.NewFlagSet("aptly-package-search", flag.ExitOnError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.Flag.String("format", "", "custom format for result printing")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-25
@@ -3,18 +3,20 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
"os"
|
||||||
"github.com/smira/aptly/query"
|
|
||||||
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/query"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func printReferencesTo(p *deb.Package) (err error) {
|
func printReferencesTo(p *deb.Package, collectionFactory *deb.CollectionFactory) (err error) {
|
||||||
err = context.CollectionFactory().RemoteRepoCollection().ForEach(func(repo *deb.RemoteRepo) error {
|
err = collectionFactory.RemoteRepoCollection().ForEach(func(repo *deb.RemoteRepo) error {
|
||||||
err := context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo)
|
e := collectionFactory.RemoteRepoCollection().LoadComplete(repo)
|
||||||
if err != nil {
|
if e != nil {
|
||||||
return err
|
return e
|
||||||
}
|
}
|
||||||
if repo.RefList() != nil {
|
if repo.RefList() != nil {
|
||||||
if repo.RefList().Has(p) {
|
if repo.RefList().Has(p) {
|
||||||
@@ -27,10 +29,10 @@ func printReferencesTo(p *deb.Package) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().ForEach(func(repo *deb.LocalRepo) error {
|
err = collectionFactory.LocalRepoCollection().ForEach(func(repo *deb.LocalRepo) error {
|
||||||
err := context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
e := collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||||
if err != nil {
|
if e != nil {
|
||||||
return err
|
return e
|
||||||
}
|
}
|
||||||
if repo.RefList() != nil {
|
if repo.RefList() != nil {
|
||||||
if repo.RefList().Has(p) {
|
if repo.RefList().Has(p) {
|
||||||
@@ -43,21 +45,18 @@ func printReferencesTo(p *deb.Package) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().ForEach(func(snapshot *deb.Snapshot) error {
|
err = collectionFactory.SnapshotCollection().ForEach(func(snapshot *deb.Snapshot) error {
|
||||||
err := context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot)
|
e := collectionFactory.SnapshotCollection().LoadComplete(snapshot)
|
||||||
if err != nil {
|
if e != nil {
|
||||||
return err
|
return e
|
||||||
}
|
}
|
||||||
if snapshot.RefList().Has(p) {
|
if snapshot.RefList().Has(p) {
|
||||||
fmt.Printf(" snapshot %s\n", snapshot)
|
fmt.Printf(" snapshot %s\n", snapshot)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func aptlyPackageShow(cmd *commander.Command, args []string) error {
|
func aptlyPackageShow(cmd *commander.Command, args []string) error {
|
||||||
@@ -77,20 +76,28 @@ func aptlyPackageShow(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
w := bufio.NewWriter(os.Stdout)
|
w := bufio.NewWriter(os.Stdout)
|
||||||
|
|
||||||
result := q.Query(context.CollectionFactory().PackageCollection())
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
result := q.Query(collectionFactory.PackageCollection())
|
||||||
|
|
||||||
err = result.ForEach(func(p *deb.Package) error {
|
err = result.ForEach(func(p *deb.Package) error {
|
||||||
p.Stanza().WriteTo(w, p.IsSource, false)
|
p.Stanza().WriteTo(w, p.IsSource, false, false)
|
||||||
w.Flush()
|
w.Flush()
|
||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
|
|
||||||
if withFiles {
|
if withFiles {
|
||||||
fmt.Printf("Files in the pool:\n")
|
fmt.Printf("Files in the pool:\n")
|
||||||
|
packagePool := context.PackagePool()
|
||||||
for _, f := range p.Files() {
|
for _, f := range p.Files() {
|
||||||
path, err := context.PackagePool().Path(f.Filename, f.Checksums.MD5)
|
var path string
|
||||||
|
path, err = f.GetPoolPath(packagePool)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pp, ok := packagePool.(aptly.LocalPackagePool); ok {
|
||||||
|
path = pp.FullPath(path)
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf(" %s\n", path)
|
fmt.Printf(" %s\n", path)
|
||||||
}
|
}
|
||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
@@ -98,7 +105,7 @@ func aptlyPackageShow(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
if withReferences {
|
if withReferences {
|
||||||
fmt.Printf("References to package:\n")
|
fmt.Printf("References to package:\n")
|
||||||
printReferencesTo(p)
|
printReferencesTo(p, collectionFactory)
|
||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +132,7 @@ inclusion into mirrors/snapshots/local repos is shown.
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
$ aptly package show nginx-light_1.2.1-2.2+wheezy2_i386'
|
$ aptly package show 'nginx-light_1.2.1-2.2+wheezy2_i386'
|
||||||
`,
|
`,
|
||||||
Flag: *flag.NewFlagSet("aptly-package-show", flag.ExitOnError),
|
Flag: *flag.NewFlagSet("aptly-package-show", flag.ExitOnError),
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -1,17 +1,17 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/smira/aptly/utils"
|
"github.com/aptly-dev/aptly/pgp"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getSigner(flags *flag.FlagSet) (utils.Signer, error) {
|
func getSigner(flags *flag.FlagSet) (pgp.Signer, error) {
|
||||||
if LookupOption(context.Config().GpgDisableSign, flags, "skip-signing") {
|
if LookupOption(context.Config().GpgDisableSign, flags, "skip-signing") {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
signer := &utils.GpgSigner{}
|
signer := context.GetSigner()
|
||||||
signer.SetKey(flags.Lookup("gpg-key").Value.String())
|
signer.SetKey(flags.Lookup("gpg-key").Value.String())
|
||||||
signer.SetKeyRing(flags.Lookup("keyring").Value.String(), flags.Lookup("secret-keyring").Value.String())
|
signer.SetKeyRing(flags.Lookup("keyring").Value.String(), flags.Lookup("secret-keyring").Value.String())
|
||||||
signer.SetPassphrase(flags.Lookup("passphrase").Value.String(), flags.Lookup("passphrase-file").Value.String())
|
signer.SetPassphrase(flags.Lookup("passphrase").Value.String(), flags.Lookup("passphrase-file").Value.String())
|
||||||
@@ -37,6 +37,7 @@ func makeCmdPublish() *commander.Command {
|
|||||||
makeCmdPublishSnapshot(),
|
makeCmdPublishSnapshot(),
|
||||||
makeCmdPublishSwitch(),
|
makeCmdPublishSwitch(),
|
||||||
makeCmdPublishUpdate(),
|
makeCmdPublishUpdate(),
|
||||||
|
makeCmdPublishShow(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-3
@@ -2,7 +2,8 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -22,8 +23,11 @@ func aptlyPublishDrop(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
storage, prefix := deb.ParsePrefix(param)
|
storage, prefix := deb.ParsePrefix(param)
|
||||||
|
|
||||||
err = context.CollectionFactory().PublishedRepoCollection().Remove(context, storage, prefix, distribution,
|
collectionFactory := context.NewCollectionFactory()
|
||||||
context.CollectionFactory(), context.Progress())
|
err = collectionFactory.PublishedRepoCollection().Remove(context, storage, prefix, distribution,
|
||||||
|
collectionFactory, context.Progress(),
|
||||||
|
context.Flags().Lookup("force-drop").Value.Get().(bool),
|
||||||
|
context.Flags().Lookup("skip-cleanup").Value.Get().(bool))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to remove: %s", err)
|
return fmt.Errorf("unable to remove: %s", err)
|
||||||
}
|
}
|
||||||
@@ -48,5 +52,8 @@ Example:
|
|||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.Flag.Bool("force-drop", false, "remove published repository even if some files could not be cleaned up")
|
||||||
|
cmd.Flag.Bool("skip-cleanup", false, "don't remove unreferenced files in prefix/component")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
+62
-8
@@ -1,27 +1,44 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
"os"
|
||||||
"github.com/smira/commander"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/smira/commander"
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyPublishList(cmd *commander.Command, args []string) error {
|
func aptlyPublishList(cmd *commander.Command, args []string) error {
|
||||||
var err error
|
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jsonFlag := cmd.Flag.Lookup("json").Value.Get().(bool)
|
||||||
|
|
||||||
|
if jsonFlag {
|
||||||
|
return aptlyPublishListJSON(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
return aptlyPublishListTxt(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func aptlyPublishListTxt(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
|
raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
|
||||||
|
|
||||||
published := make([]string, 0, context.CollectionFactory().PublishedRepoCollection().Len())
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
published := make([]string, 0, collectionFactory.PublishedRepoCollection().Len())
|
||||||
|
|
||||||
err = context.CollectionFactory().PublishedRepoCollection().ForEach(func(repo *deb.PublishedRepo) error {
|
err = collectionFactory.PublishedRepoCollection().ForEach(func(repo *deb.PublishedRepo) error {
|
||||||
err := context.CollectionFactory().PublishedRepoCollection().LoadComplete(repo, context.CollectionFactory())
|
e := collectionFactory.PublishedRepoCollection().LoadComplete(repo, collectionFactory)
|
||||||
if err != nil {
|
if e != nil {
|
||||||
return err
|
fmt.Fprintf(os.Stderr, "Error found on one publish (prefix:%s / distribution:%s / component:%s\n)",
|
||||||
|
repo.StoragePrefix(), repo.Distribution, repo.Components())
|
||||||
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
if raw {
|
if raw {
|
||||||
@@ -60,6 +77,42 @@ func aptlyPublishList(cmd *commander.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func aptlyPublishListJSON(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
repos := make([]*deb.PublishedRepo, 0, context.NewCollectionFactory().PublishedRepoCollection().Len())
|
||||||
|
|
||||||
|
err = context.NewCollectionFactory().PublishedRepoCollection().ForEach(func(repo *deb.PublishedRepo) error {
|
||||||
|
e := context.NewCollectionFactory().PublishedRepoCollection().LoadComplete(repo, context.NewCollectionFactory())
|
||||||
|
if e != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error found on one publish (prefix:%s / distribution:%s / component:%s\n)",
|
||||||
|
repo.StoragePrefix(), repo.Distribution, repo.Components())
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
repos = append(repos, repo)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to load list of repos: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
context.CloseDatabase()
|
||||||
|
|
||||||
|
sort.Slice(repos, func(i, j int) bool {
|
||||||
|
return repos[i].GetPath() < repos[j].GetPath()
|
||||||
|
})
|
||||||
|
if output, e := json.MarshalIndent(repos, "", " "); e == nil {
|
||||||
|
fmt.Println(string(output))
|
||||||
|
} else {
|
||||||
|
err = e
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func makeCmdPublishList() *commander.Command {
|
func makeCmdPublishList() *commander.Command {
|
||||||
cmd := &commander.Command{
|
cmd := &commander.Command{
|
||||||
Run: aptlyPublishList,
|
Run: aptlyPublishList,
|
||||||
@@ -74,6 +127,7 @@ Example:
|
|||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.Flag.Bool("json", false, "display list in JSON format")
|
||||||
cmd.Flag.Bool("raw", false, "display list in machine-readable format")
|
cmd.Flag.Bool("raw", false, "display list in machine-readable format")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|||||||
+8
-2
@@ -37,13 +37,19 @@ Example:
|
|||||||
cmd.Flag.String("gpg-key", "", "GPG key ID to use when signing the release")
|
cmd.Flag.String("gpg-key", "", "GPG key ID to use when signing the release")
|
||||||
cmd.Flag.Var(&keyRingsFlag{}, "keyring", "GPG keyring to use (instead of default)")
|
cmd.Flag.Var(&keyRingsFlag{}, "keyring", "GPG keyring to use (instead of default)")
|
||||||
cmd.Flag.String("secret-keyring", "", "GPG secret keyring to use (instead of default)")
|
cmd.Flag.String("secret-keyring", "", "GPG secret keyring to use (instead of default)")
|
||||||
cmd.Flag.String("passphrase", "", "GPG passhprase for the key (warning: could be insecure)")
|
cmd.Flag.String("passphrase", "", "GPG passphrase for the key (warning: could be insecure)")
|
||||||
cmd.Flag.String("passphrase-file", "", "GPG passhprase-file for the key (warning: could be insecure)")
|
cmd.Flag.String("passphrase-file", "", "GPG passphrase-file for the key (warning: could be insecure)")
|
||||||
cmd.Flag.Bool("batch", false, "run GPG with detached tty")
|
cmd.Flag.Bool("batch", false, "run GPG with detached tty")
|
||||||
cmd.Flag.Bool("skip-signing", false, "don't sign Release files with GPG")
|
cmd.Flag.Bool("skip-signing", false, "don't sign Release files with GPG")
|
||||||
|
cmd.Flag.Bool("skip-contents", false, "don't generate Contents indexes")
|
||||||
|
cmd.Flag.Bool("skip-bz2", false, "don't generate bzipped indexes")
|
||||||
cmd.Flag.String("origin", "", "origin name to publish")
|
cmd.Flag.String("origin", "", "origin name to publish")
|
||||||
|
cmd.Flag.String("notautomatic", "", "set value for NotAutomatic field")
|
||||||
|
cmd.Flag.String("butautomaticupgrades", "", "set value for ButAutomaticUpgrades field")
|
||||||
cmd.Flag.String("label", "", "label to publish")
|
cmd.Flag.String("label", "", "label to publish")
|
||||||
|
cmd.Flag.String("suite", "", "suite to publish (defaults to distribution)")
|
||||||
cmd.Flag.Bool("force-overwrite", false, "overwrite files in package pool in case of mismatch")
|
cmd.Flag.Bool("force-overwrite", false, "overwrite files in package pool in case of mismatch")
|
||||||
|
cmd.Flag.Bool("acquire-by-hash", false, "provide index files by hash")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,126 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/smira/commander"
|
||||||
|
)
|
||||||
|
|
||||||
|
func aptlyPublishShow(cmd *commander.Command, args []string) error {
|
||||||
|
if len(args) < 1 || len(args) > 2 {
|
||||||
|
cmd.Usage()
|
||||||
|
return commander.ErrCommandError
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonFlag := cmd.Flag.Lookup("json").Value.Get().(bool)
|
||||||
|
|
||||||
|
if jsonFlag {
|
||||||
|
return aptlyPublishShowJSON(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
return aptlyPublishShowTxt(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func aptlyPublishShowTxt(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
distribution := args[0]
|
||||||
|
param := "."
|
||||||
|
|
||||||
|
if len(args) == 2 {
|
||||||
|
param = args[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
storage, prefix := deb.ParsePrefix(param)
|
||||||
|
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
repo, err := collectionFactory.PublishedRepoCollection().ByStoragePrefixDistribution(storage, prefix, distribution)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to show: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if repo.Storage != "" {
|
||||||
|
fmt.Printf("Storage: %s\n", repo.Storage)
|
||||||
|
}
|
||||||
|
fmt.Printf("Prefix: %s\n", repo.Prefix)
|
||||||
|
if repo.Distribution != "" {
|
||||||
|
fmt.Printf("Distribution: %s\n", repo.Distribution)
|
||||||
|
}
|
||||||
|
fmt.Printf("Architectures: %s\n", strings.Join(repo.Architectures, " "))
|
||||||
|
|
||||||
|
fmt.Printf("Sources:\n")
|
||||||
|
for component, sourceID := range repo.Sources {
|
||||||
|
var name string
|
||||||
|
if repo.SourceKind == deb.SourceSnapshot {
|
||||||
|
source, e := collectionFactory.SnapshotCollection().ByUUID(sourceID)
|
||||||
|
if e != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
name = source.Name
|
||||||
|
} else if repo.SourceKind == deb.SourceLocalRepo {
|
||||||
|
source, e := collectionFactory.LocalRepoCollection().ByUUID(sourceID)
|
||||||
|
if e != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
name = source.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
if name != "" {
|
||||||
|
fmt.Printf(" %s: %s [%s]\n", component, name, repo.SourceKind)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func aptlyPublishShowJSON(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
distribution := args[0]
|
||||||
|
param := "."
|
||||||
|
|
||||||
|
if len(args) == 2 {
|
||||||
|
param = args[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
storage, prefix := deb.ParsePrefix(param)
|
||||||
|
|
||||||
|
repo, err := context.NewCollectionFactory().PublishedRepoCollection().ByStoragePrefixDistribution(storage, prefix, distribution)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to show: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = context.NewCollectionFactory().PublishedRepoCollection().LoadComplete(repo, context.NewCollectionFactory())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var output []byte
|
||||||
|
if output, err = json.MarshalIndent(repo, "", " "); err == nil {
|
||||||
|
fmt.Println(string(output))
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeCmdPublishShow() *commander.Command {
|
||||||
|
cmd := &commander.Command{
|
||||||
|
Run: aptlyPublishShow,
|
||||||
|
UsageLine: "show <distribution> [[<endpoint>:]<prefix>]",
|
||||||
|
Short: "shows details of published repository",
|
||||||
|
Long: `
|
||||||
|
Command show displays full information of a published repository.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
$ aptly publish show wheezy
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Flag.Bool("json", false, "display record in JSON format")
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
+57
-22
@@ -2,18 +2,20 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/aptly"
|
"strings"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"github.com/smira/aptly/utils"
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/utils"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
|
func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
components := strings.Split(context.Flags().Lookup("component").Value.String(), ",")
|
components := strings.Split(context.Flags().Lookup("component").Value.String(), ",")
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
|
||||||
if len(args) < len(components) || len(args) > len(components)+1 {
|
if len(args) < len(components) || len(args) > len(components)+1 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
@@ -34,7 +36,7 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
|
|||||||
message string
|
message string
|
||||||
)
|
)
|
||||||
|
|
||||||
if cmd.Name() == "snapshot" {
|
if cmd.Name() == "snapshot" { // nolint: goconst
|
||||||
var (
|
var (
|
||||||
snapshot *deb.Snapshot
|
snapshot *deb.Snapshot
|
||||||
emptyWarning = false
|
emptyWarning = false
|
||||||
@@ -42,12 +44,12 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
|
|||||||
)
|
)
|
||||||
|
|
||||||
for _, name := range args {
|
for _, name := range args {
|
||||||
snapshot, err = context.CollectionFactory().SnapshotCollection().ByName(name)
|
snapshot, err = collectionFactory.SnapshotCollection().ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to publish: %s", err)
|
return fmt.Errorf("unable to publish: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot)
|
err = collectionFactory.SnapshotCollection().LoadComplete(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to publish: %s", err)
|
return fmt.Errorf("unable to publish: %s", err)
|
||||||
}
|
}
|
||||||
@@ -70,7 +72,7 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
|
|||||||
if emptyWarning {
|
if emptyWarning {
|
||||||
context.Progress().Printf("Warning: publishing from empty source, architectures list should be complete, it can't be changed after publishing (use -architectures flag)\n")
|
context.Progress().Printf("Warning: publishing from empty source, architectures list should be complete, it can't be changed after publishing (use -architectures flag)\n")
|
||||||
}
|
}
|
||||||
} else if cmd.Name() == "repo" {
|
} else if cmd.Name() == "repo" { // nolint: goconst
|
||||||
var (
|
var (
|
||||||
localRepo *deb.LocalRepo
|
localRepo *deb.LocalRepo
|
||||||
emptyWarning = false
|
emptyWarning = false
|
||||||
@@ -78,12 +80,12 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
|
|||||||
)
|
)
|
||||||
|
|
||||||
for _, name := range args {
|
for _, name := range args {
|
||||||
localRepo, err = context.CollectionFactory().LocalRepoCollection().ByName(name)
|
localRepo, err = collectionFactory.LocalRepoCollection().ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to publish: %s", err)
|
return fmt.Errorf("unable to publish: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().LoadComplete(localRepo)
|
err = collectionFactory.LocalRepoCollection().LoadComplete(localRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to publish: %s", err)
|
return fmt.Errorf("unable to publish: %s", err)
|
||||||
}
|
}
|
||||||
@@ -111,17 +113,44 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
distribution := context.Flags().Lookup("distribution").Value.String()
|
distribution := context.Flags().Lookup("distribution").Value.String()
|
||||||
|
origin := context.Flags().Lookup("origin").Value.String()
|
||||||
|
notAutomatic := context.Flags().Lookup("notautomatic").Value.String()
|
||||||
|
butAutomaticUpgrades := context.Flags().Lookup("butautomaticupgrades").Value.String()
|
||||||
|
|
||||||
published, err := deb.NewPublishedRepo(storage, prefix, distribution, context.ArchitecturesList(), components, sources, context.CollectionFactory())
|
published, err := deb.NewPublishedRepo(storage, prefix, distribution, context.ArchitecturesList(), components, sources, collectionFactory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to publish: %s", err)
|
return fmt.Errorf("unable to publish: %s", err)
|
||||||
}
|
}
|
||||||
published.Origin = cmd.Flag.Lookup("origin").Value.String()
|
if origin != "" {
|
||||||
published.Label = cmd.Flag.Lookup("label").Value.String()
|
published.Origin = origin
|
||||||
|
}
|
||||||
|
if notAutomatic != "" {
|
||||||
|
published.NotAutomatic = notAutomatic
|
||||||
|
}
|
||||||
|
if butAutomaticUpgrades != "" {
|
||||||
|
published.ButAutomaticUpgrades = butAutomaticUpgrades
|
||||||
|
}
|
||||||
|
published.Label = context.Flags().Lookup("label").Value.String()
|
||||||
|
published.Suite = context.Flags().Lookup("suite").Value.String()
|
||||||
|
|
||||||
duplicate := context.CollectionFactory().PublishedRepoCollection().CheckDuplicate(published)
|
published.SkipContents = context.Config().SkipContentsPublishing
|
||||||
|
|
||||||
|
if context.Flags().IsSet("skip-contents") {
|
||||||
|
published.SkipContents = context.Flags().Lookup("skip-contents").Value.Get().(bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
published.SkipBz2 = context.Config().SkipBz2Publishing
|
||||||
|
if context.Flags().IsSet("skip-bz2") {
|
||||||
|
published.SkipBz2 = context.Flags().Lookup("skip-bz2").Value.Get().(bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
if context.Flags().IsSet("acquire-by-hash") {
|
||||||
|
published.AcquireByHash = context.Flags().Lookup("acquire-by-hash").Value.Get().(bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
duplicate := collectionFactory.PublishedRepoCollection().CheckDuplicate(published)
|
||||||
if duplicate != nil {
|
if duplicate != nil {
|
||||||
context.CollectionFactory().PublishedRepoCollection().LoadComplete(duplicate, context.CollectionFactory())
|
collectionFactory.PublishedRepoCollection().LoadComplete(duplicate, collectionFactory)
|
||||||
return fmt.Errorf("prefix/distribution already used by another published repo: %s", duplicate)
|
return fmt.Errorf("prefix/distribution already used by another published repo: %s", duplicate)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,12 +165,12 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
|
|||||||
"the same package pool.\n")
|
"the same package pool.\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = published.Publish(context.PackagePool(), context, context.CollectionFactory(), signer, context.Progress(), forceOverwrite)
|
err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to publish: %s", err)
|
return fmt.Errorf("unable to publish: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().PublishedRepoCollection().Add(published)
|
err = collectionFactory.PublishedRepoCollection().Add(published)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to save to DB: %s", err)
|
return fmt.Errorf("unable to save to DB: %s", err)
|
||||||
}
|
}
|
||||||
@@ -156,14 +185,14 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
context.Progress().Printf("\n%s been successfully published.\n", message)
|
context.Progress().Printf("\n%s been successfully published.\n", message)
|
||||||
|
|
||||||
if localStorage, ok := context.GetPublishedStorage(storage).(aptly.LocalPublishedStorage); ok {
|
if localStorage, ok := context.GetPublishedStorage(storage).(aptly.FileSystemPublishedStorage); ok {
|
||||||
context.Progress().Printf("Please setup your webserver to serve directory '%s' with autoindexing.\n",
|
context.Progress().Printf("Please setup your webserver to serve directory '%s' with autoindexing.\n",
|
||||||
localStorage.PublicPath())
|
localStorage.PublicPath())
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Progress().Printf("Now you can add following line to apt sources:\n")
|
context.Progress().Printf("Now you can add following line to apt sources:\n")
|
||||||
context.Progress().Printf(" deb http://your-server/%s %s %s\n", prefix, distribution, repoComponents)
|
context.Progress().Printf(" deb http://your-server/%s %s %s\n", prefix, distribution, repoComponents)
|
||||||
if utils.StrSliceHasItem(published.Architectures, "source") {
|
if utils.StrSliceHasItem(published.Architectures, deb.ArchitectureSource) {
|
||||||
context.Progress().Printf(" deb-src http://your-server/%s %s %s\n", prefix, distribution, repoComponents)
|
context.Progress().Printf(" deb-src http://your-server/%s %s %s\n", prefix, distribution, repoComponents)
|
||||||
}
|
}
|
||||||
context.Progress().Printf("Don't forget to add your GPG key to apt with apt-key.\n")
|
context.Progress().Printf("Don't forget to add your GPG key to apt with apt-key.\n")
|
||||||
@@ -199,13 +228,19 @@ Example:
|
|||||||
cmd.Flag.String("gpg-key", "", "GPG key ID to use when signing the release")
|
cmd.Flag.String("gpg-key", "", "GPG key ID to use when signing the release")
|
||||||
cmd.Flag.Var(&keyRingsFlag{}, "keyring", "GPG keyring to use (instead of default)")
|
cmd.Flag.Var(&keyRingsFlag{}, "keyring", "GPG keyring to use (instead of default)")
|
||||||
cmd.Flag.String("secret-keyring", "", "GPG secret keyring to use (instead of default)")
|
cmd.Flag.String("secret-keyring", "", "GPG secret keyring to use (instead of default)")
|
||||||
cmd.Flag.String("passphrase", "", "GPG passhprase for the key (warning: could be insecure)")
|
cmd.Flag.String("passphrase", "", "GPG passphrase for the key (warning: could be insecure)")
|
||||||
cmd.Flag.String("passphrase-file", "", "GPG passhprase-file for the key (warning: could be insecure)")
|
cmd.Flag.String("passphrase-file", "", "GPG passphrase-file for the key (warning: could be insecure)")
|
||||||
cmd.Flag.Bool("batch", false, "run GPG with detached tty")
|
cmd.Flag.Bool("batch", false, "run GPG with detached tty")
|
||||||
cmd.Flag.Bool("skip-signing", false, "don't sign Release files with GPG")
|
cmd.Flag.Bool("skip-signing", false, "don't sign Release files with GPG")
|
||||||
cmd.Flag.String("origin", "", "origin name to publish")
|
cmd.Flag.Bool("skip-contents", false, "don't generate Contents indexes")
|
||||||
|
cmd.Flag.Bool("skip-bz2", false, "don't generate bzipped indexes")
|
||||||
|
cmd.Flag.String("origin", "", "overwrite origin name to publish")
|
||||||
|
cmd.Flag.String("notautomatic", "", "overwrite value for NotAutomatic field")
|
||||||
|
cmd.Flag.String("butautomaticupgrades", "", "overwrite value for ButAutomaticUpgrades field")
|
||||||
cmd.Flag.String("label", "", "label to publish")
|
cmd.Flag.String("label", "", "label to publish")
|
||||||
|
cmd.Flag.String("suite", "", "suite to publish (defaults to distribution)")
|
||||||
cmd.Flag.Bool("force-overwrite", false, "overwrite files in package pool in case of mismatch")
|
cmd.Flag.Bool("force-overwrite", false, "overwrite files in package pool in case of mismatch")
|
||||||
|
cmd.Flag.Bool("acquire-by-hash", false, "provide index files by hash")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-14
@@ -2,11 +2,12 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
"strings"
|
||||||
"github.com/smira/aptly/utils"
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/utils"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyPublishSwitch(cmd *commander.Command, args []string) error {
|
func aptlyPublishSwitch(cmd *commander.Command, args []string) error {
|
||||||
@@ -38,16 +39,17 @@ func aptlyPublishSwitch(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
var published *deb.PublishedRepo
|
var published *deb.PublishedRepo
|
||||||
|
|
||||||
published, err = context.CollectionFactory().PublishedRepoCollection().ByStoragePrefixDistribution(storage, prefix, distribution)
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
published, err = collectionFactory.PublishedRepoCollection().ByStoragePrefixDistribution(storage, prefix, distribution)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to update: %s", err)
|
return fmt.Errorf("unable to update: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if published.SourceKind != "snapshot" {
|
if published.SourceKind != deb.SourceSnapshot {
|
||||||
return fmt.Errorf("unable to update: not a snapshot publish")
|
return fmt.Errorf("unable to update: not a snapshot publish")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().PublishedRepoCollection().LoadComplete(published, context.CollectionFactory())
|
err = collectionFactory.PublishedRepoCollection().LoadComplete(published, collectionFactory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to update: %s", err)
|
return fmt.Errorf("unable to update: %s", err)
|
||||||
}
|
}
|
||||||
@@ -66,12 +68,12 @@ func aptlyPublishSwitch(cmd *commander.Command, args []string) error {
|
|||||||
return fmt.Errorf("unable to switch: component %s is not in published repository", component)
|
return fmt.Errorf("unable to switch: component %s is not in published repository", component)
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshot, err = context.CollectionFactory().SnapshotCollection().ByName(names[i])
|
snapshot, err = collectionFactory.SnapshotCollection().ByName(names[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to switch: %s", err)
|
return fmt.Errorf("unable to switch: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot)
|
err = collectionFactory.SnapshotCollection().LoadComplete(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to switch: %s", err)
|
return fmt.Errorf("unable to switch: %s", err)
|
||||||
}
|
}
|
||||||
@@ -90,21 +92,32 @@ func aptlyPublishSwitch(cmd *commander.Command, args []string) error {
|
|||||||
"the same package pool.\n")
|
"the same package pool.\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = published.Publish(context.PackagePool(), context, context.CollectionFactory(), signer, context.Progress(), forceOverwrite)
|
if context.Flags().IsSet("skip-contents") {
|
||||||
|
published.SkipContents = context.Flags().Lookup("skip-contents").Value.Get().(bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
if context.Flags().IsSet("skip-bz2") {
|
||||||
|
published.SkipBz2 = context.Flags().Lookup("skip-bz2").Value.Get().(bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to publish: %s", err)
|
return fmt.Errorf("unable to publish: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().PublishedRepoCollection().Update(published)
|
err = collectionFactory.PublishedRepoCollection().Update(published)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to save to DB: %s", err)
|
return fmt.Errorf("unable to save to DB: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().PublishedRepoCollection().CleanupPrefixComponentFiles(published.Prefix, components,
|
skipCleanup := context.Flags().Lookup("skip-cleanup").Value.Get().(bool)
|
||||||
context.GetPublishedStorage(storage), context.CollectionFactory(), context.Progress())
|
if !skipCleanup {
|
||||||
|
err = collectionFactory.PublishedRepoCollection().CleanupPrefixComponentFiles(published.Prefix, components,
|
||||||
|
context.GetPublishedStorage(storage), collectionFactory, context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to update: %s", err)
|
return fmt.Errorf("unable to update: %s", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
context.Progress().Printf("\nPublish for snapshot %s has been successfully switched to new snapshot.\n", published.String())
|
context.Progress().Printf("\nPublish for snapshot %s has been successfully switched to new snapshot.\n", published.String())
|
||||||
|
|
||||||
@@ -139,12 +152,15 @@ This command would switch published repository (with one component) named ppa/wh
|
|||||||
cmd.Flag.String("gpg-key", "", "GPG key ID to use when signing the release")
|
cmd.Flag.String("gpg-key", "", "GPG key ID to use when signing the release")
|
||||||
cmd.Flag.Var(&keyRingsFlag{}, "keyring", "GPG keyring to use (instead of default)")
|
cmd.Flag.Var(&keyRingsFlag{}, "keyring", "GPG keyring to use (instead of default)")
|
||||||
cmd.Flag.String("secret-keyring", "", "GPG secret keyring to use (instead of default)")
|
cmd.Flag.String("secret-keyring", "", "GPG secret keyring to use (instead of default)")
|
||||||
cmd.Flag.String("passphrase", "", "GPG passhprase for the key (warning: could be insecure)")
|
cmd.Flag.String("passphrase", "", "GPG passphrase for the key (warning: could be insecure)")
|
||||||
cmd.Flag.String("passphrase-file", "", "GPG passhprase-file for the key (warning: could be insecure)")
|
cmd.Flag.String("passphrase-file", "", "GPG passphrase-file for the key (warning: could be insecure)")
|
||||||
cmd.Flag.Bool("batch", false, "run GPG with detached tty")
|
cmd.Flag.Bool("batch", false, "run GPG with detached tty")
|
||||||
cmd.Flag.Bool("skip-signing", false, "don't sign Release files with GPG")
|
cmd.Flag.Bool("skip-signing", false, "don't sign Release files with GPG")
|
||||||
|
cmd.Flag.Bool("skip-contents", false, "don't generate Contents indexes")
|
||||||
|
cmd.Flag.Bool("skip-bz2", false, "don't generate bzipped indexes")
|
||||||
cmd.Flag.String("component", "", "component names to update (for multi-component publishing, separate components with commas)")
|
cmd.Flag.String("component", "", "component names to update (for multi-component publishing, separate components with commas)")
|
||||||
cmd.Flag.Bool("force-overwrite", false, "overwrite files in package pool in case of mismatch")
|
cmd.Flag.Bool("force-overwrite", false, "overwrite files in package pool in case of mismatch")
|
||||||
|
cmd.Flag.Bool("skip-cleanup", false, "don't remove unreferenced files in prefix/component")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-10
@@ -2,7 +2,8 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
@@ -24,16 +25,17 @@ func aptlyPublishUpdate(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
var published *deb.PublishedRepo
|
var published *deb.PublishedRepo
|
||||||
|
|
||||||
published, err = context.CollectionFactory().PublishedRepoCollection().ByStoragePrefixDistribution(storage, prefix, distribution)
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
published, err = collectionFactory.PublishedRepoCollection().ByStoragePrefixDistribution(storage, prefix, distribution)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to update: %s", err)
|
return fmt.Errorf("unable to update: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if published.SourceKind != "local" {
|
if published.SourceKind != deb.SourceLocalRepo {
|
||||||
return fmt.Errorf("unable to update: not a local repository publish")
|
return fmt.Errorf("unable to update: not a local repository publish")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().PublishedRepoCollection().LoadComplete(published, context.CollectionFactory())
|
err = collectionFactory.PublishedRepoCollection().LoadComplete(published, collectionFactory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to update: %s", err)
|
return fmt.Errorf("unable to update: %s", err)
|
||||||
}
|
}
|
||||||
@@ -54,21 +56,32 @@ func aptlyPublishUpdate(cmd *commander.Command, args []string) error {
|
|||||||
"the same package pool.\n")
|
"the same package pool.\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = published.Publish(context.PackagePool(), context, context.CollectionFactory(), signer, context.Progress(), forceOverwrite)
|
if context.Flags().IsSet("skip-contents") {
|
||||||
|
published.SkipContents = context.Flags().Lookup("skip-contents").Value.Get().(bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
if context.Flags().IsSet("skip-bz2") {
|
||||||
|
published.SkipBz2 = context.Flags().Lookup("skip-bz2").Value.Get().(bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = published.Publish(context.PackagePool(), context, collectionFactory, signer, context.Progress(), forceOverwrite)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to publish: %s", err)
|
return fmt.Errorf("unable to publish: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().PublishedRepoCollection().Update(published)
|
err = collectionFactory.PublishedRepoCollection().Update(published)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to save to DB: %s", err)
|
return fmt.Errorf("unable to save to DB: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().PublishedRepoCollection().CleanupPrefixComponentFiles(published.Prefix, components,
|
skipCleanup := context.Flags().Lookup("skip-cleanup").Value.Get().(bool)
|
||||||
context.GetPublishedStorage(storage), context.CollectionFactory(), context.Progress())
|
if !skipCleanup {
|
||||||
|
err = collectionFactory.PublishedRepoCollection().CleanupPrefixComponentFiles(published.Prefix, components,
|
||||||
|
context.GetPublishedStorage(storage), collectionFactory, context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to update: %s", err)
|
return fmt.Errorf("unable to update: %s", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
context.Progress().Printf("\nPublish for local repo %s has been successfully updated.\n", published.String())
|
context.Progress().Printf("\nPublish for local repo %s has been successfully updated.\n", published.String())
|
||||||
|
|
||||||
@@ -98,11 +111,14 @@ Example:
|
|||||||
cmd.Flag.String("gpg-key", "", "GPG key ID to use when signing the release")
|
cmd.Flag.String("gpg-key", "", "GPG key ID to use when signing the release")
|
||||||
cmd.Flag.Var(&keyRingsFlag{}, "keyring", "GPG keyring to use (instead of default)")
|
cmd.Flag.Var(&keyRingsFlag{}, "keyring", "GPG keyring to use (instead of default)")
|
||||||
cmd.Flag.String("secret-keyring", "", "GPG secret keyring to use (instead of default)")
|
cmd.Flag.String("secret-keyring", "", "GPG secret keyring to use (instead of default)")
|
||||||
cmd.Flag.String("passphrase", "", "GPG passhprase for the key (warning: could be insecure)")
|
cmd.Flag.String("passphrase", "", "GPG passphrase for the key (warning: could be insecure)")
|
||||||
cmd.Flag.String("passphrase-file", "", "GPG passhprase-file for the key (warning: could be insecure)")
|
cmd.Flag.String("passphrase-file", "", "GPG passphrase-file for the key (warning: could be insecure)")
|
||||||
cmd.Flag.Bool("batch", false, "run GPG with detached tty")
|
cmd.Flag.Bool("batch", false, "run GPG with detached tty")
|
||||||
cmd.Flag.Bool("skip-signing", false, "don't sign Release files with GPG")
|
cmd.Flag.Bool("skip-signing", false, "don't sign Release files with GPG")
|
||||||
|
cmd.Flag.Bool("skip-contents", false, "don't generate Contents indexes")
|
||||||
|
cmd.Flag.Bool("skip-bz2", false, "don't generate bzipped indexes")
|
||||||
cmd.Flag.Bool("force-overwrite", false, "overwrite files in package pool in case of mismatch")
|
cmd.Flag.Bool("force-overwrite", false, "overwrite files in package pool in case of mismatch")
|
||||||
|
cmd.Flag.Bool("skip-cleanup", false, "don't remove unreferenced files in prefix/component")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ func makeCmdRepo() *commander.Command {
|
|||||||
makeCmdRepoShow(),
|
makeCmdRepoShow(),
|
||||||
makeCmdRepoRename(),
|
makeCmdRepoRename(),
|
||||||
makeCmdRepoSearch(),
|
makeCmdRepoSearch(),
|
||||||
|
makeCmdRepoInclude(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-16
@@ -2,12 +2,13 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/aptly"
|
"os"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"github.com/smira/aptly/utils"
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/utils"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
||||||
@@ -19,46 +20,47 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
verifier := &utils.GpgVerifier{}
|
verifier := context.GetVerifier()
|
||||||
|
|
||||||
repo, err := context.CollectionFactory().LocalRepoCollection().ByName(name)
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
repo, err := collectionFactory.LocalRepoCollection().ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to add: %s", err)
|
return fmt.Errorf("unable to add: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
err = collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to add: %s", err)
|
return fmt.Errorf("unable to add: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Progress().Printf("Loading packages...\n")
|
context.Progress().Printf("Loading packages...\n")
|
||||||
|
|
||||||
list, err := deb.NewPackageListFromRefList(repo.RefList(), context.CollectionFactory().PackageCollection(), context.Progress())
|
list, err := deb.NewPackageListFromRefList(repo.RefList(), collectionFactory.PackageCollection(), context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to load packages: %s", err)
|
return fmt.Errorf("unable to load packages: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
forceReplace := context.Flags().Lookup("force-replace").Value.Get().(bool)
|
forceReplace := context.Flags().Lookup("force-replace").Value.Get().(bool)
|
||||||
|
|
||||||
var packageFiles, failedFiles []string
|
var packageFiles, otherFiles, failedFiles []string
|
||||||
|
|
||||||
packageFiles, failedFiles, err = deb.CollectPackageFiles(args[1:], &aptly.ConsoleResultReporter{Progress: context.Progress()})
|
packageFiles, otherFiles, failedFiles = deb.CollectPackageFiles(args[1:], &aptly.ConsoleResultReporter{Progress: context.Progress()})
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("unable to collect package files: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var processedFiles, failedFiles2 []string
|
var processedFiles, failedFiles2 []string
|
||||||
|
|
||||||
processedFiles, failedFiles2, err = deb.ImportPackageFiles(list, packageFiles, forceReplace, verifier, context.PackagePool(),
|
processedFiles, failedFiles2, err = deb.ImportPackageFiles(list, packageFiles, forceReplace, verifier, context.PackagePool(),
|
||||||
context.CollectionFactory().PackageCollection(), &aptly.ConsoleResultReporter{Progress: context.Progress()})
|
collectionFactory.PackageCollection(), &aptly.ConsoleResultReporter{Progress: context.Progress()}, nil,
|
||||||
|
collectionFactory.ChecksumCollection)
|
||||||
failedFiles = append(failedFiles, failedFiles2...)
|
failedFiles = append(failedFiles, failedFiles2...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to import package files: %s", err)
|
return fmt.Errorf("unable to import package files: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
processedFiles = append(processedFiles, otherFiles...)
|
||||||
|
|
||||||
repo.UpdateRefList(deb.NewPackageRefListFromPackageList(list))
|
repo.UpdateRefList(deb.NewPackageRefListFromPackageList(list))
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().Update(repo)
|
err = collectionFactory.LocalRepoCollection().Update(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to save: %s", err)
|
return fmt.Errorf("unable to save: %s", err)
|
||||||
}
|
}
|
||||||
@@ -67,7 +69,7 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
|||||||
processedFiles = utils.StrSliceDeduplicate(processedFiles)
|
processedFiles = utils.StrSliceDeduplicate(processedFiles)
|
||||||
|
|
||||||
for _, file := range processedFiles {
|
for _, file := range processedFiles {
|
||||||
err := os.Remove(file)
|
err = os.Remove(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to remove file: %s", err)
|
return fmt.Errorf("unable to remove file: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+36
-4
@@ -2,14 +2,15 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyRepoCreate(cmd *commander.Command, args []string) error {
|
func aptlyRepoCreate(cmd *commander.Command, args []string) error {
|
||||||
var err error
|
var err error
|
||||||
if len(args) != 1 {
|
if !(len(args) == 1 || (len(args) == 4 && args[1] == "from" && args[2] == "snapshot")) { // nolint: goconst
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
@@ -18,7 +19,32 @@ func aptlyRepoCreate(cmd *commander.Command, args []string) error {
|
|||||||
repo.DefaultDistribution = context.Flags().Lookup("distribution").Value.String()
|
repo.DefaultDistribution = context.Flags().Lookup("distribution").Value.String()
|
||||||
repo.DefaultComponent = context.Flags().Lookup("component").Value.String()
|
repo.DefaultComponent = context.Flags().Lookup("component").Value.String()
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().Add(repo)
|
uploadersFile := context.Flags().Lookup("uploaders-file").Value.Get().(string)
|
||||||
|
if uploadersFile != "" {
|
||||||
|
repo.Uploaders, err = deb.NewUploadersFromFile(uploadersFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
if len(args) == 4 {
|
||||||
|
var snapshot *deb.Snapshot
|
||||||
|
|
||||||
|
snapshot, err = collectionFactory.SnapshotCollection().ByName(args[3])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to load source snapshot: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = collectionFactory.SnapshotCollection().LoadComplete(snapshot)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to load source snapshot: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
repo.UpdateRefList(snapshot.RefList())
|
||||||
|
}
|
||||||
|
|
||||||
|
err = collectionFactory.LocalRepoCollection().Add(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to add local repo: %s", err)
|
return fmt.Errorf("unable to add local repo: %s", err)
|
||||||
}
|
}
|
||||||
@@ -30,16 +56,21 @@ func aptlyRepoCreate(cmd *commander.Command, args []string) error {
|
|||||||
func makeCmdRepoCreate() *commander.Command {
|
func makeCmdRepoCreate() *commander.Command {
|
||||||
cmd := &commander.Command{
|
cmd := &commander.Command{
|
||||||
Run: aptlyRepoCreate,
|
Run: aptlyRepoCreate,
|
||||||
UsageLine: "create <name>",
|
UsageLine: "create <name> [ from snapshot <snapshot> ]",
|
||||||
Short: "create local repository",
|
Short: "create local repository",
|
||||||
Long: `
|
Long: `
|
||||||
Create local package repository. Repository would be empty when
|
Create local package repository. Repository would be empty when
|
||||||
created, packages could be added from files, copied or moved from
|
created, packages could be added from files, copied or moved from
|
||||||
another local repository or imported from the mirror.
|
another local repository or imported from the mirror.
|
||||||
|
|
||||||
|
If local package repository is created from snapshot, repo initial
|
||||||
|
contents are copied from snapsot contents.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
$ aptly repo create testing
|
$ aptly repo create testing
|
||||||
|
|
||||||
|
$ aptly repo create mysql35 from snapshot mysql-35-2017
|
||||||
`,
|
`,
|
||||||
Flag: *flag.NewFlagSet("aptly-repo-create", flag.ExitOnError),
|
Flag: *flag.NewFlagSet("aptly-repo-create", flag.ExitOnError),
|
||||||
}
|
}
|
||||||
@@ -47,6 +78,7 @@ Example:
|
|||||||
cmd.Flag.String("comment", "", "any text that would be used to described local repository")
|
cmd.Flag.String("comment", "", "any text that would be used to described local repository")
|
||||||
cmd.Flag.String("distribution", "", "default distribution when publishing")
|
cmd.Flag.String("distribution", "", "default distribution when publishing")
|
||||||
cmd.Flag.String("component", "main", "default component when publishing")
|
cmd.Flag.String("component", "main", "default component when publishing")
|
||||||
|
cmd.Flag.String("uploaders-file", "", "uploaders.json to be used when including .changes into this repository")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-5
@@ -2,6 +2,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
@@ -14,17 +15,18 @@ func aptlyRepoDrop(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
|
||||||
repo, err := context.CollectionFactory().LocalRepoCollection().ByName(name)
|
repo, err := collectionFactory.LocalRepoCollection().ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to drop: %s", err)
|
return fmt.Errorf("unable to drop: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
published := context.CollectionFactory().PublishedRepoCollection().ByLocalRepo(repo)
|
published := collectionFactory.PublishedRepoCollection().ByLocalRepo(repo)
|
||||||
if len(published) > 0 {
|
if len(published) > 0 {
|
||||||
fmt.Printf("Local repo `%s` is published currently:\n", repo.Name)
|
fmt.Printf("Local repo `%s` is published currently:\n", repo.Name)
|
||||||
for _, repo := range published {
|
for _, repo := range published {
|
||||||
err = context.CollectionFactory().PublishedRepoCollection().LoadComplete(repo, context.CollectionFactory())
|
err = collectionFactory.PublishedRepoCollection().LoadComplete(repo, collectionFactory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to load published: %s", err)
|
return fmt.Errorf("unable to load published: %s", err)
|
||||||
}
|
}
|
||||||
@@ -36,7 +38,7 @@ func aptlyRepoDrop(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
force := context.Flags().Lookup("force").Value.Get().(bool)
|
force := context.Flags().Lookup("force").Value.Get().(bool)
|
||||||
if !force {
|
if !force {
|
||||||
snapshots := context.CollectionFactory().SnapshotCollection().ByLocalRepoSource(repo)
|
snapshots := collectionFactory.SnapshotCollection().ByLocalRepoSource(repo)
|
||||||
|
|
||||||
if len(snapshots) > 0 {
|
if len(snapshots) > 0 {
|
||||||
fmt.Printf("Local repo `%s` was used to create following snapshots:\n", repo.Name)
|
fmt.Printf("Local repo `%s` was used to create following snapshots:\n", repo.Name)
|
||||||
@@ -48,7 +50,7 @@ func aptlyRepoDrop(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().Drop(repo)
|
err = collectionFactory.LocalRepoCollection().Drop(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to drop: %s", err)
|
return fmt.Errorf("unable to drop: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-13
@@ -2,6 +2,9 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/AlekSi/pointer"
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
@@ -13,29 +16,44 @@ func aptlyRepoEdit(cmd *commander.Command, args []string) error {
|
|||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := context.CollectionFactory().LocalRepoCollection().ByName(args[0])
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
repo, err := collectionFactory.LocalRepoCollection().ByName(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to edit: %s", err)
|
return fmt.Errorf("unable to edit: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
err = collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to edit: %s", err)
|
return fmt.Errorf("unable to edit: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Flags().Lookup("comment").Value.String() != "" {
|
var uploadersFile *string
|
||||||
repo.Comment = context.Flags().Lookup("comment").Value.String()
|
|
||||||
|
context.Flags().Visit(func(flag *flag.Flag) {
|
||||||
|
switch flag.Name {
|
||||||
|
case "comment":
|
||||||
|
repo.Comment = flag.Value.String()
|
||||||
|
case "distribution":
|
||||||
|
repo.DefaultDistribution = flag.Value.String()
|
||||||
|
case "component":
|
||||||
|
repo.DefaultComponent = flag.Value.String()
|
||||||
|
case "uploaders-file":
|
||||||
|
uploadersFile = pointer.ToString(flag.Value.String())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if uploadersFile != nil {
|
||||||
|
if *uploadersFile != "" {
|
||||||
|
repo.Uploaders, err = deb.NewUploadersFromFile(*uploadersFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
repo.Uploaders = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.Flags().Lookup("distribution").Value.String() != "" {
|
err = collectionFactory.LocalRepoCollection().Update(repo)
|
||||||
repo.DefaultDistribution = context.Flags().Lookup("distribution").Value.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
if context.Flags().Lookup("component").Value.String() != "" {
|
|
||||||
repo.DefaultComponent = context.Flags().Lookup("component").Value.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().Update(repo)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to edit: %s", err)
|
return fmt.Errorf("unable to edit: %s", err)
|
||||||
}
|
}
|
||||||
@@ -63,6 +81,7 @@ Example:
|
|||||||
cmd.Flag.String("comment", "", "any text that would be used to described local repository")
|
cmd.Flag.String("comment", "", "any text that would be used to described local repository")
|
||||||
cmd.Flag.String("distribution", "", "default distribution when publishing")
|
cmd.Flag.String("distribution", "", "default distribution when publishing")
|
||||||
cmd.Flag.String("component", "", "default component when publishing")
|
cmd.Flag.String("component", "", "default component when publishing")
|
||||||
|
cmd.Flag.String("uploaders-file", "", "uploaders.json to be used when including .changes into this repository")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/query"
|
||||||
|
"github.com/smira/commander"
|
||||||
|
"github.com/smira/flag"
|
||||||
|
)
|
||||||
|
|
||||||
|
func aptlyRepoInclude(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
if len(args) < 1 {
|
||||||
|
cmd.Usage()
|
||||||
|
return commander.ErrCommandError
|
||||||
|
}
|
||||||
|
|
||||||
|
verifier, err := getVerifier(context.Flags())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to initialize GPG verifier: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if verifier == nil {
|
||||||
|
verifier = context.GetVerifier()
|
||||||
|
}
|
||||||
|
|
||||||
|
forceReplace := context.Flags().Lookup("force-replace").Value.Get().(bool)
|
||||||
|
acceptUnsigned := context.Flags().Lookup("accept-unsigned").Value.Get().(bool)
|
||||||
|
ignoreSignatures := context.Flags().Lookup("ignore-signatures").Value.Get().(bool)
|
||||||
|
noRemoveFiles := context.Flags().Lookup("no-remove-files").Value.Get().(bool)
|
||||||
|
repoTemplateString := context.Flags().Lookup("repo").Value.Get().(string)
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
|
||||||
|
var repoTemplate *template.Template
|
||||||
|
repoTemplate, err = template.New("repo").Parse(repoTemplateString)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error parsing -repo template: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
uploaders := (*deb.Uploaders)(nil)
|
||||||
|
uploadersFile := context.Flags().Lookup("uploaders-file").Value.Get().(string)
|
||||||
|
if uploadersFile != "" {
|
||||||
|
uploaders, err = deb.NewUploadersFromFile(uploadersFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range uploaders.Rules {
|
||||||
|
uploaders.Rules[i].CompiledCondition, err = query.Parse(uploaders.Rules[i].Condition)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error parsing query %s: %s", uploaders.Rules[i].Condition, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reporter := &aptly.ConsoleResultReporter{Progress: context.Progress()}
|
||||||
|
|
||||||
|
var changesFiles, failedFiles, failedFiles2 []string
|
||||||
|
|
||||||
|
changesFiles, failedFiles = deb.CollectChangesFiles(args, reporter)
|
||||||
|
_, failedFiles2, err = deb.ImportChangesFiles(
|
||||||
|
changesFiles, reporter, acceptUnsigned, ignoreSignatures, forceReplace, noRemoveFiles, verifier, repoTemplate,
|
||||||
|
context.Progress(), collectionFactory.LocalRepoCollection(), collectionFactory.PackageCollection(),
|
||||||
|
context.PackagePool(), collectionFactory.ChecksumCollection,
|
||||||
|
uploaders, query.Parse)
|
||||||
|
failedFiles = append(failedFiles, failedFiles2...)
|
||||||
|
|
||||||
|
if len(failedFiles) > 0 {
|
||||||
|
context.Progress().ColoredPrintf("@y[!]@| @!Some files were skipped due to errors:@|")
|
||||||
|
for _, file := range failedFiles {
|
||||||
|
context.Progress().ColoredPrintf(" %s", file)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("some files failed to be added")
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeCmdRepoInclude() *commander.Command {
|
||||||
|
cmd := &commander.Command{
|
||||||
|
Run: aptlyRepoInclude,
|
||||||
|
UsageLine: "include <file.changes>|<directory> ...",
|
||||||
|
Short: "add packages to local repositories based on .changes files",
|
||||||
|
Long: `
|
||||||
|
Command include looks for .changes files in list of arguments or specified directories. Each
|
||||||
|
.changes file is verified, parsed, referenced files are put into separate temporary directory
|
||||||
|
and added into local repository. Successfully imported files are removed by default.
|
||||||
|
|
||||||
|
Additionally uploads could be restricted with <uploaders.json> file. Rules in this file control
|
||||||
|
uploads based on GPG key ID of .changes file signature and queries on .changes file fields.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
$ aptly repo include -repo=foo-release incoming/
|
||||||
|
`,
|
||||||
|
Flag: *flag.NewFlagSet("aptly-repo-include", flag.ExitOnError),
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Flag.Bool("no-remove-files", false, "don't remove files that have been imported successfully into repository")
|
||||||
|
cmd.Flag.Bool("force-replace", false, "when adding package that conflicts with existing package, remove existing package")
|
||||||
|
cmd.Flag.String("repo", "{{.Distribution}}", "which repo should files go to, defaults to Distribution field of .changes file")
|
||||||
|
cmd.Flag.Var(&keyRingsFlag{}, "keyring", "gpg keyring to use when verifying Release file (could be specified multiple times)")
|
||||||
|
cmd.Flag.Bool("ignore-signatures", false, "disable verification of .changes file signature")
|
||||||
|
cmd.Flag.Bool("accept-unsigned", false, "accept unsigned .changes files")
|
||||||
|
cmd.Flag.String("uploaders-file", "", "path to uploaders.json file")
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
+53
-8
@@ -1,30 +1,44 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"github.com/smira/commander"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/smira/commander"
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyRepoList(cmd *commander.Command, args []string) error {
|
func aptlyRepoList(cmd *commander.Command, args []string) error {
|
||||||
var err error
|
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jsonFlag := cmd.Flag.Lookup("json").Value.Get().(bool)
|
||||||
|
|
||||||
|
if jsonFlag {
|
||||||
|
return aptlyRepoListJSON(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
return aptlyRepoListTxt(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func aptlyRepoListTxt(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
|
raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
|
||||||
|
|
||||||
repos := make([]string, context.CollectionFactory().LocalRepoCollection().Len())
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
repos := make([]string, collectionFactory.LocalRepoCollection().Len())
|
||||||
i := 0
|
i := 0
|
||||||
context.CollectionFactory().LocalRepoCollection().ForEach(func(repo *deb.LocalRepo) error {
|
collectionFactory.LocalRepoCollection().ForEach(func(repo *deb.LocalRepo) error {
|
||||||
if raw {
|
if raw {
|
||||||
repos[i] = repo.Name
|
repos[i] = repo.Name
|
||||||
} else {
|
} else {
|
||||||
err := context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
e := collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||||
if err != nil {
|
if e != nil {
|
||||||
return err
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
repos[i] = fmt.Sprintf(" * %s (packages: %d)", repo.String(), repo.NumPackages())
|
repos[i] = fmt.Sprintf(" * %s (packages: %d)", repo.String(), repo.NumPackages())
|
||||||
@@ -57,6 +71,36 @@ func aptlyRepoList(cmd *commander.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func aptlyRepoListJSON(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
repos := make([]*deb.LocalRepo, context.NewCollectionFactory().LocalRepoCollection().Len())
|
||||||
|
i := 0
|
||||||
|
context.NewCollectionFactory().LocalRepoCollection().ForEach(func(repo *deb.LocalRepo) error {
|
||||||
|
e := context.NewCollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
||||||
|
if e != nil {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
repos[i] = repo
|
||||||
|
i++
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
context.CloseDatabase()
|
||||||
|
|
||||||
|
sort.Slice(repos, func(i, j int) bool {
|
||||||
|
return repos[i].Name < repos[j].Name
|
||||||
|
})
|
||||||
|
if output, e := json.MarshalIndent(repos, "", " "); e == nil {
|
||||||
|
fmt.Println(string(output))
|
||||||
|
} else {
|
||||||
|
err = e
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func makeCmdRepoList() *commander.Command {
|
func makeCmdRepoList() *commander.Command {
|
||||||
cmd := &commander.Command{
|
cmd := &commander.Command{
|
||||||
Run: aptlyRepoList,
|
Run: aptlyRepoList,
|
||||||
@@ -71,6 +115,7 @@ Example:
|
|||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.Flag.Bool("json", false, "display list in JSON format")
|
||||||
cmd.Flag.Bool("raw", false, "display list in machine-readable format")
|
cmd.Flag.Bool("raw", false, "display list in machine-readable format")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|||||||
+23
-21
@@ -2,11 +2,12 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
"sort"
|
||||||
"github.com/smira/aptly/query"
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/query"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
"sort"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
||||||
@@ -18,12 +19,13 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
command := cmd.Name()
|
command := cmd.Name()
|
||||||
|
|
||||||
dstRepo, err := context.CollectionFactory().LocalRepoCollection().ByName(args[1])
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
dstRepo, err := collectionFactory.LocalRepoCollection().ByName(args[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to %s: %s", command, err)
|
return fmt.Errorf("unable to %s: %s", command, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().LoadComplete(dstRepo)
|
err = collectionFactory.LocalRepoCollection().LoadComplete(dstRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to %s: %s", command, err)
|
return fmt.Errorf("unable to %s: %s", command, err)
|
||||||
}
|
}
|
||||||
@@ -33,8 +35,8 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
|||||||
srcRepo *deb.LocalRepo
|
srcRepo *deb.LocalRepo
|
||||||
)
|
)
|
||||||
|
|
||||||
if command == "copy" || command == "move" {
|
if command == "copy" || command == "move" { // nolint: goconst
|
||||||
srcRepo, err = context.CollectionFactory().LocalRepoCollection().ByName(args[0])
|
srcRepo, err = collectionFactory.LocalRepoCollection().ByName(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to %s: %s", command, err)
|
return fmt.Errorf("unable to %s: %s", command, err)
|
||||||
}
|
}
|
||||||
@@ -43,21 +45,21 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
|||||||
return fmt.Errorf("unable to %s: source and destination are the same", command)
|
return fmt.Errorf("unable to %s: source and destination are the same", command)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().LoadComplete(srcRepo)
|
err = collectionFactory.LocalRepoCollection().LoadComplete(srcRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to %s: %s", command, err)
|
return fmt.Errorf("unable to %s: %s", command, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
srcRefList = srcRepo.RefList()
|
srcRefList = srcRepo.RefList()
|
||||||
} else if command == "import" {
|
} else if command == "import" { // nolint: goconst
|
||||||
var srcRemoteRepo *deb.RemoteRepo
|
var srcRemoteRepo *deb.RemoteRepo
|
||||||
|
|
||||||
srcRemoteRepo, err = context.CollectionFactory().RemoteRepoCollection().ByName(args[0])
|
srcRemoteRepo, err = collectionFactory.RemoteRepoCollection().ByName(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to %s: %s", command, err)
|
return fmt.Errorf("unable to %s: %s", command, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().RemoteRepoCollection().LoadComplete(srcRemoteRepo)
|
err = collectionFactory.RemoteRepoCollection().LoadComplete(srcRemoteRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to %s: %s", command, err)
|
return fmt.Errorf("unable to %s: %s", command, err)
|
||||||
}
|
}
|
||||||
@@ -73,12 +75,12 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
context.Progress().Printf("Loading packages...\n")
|
context.Progress().Printf("Loading packages...\n")
|
||||||
|
|
||||||
dstList, err := deb.NewPackageListFromRefList(dstRepo.RefList(), context.CollectionFactory().PackageCollection(), context.Progress())
|
dstList, err := deb.NewPackageListFromRefList(dstRepo.RefList(), collectionFactory.PackageCollection(), context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to load packages: %s", err)
|
return fmt.Errorf("unable to load packages: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
srcList, err := deb.NewPackageListFromRefList(srcRefList, context.CollectionFactory().PackageCollection(), context.Progress())
|
srcList, err := deb.NewPackageListFromRefList(srcRefList, collectionFactory.PackageCollection(), context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to load packages: %s", err)
|
return fmt.Errorf("unable to load packages: %s", err)
|
||||||
}
|
}
|
||||||
@@ -114,18 +116,18 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toProcess, err := srcList.Filter(queries, withDeps, dstList, context.DependencyOptions(), architecturesList)
|
toProcess, err := srcList.FilterWithProgress(queries, withDeps, dstList, context.DependencyOptions(), architecturesList, context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to %s: %s", command, err)
|
return fmt.Errorf("unable to %s: %s", command, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var verb string
|
var verb string
|
||||||
|
|
||||||
if command == "move" {
|
if command == "move" { // nolint: goconst
|
||||||
verb = "moved"
|
verb = "moved"
|
||||||
} else if command == "copy" {
|
} else if command == "copy" { // nolint: goconst
|
||||||
verb = "copied"
|
verb = "copied"
|
||||||
} else if command == "import" {
|
} else if command == "import" { // nolint: goconst
|
||||||
verb = "imported"
|
verb = "imported"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +137,7 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if command == "move" {
|
if command == "move" { // nolint: goconst
|
||||||
srcList.Remove(p)
|
srcList.Remove(p)
|
||||||
}
|
}
|
||||||
context.Progress().ColoredPrintf("@g[o]@| %s %s", p, verb)
|
context.Progress().ColoredPrintf("@g[o]@| %s %s", p, verb)
|
||||||
@@ -150,15 +152,15 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error {
|
|||||||
} else {
|
} else {
|
||||||
dstRepo.UpdateRefList(deb.NewPackageRefListFromPackageList(dstList))
|
dstRepo.UpdateRefList(deb.NewPackageRefListFromPackageList(dstList))
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().Update(dstRepo)
|
err = collectionFactory.LocalRepoCollection().Update(dstRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to save: %s", err)
|
return fmt.Errorf("unable to save: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if command == "move" {
|
if command == "move" { // nolint: goconst
|
||||||
srcRepo.UpdateRefList(deb.NewPackageRefListFromPackageList(srcList))
|
srcRepo.UpdateRefList(deb.NewPackageRefListFromPackageList(srcList))
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().Update(srcRepo)
|
err = collectionFactory.LocalRepoCollection().Update(srcRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to save: %s", err)
|
return fmt.Errorf("unable to save: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-6
@@ -2,8 +2,9 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"github.com/smira/aptly/query"
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/query"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
@@ -17,19 +18,20 @@ func aptlyRepoRemove(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
repo, err := context.CollectionFactory().LocalRepoCollection().ByName(name)
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
repo, err := collectionFactory.LocalRepoCollection().ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to remove: %s", err)
|
return fmt.Errorf("unable to remove: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
err = collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to remove: %s", err)
|
return fmt.Errorf("unable to remove: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Progress().Printf("Loading packages...\n")
|
context.Progress().Printf("Loading packages...\n")
|
||||||
|
|
||||||
list, err := deb.NewPackageListFromRefList(repo.RefList(), context.CollectionFactory().PackageCollection(), context.Progress())
|
list, err := deb.NewPackageListFromRefList(repo.RefList(), collectionFactory.PackageCollection(), context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to load packages: %s", err)
|
return fmt.Errorf("unable to load packages: %s", err)
|
||||||
}
|
}
|
||||||
@@ -59,7 +61,7 @@ func aptlyRepoRemove(cmd *commander.Command, args []string) error {
|
|||||||
} else {
|
} else {
|
||||||
repo.UpdateRefList(deb.NewPackageRefListFromPackageList(list))
|
repo.UpdateRefList(deb.NewPackageRefListFromPackageList(list))
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().Update(repo)
|
err = collectionFactory.LocalRepoCollection().Update(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to save: %s", err)
|
return fmt.Errorf("unable to save: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-4
@@ -2,7 +2,8 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,18 +20,19 @@ func aptlyRepoRename(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
oldName, newName := args[0], args[1]
|
oldName, newName := args[0], args[1]
|
||||||
|
|
||||||
repo, err = context.CollectionFactory().LocalRepoCollection().ByName(oldName)
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
repo, err = collectionFactory.LocalRepoCollection().ByName(oldName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to rename: %s", err)
|
return fmt.Errorf("unable to rename: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = context.CollectionFactory().LocalRepoCollection().ByName(newName)
|
_, err = collectionFactory.LocalRepoCollection().ByName(newName)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return fmt.Errorf("unable to rename: local repo %s already exists", newName)
|
return fmt.Errorf("unable to rename: local repo %s already exists", newName)
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.Name = newName
|
repo.Name = newName
|
||||||
err = context.CollectionFactory().LocalRepoCollection().Update(repo)
|
err = collectionFactory.LocalRepoCollection().Update(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to rename: %s", err)
|
return fmt.Errorf("unable to rename: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -8,11 +8,13 @@ import (
|
|||||||
func makeCmdRepoSearch() *commander.Command {
|
func makeCmdRepoSearch() *commander.Command {
|
||||||
cmd := &commander.Command{
|
cmd := &commander.Command{
|
||||||
Run: aptlySnapshotMirrorRepoSearch,
|
Run: aptlySnapshotMirrorRepoSearch,
|
||||||
UsageLine: "search <name> <package-query>",
|
UsageLine: "search <name> [<package-query>]",
|
||||||
Short: "search repo for packages matching query",
|
Short: "search repo for packages matching query",
|
||||||
Long: `
|
Long: `
|
||||||
Command search displays list of packages in local repository that match package query
|
Command search displays list of packages in local repository that match package query
|
||||||
|
|
||||||
|
If query is not specified, all the packages are displayed.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
$ aptly repo search my-software '$Architecture (i386), Name (% *-dev)'
|
$ aptly repo search my-software '$Architecture (i386), Name (% *-dev)'
|
||||||
@@ -21,6 +23,7 @@ Example:
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flag.Bool("with-deps", false, "include dependencies into search results")
|
cmd.Flag.Bool("with-deps", false, "include dependencies into search results")
|
||||||
|
cmd.Flag.String("format", "", "custom format for result printing")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
+66
-4
@@ -1,26 +1,42 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyRepoShow(cmd *commander.Command, args []string) error {
|
func aptlyRepoShow(cmd *commander.Command, args []string) error {
|
||||||
var err error
|
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jsonFlag := cmd.Flag.Lookup("json").Value.Get().(bool)
|
||||||
|
|
||||||
|
if jsonFlag {
|
||||||
|
return aptlyRepoShowJSON(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
return aptlyRepoShowTxt(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func aptlyRepoShowTxt(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
repo, err := context.CollectionFactory().LocalRepoCollection().ByName(name)
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
repo, err := collectionFactory.LocalRepoCollection().ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to show: %s", err)
|
return fmt.Errorf("unable to show: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
err = collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to show: %s", err)
|
return fmt.Errorf("unable to show: %s", err)
|
||||||
}
|
}
|
||||||
@@ -29,11 +45,56 @@ func aptlyRepoShow(cmd *commander.Command, args []string) error {
|
|||||||
fmt.Printf("Comment: %s\n", repo.Comment)
|
fmt.Printf("Comment: %s\n", repo.Comment)
|
||||||
fmt.Printf("Default Distribution: %s\n", repo.DefaultDistribution)
|
fmt.Printf("Default Distribution: %s\n", repo.DefaultDistribution)
|
||||||
fmt.Printf("Default Component: %s\n", repo.DefaultComponent)
|
fmt.Printf("Default Component: %s\n", repo.DefaultComponent)
|
||||||
|
if repo.Uploaders != nil {
|
||||||
|
fmt.Printf("Uploaders: %s\n", repo.Uploaders)
|
||||||
|
}
|
||||||
fmt.Printf("Number of packages: %d\n", repo.NumPackages())
|
fmt.Printf("Number of packages: %d\n", repo.NumPackages())
|
||||||
|
|
||||||
withPackages := context.Flags().Lookup("with-packages").Value.Get().(bool)
|
withPackages := context.Flags().Lookup("with-packages").Value.Get().(bool)
|
||||||
if withPackages {
|
if withPackages {
|
||||||
ListPackagesRefList(repo.RefList())
|
ListPackagesRefList(repo.RefList(), collectionFactory)
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func aptlyRepoShowJSON(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
name := args[0]
|
||||||
|
|
||||||
|
repo, err := context.NewCollectionFactory().LocalRepoCollection().ByName(name)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to show: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = context.NewCollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to show: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// include packages if requested
|
||||||
|
packageList := []string{}
|
||||||
|
withPackages := context.Flags().Lookup("with-packages").Value.Get().(bool)
|
||||||
|
if withPackages {
|
||||||
|
if repo.RefList() != nil {
|
||||||
|
var list *deb.PackageList
|
||||||
|
list, err = deb.NewPackageListFromRefList(repo.RefList(), context.NewCollectionFactory().PackageCollection(), context.Progress())
|
||||||
|
if err == nil {
|
||||||
|
packageList = list.FullNames()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(packageList)
|
||||||
|
}
|
||||||
|
|
||||||
|
// merge the repo object with the package list
|
||||||
|
var output []byte
|
||||||
|
if output, err = json.MarshalIndent(struct {
|
||||||
|
*deb.LocalRepo
|
||||||
|
Packages []string
|
||||||
|
}{repo, packageList}, "", " "); err == nil {
|
||||||
|
fmt.Println(string(output))
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
@@ -53,6 +114,7 @@ ex:
|
|||||||
Flag: *flag.NewFlagSet("aptly-repo-show", flag.ExitOnError),
|
Flag: *flag.NewFlagSet("aptly-repo-show", flag.ExitOnError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.Flag.Bool("json", false, "display record in JSON format")
|
||||||
cmd.Flag.Bool("with-packages", false, "show list of packages")
|
cmd.Flag.Bool("with-packages", false, "show list of packages")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|||||||
+4
-2
@@ -2,7 +2,9 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
ctx "github.com/smira/aptly/context"
|
"os"
|
||||||
|
|
||||||
|
ctx "github.com/aptly-dev/aptly/context"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,7 +16,7 @@ func Run(cmd *commander.Command, cmdArgs []string, initContext bool) (returnCode
|
|||||||
if !ok {
|
if !ok {
|
||||||
panic(r)
|
panic(r)
|
||||||
}
|
}
|
||||||
fmt.Println("ERROR:", fatal.Message)
|
fmt.Fprintln(os.Stderr, "ERROR:", fatal.Message)
|
||||||
returnCode = fatal.ReturnCode
|
returnCode = fatal.ReturnCode
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|||||||
+27
-14
@@ -2,16 +2,17 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/aptly"
|
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"github.com/smira/aptly/utils"
|
|
||||||
"github.com/smira/commander"
|
|
||||||
"github.com/smira/flag"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/utils"
|
||||||
|
"github.com/smira/commander"
|
||||||
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyServe(cmd *commander.Command, args []string) error {
|
func aptlyServe(cmd *commander.Command, args []string) error {
|
||||||
@@ -22,7 +23,19 @@ func aptlyServe(cmd *commander.Command, args []string) error {
|
|||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.CollectionFactory().PublishedRepoCollection().Len() == 0 {
|
// There are only two working options for aptly's rootDir:
|
||||||
|
// 1. rootDir does not exist, then we'll create it
|
||||||
|
// 2. rootDir exists and is writable
|
||||||
|
// anything else must fail.
|
||||||
|
// E.g.: Running the service under a different user may lead to a rootDir
|
||||||
|
// that exists but is not usable due to access permissions.
|
||||||
|
err = utils.DirIsAccessible(context.Config().RootDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
if collectionFactory.PublishedRepoCollection().Len() == 0 {
|
||||||
fmt.Printf("No published repositories, unable to serve.\n")
|
fmt.Printf("No published repositories, unable to serve.\n")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -44,13 +57,13 @@ func aptlyServe(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
fmt.Printf("Serving published repositories, recommended apt sources list:\n\n")
|
fmt.Printf("Serving published repositories, recommended apt sources list:\n\n")
|
||||||
|
|
||||||
sources := make(sort.StringSlice, 0, context.CollectionFactory().PublishedRepoCollection().Len())
|
sources := make(sort.StringSlice, 0, collectionFactory.PublishedRepoCollection().Len())
|
||||||
published := make(map[string]*deb.PublishedRepo, context.CollectionFactory().PublishedRepoCollection().Len())
|
published := make(map[string]*deb.PublishedRepo, collectionFactory.PublishedRepoCollection().Len())
|
||||||
|
|
||||||
err = context.CollectionFactory().PublishedRepoCollection().ForEach(func(repo *deb.PublishedRepo) error {
|
err = collectionFactory.PublishedRepoCollection().ForEach(func(repo *deb.PublishedRepo) error {
|
||||||
err := context.CollectionFactory().PublishedRepoCollection().LoadComplete(repo, context.CollectionFactory())
|
e := collectionFactory.PublishedRepoCollection().LoadComplete(repo, collectionFactory)
|
||||||
if err != nil {
|
if e != nil {
|
||||||
return err
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
sources = append(sources, repo.String())
|
sources = append(sources, repo.String())
|
||||||
@@ -78,13 +91,13 @@ func aptlyServe(cmd *commander.Command, args []string) error {
|
|||||||
fmt.Printf("# %s\ndeb http://%s:%s/%s %s %s\n",
|
fmt.Printf("# %s\ndeb http://%s:%s/%s %s %s\n",
|
||||||
repo, listenHost, listenPort, prefix, repo.Distribution, strings.Join(repo.Components(), " "))
|
repo, listenHost, listenPort, prefix, repo.Distribution, strings.Join(repo.Components(), " "))
|
||||||
|
|
||||||
if utils.StrSliceHasItem(repo.Architectures, "source") {
|
if utils.StrSliceHasItem(repo.Architectures, deb.ArchitectureSource) {
|
||||||
fmt.Printf("deb-src http://%s:%s/%s %s %s\n",
|
fmt.Printf("deb-src http://%s:%s/%s %s %s\n",
|
||||||
listenHost, listenPort, prefix, repo.Distribution, strings.Join(repo.Components(), " "))
|
listenHost, listenPort, prefix, repo.Distribution, strings.Join(repo.Components(), " "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
publicPath := context.GetPublishedStorage("").(aptly.LocalPublishedStorage).PublicPath()
|
publicPath := context.GetPublishedStorage("").(aptly.FileSystemPublishedStorage).PublicPath()
|
||||||
ShutdownContext()
|
ShutdownContext()
|
||||||
|
|
||||||
fmt.Printf("\nStarting web server at: %s (press Ctrl+C to quit)...\n", listen)
|
fmt.Printf("\nStarting web server at: %s (press Ctrl+C to quit)...\n", listen)
|
||||||
|
|||||||
+10
-8
@@ -2,7 +2,8 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,13 +13,14 @@ func aptlySnapshotCreate(cmd *commander.Command, args []string) error {
|
|||||||
snapshot *deb.Snapshot
|
snapshot *deb.Snapshot
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(args) == 4 && args[1] == "from" && args[2] == "mirror" {
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
if len(args) == 4 && args[1] == "from" && args[2] == "mirror" { // nolint: goconst
|
||||||
// aptly snapshot create snap from mirror mirror
|
// aptly snapshot create snap from mirror mirror
|
||||||
var repo *deb.RemoteRepo
|
var repo *deb.RemoteRepo
|
||||||
|
|
||||||
repoName, snapshotName := args[3], args[0]
|
repoName, snapshotName := args[3], args[0]
|
||||||
|
|
||||||
repo, err = context.CollectionFactory().RemoteRepoCollection().ByName(repoName)
|
repo, err = collectionFactory.RemoteRepoCollection().ByName(repoName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create snapshot: %s", err)
|
return fmt.Errorf("unable to create snapshot: %s", err)
|
||||||
}
|
}
|
||||||
@@ -28,7 +30,7 @@ func aptlySnapshotCreate(cmd *commander.Command, args []string) error {
|
|||||||
return fmt.Errorf("unable to create snapshot: %s", err)
|
return fmt.Errorf("unable to create snapshot: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo)
|
err = collectionFactory.RemoteRepoCollection().LoadComplete(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create snapshot: %s", err)
|
return fmt.Errorf("unable to create snapshot: %s", err)
|
||||||
}
|
}
|
||||||
@@ -37,18 +39,18 @@ func aptlySnapshotCreate(cmd *commander.Command, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create snapshot: %s", err)
|
return fmt.Errorf("unable to create snapshot: %s", err)
|
||||||
}
|
}
|
||||||
} else if len(args) == 4 && args[1] == "from" && args[2] == "repo" {
|
} else if len(args) == 4 && args[1] == "from" && args[2] == "repo" { // nolint: goconst
|
||||||
// aptly snapshot create snap from repo repo
|
// aptly snapshot create snap from repo repo
|
||||||
var repo *deb.LocalRepo
|
var repo *deb.LocalRepo
|
||||||
|
|
||||||
localRepoName, snapshotName := args[3], args[0]
|
localRepoName, snapshotName := args[3], args[0]
|
||||||
|
|
||||||
repo, err = context.CollectionFactory().LocalRepoCollection().ByName(localRepoName)
|
repo, err = collectionFactory.LocalRepoCollection().ByName(localRepoName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create snapshot: %s", err)
|
return fmt.Errorf("unable to create snapshot: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
err = collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create snapshot: %s", err)
|
return fmt.Errorf("unable to create snapshot: %s", err)
|
||||||
}
|
}
|
||||||
@@ -69,7 +71,7 @@ func aptlySnapshotCreate(cmd *commander.Command, args []string) error {
|
|||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().Add(snapshot)
|
err = collectionFactory.SnapshotCollection().Add(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to add snapshot: %s", err)
|
return fmt.Errorf("unable to add snapshot: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
@@ -14,31 +15,32 @@ func aptlySnapshotDiff(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onlyMatching := context.Flags().Lookup("only-matching").Value.Get().(bool)
|
onlyMatching := context.Flags().Lookup("only-matching").Value.Get().(bool)
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
|
||||||
// Load <name-a> snapshot
|
// Load <name-a> snapshot
|
||||||
snapshotA, err := context.CollectionFactory().SnapshotCollection().ByName(args[0])
|
snapshotA, err := collectionFactory.SnapshotCollection().ByName(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to load snapshot A: %s", err)
|
return fmt.Errorf("unable to load snapshot A: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(snapshotA)
|
err = collectionFactory.SnapshotCollection().LoadComplete(snapshotA)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to load snapshot A: %s", err)
|
return fmt.Errorf("unable to load snapshot A: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load <name-b> snapshot
|
// Load <name-b> snapshot
|
||||||
snapshotB, err := context.CollectionFactory().SnapshotCollection().ByName(args[1])
|
snapshotB, err := collectionFactory.SnapshotCollection().ByName(args[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to load snapshot B: %s", err)
|
return fmt.Errorf("unable to load snapshot B: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(snapshotB)
|
err = collectionFactory.SnapshotCollection().LoadComplete(snapshotB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to load snapshot B: %s", err)
|
return fmt.Errorf("unable to load snapshot B: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate diff
|
// Calculate diff
|
||||||
diff, err := snapshotA.RefList().Diff(snapshotB.RefList(), context.CollectionFactory().PackageCollection())
|
diff, err := snapshotA.RefList().Diff(snapshotB.RefList(), collectionFactory.PackageCollection())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to calculate diff: %s", err)
|
return fmt.Errorf("unable to calculate diff: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
@@ -14,18 +15,19 @@ func aptlySnapshotDrop(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
|
||||||
snapshot, err := context.CollectionFactory().SnapshotCollection().ByName(name)
|
snapshot, err := collectionFactory.SnapshotCollection().ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to drop: %s", err)
|
return fmt.Errorf("unable to drop: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
published := context.CollectionFactory().PublishedRepoCollection().BySnapshot(snapshot)
|
published := collectionFactory.PublishedRepoCollection().BySnapshot(snapshot)
|
||||||
|
|
||||||
if len(published) > 0 {
|
if len(published) > 0 {
|
||||||
fmt.Printf("Snapshot `%s` is published currently:\n", snapshot.Name)
|
fmt.Printf("Snapshot `%s` is published currently:\n", snapshot.Name)
|
||||||
for _, repo := range published {
|
for _, repo := range published {
|
||||||
err = context.CollectionFactory().PublishedRepoCollection().LoadComplete(repo, context.CollectionFactory())
|
err = collectionFactory.PublishedRepoCollection().LoadComplete(repo, collectionFactory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to load published: %s", err)
|
return fmt.Errorf("unable to load published: %s", err)
|
||||||
}
|
}
|
||||||
@@ -37,7 +39,7 @@ func aptlySnapshotDrop(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
force := context.Flags().Lookup("force").Value.Get().(bool)
|
force := context.Flags().Lookup("force").Value.Get().(bool)
|
||||||
if !force {
|
if !force {
|
||||||
snapshots := context.CollectionFactory().SnapshotCollection().BySnapshotSource(snapshot)
|
snapshots := collectionFactory.SnapshotCollection().BySnapshotSource(snapshot)
|
||||||
if len(snapshots) > 0 {
|
if len(snapshots) > 0 {
|
||||||
fmt.Printf("Snapshot `%s` was used as a source in following snapshots:\n", snapshot.Name)
|
fmt.Printf("Snapshot `%s` was used as a source in following snapshots:\n", snapshot.Name)
|
||||||
for _, snap := range snapshots {
|
for _, snap := range snapshots {
|
||||||
@@ -48,7 +50,7 @@ func aptlySnapshotDrop(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().Drop(snapshot)
|
err = collectionFactory.SnapshotCollection().Drop(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to drop: %s", err)
|
return fmt.Errorf("unable to drop: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-10
@@ -2,12 +2,13 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"github.com/smira/aptly/query"
|
|
||||||
"github.com/smira/commander"
|
|
||||||
"github.com/smira/flag"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/query"
|
||||||
|
"github.com/smira/commander"
|
||||||
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlySnapshotFilter(cmd *commander.Command, args []string) error {
|
func aptlySnapshotFilter(cmd *commander.Command, args []string) error {
|
||||||
@@ -18,21 +19,22 @@ func aptlySnapshotFilter(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
withDeps := context.Flags().Lookup("with-deps").Value.Get().(bool)
|
withDeps := context.Flags().Lookup("with-deps").Value.Get().(bool)
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
|
||||||
// Load <source> snapshot
|
// Load <source> snapshot
|
||||||
source, err := context.CollectionFactory().SnapshotCollection().ByName(args[0])
|
source, err := collectionFactory.SnapshotCollection().ByName(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to filter: %s", err)
|
return fmt.Errorf("unable to filter: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(source)
|
err = collectionFactory.SnapshotCollection().LoadComplete(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to filter: %s", err)
|
return fmt.Errorf("unable to filter: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert snapshot to package list
|
// Convert snapshot to package list
|
||||||
context.Progress().Printf("Loading packages (%d)...\n", source.RefList().Len())
|
context.Progress().Printf("Loading packages (%d)...\n", source.RefList().Len())
|
||||||
packageList, err := deb.NewPackageListFromRefList(source.RefList(), context.CollectionFactory().PackageCollection(), context.Progress())
|
packageList, err := deb.NewPackageListFromRefList(source.RefList(), collectionFactory.PackageCollection(), context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to load packages: %s", err)
|
return fmt.Errorf("unable to load packages: %s", err)
|
||||||
}
|
}
|
||||||
@@ -65,7 +67,7 @@ func aptlySnapshotFilter(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Filter with dependencies as requested
|
// Filter with dependencies as requested
|
||||||
result, err := packageList.Filter(queries, withDeps, nil, context.DependencyOptions(), architecturesList)
|
result, err := packageList.FilterWithProgress(queries, withDeps, nil, context.DependencyOptions(), architecturesList, context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to filter: %s", err)
|
return fmt.Errorf("unable to filter: %s", err)
|
||||||
}
|
}
|
||||||
@@ -74,7 +76,7 @@ func aptlySnapshotFilter(cmd *commander.Command, args []string) error {
|
|||||||
destination := deb.NewSnapshotFromPackageList(args[1], []*deb.Snapshot{source}, result,
|
destination := deb.NewSnapshotFromPackageList(args[1], []*deb.Snapshot{source}, result,
|
||||||
fmt.Sprintf("Filtered '%s', query was: '%s'", source.Name, strings.Join(args[2:], " ")))
|
fmt.Sprintf("Filtered '%s', query was: '%s'", source.Name, strings.Join(args[2:], " ")))
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().Add(destination)
|
err = collectionFactory.SnapshotCollection().Add(destination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create snapshot: %s", err)
|
return fmt.Errorf("unable to create snapshot: %s", err)
|
||||||
}
|
}
|
||||||
@@ -96,7 +98,7 @@ as 'package-name' or as package queries.
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
$ aptly snapshot filter wheezy-main wheezy-required 'Priorioty (required)'
|
$ aptly snapshot filter wheezy-main wheezy-required 'Priority (required)'
|
||||||
`,
|
`,
|
||||||
Flag: *flag.NewFlagSet("aptly-snapshot-filter", flag.ExitOnError),
|
Flag: *flag.NewFlagSet("aptly-snapshot-filter", flag.ExitOnError),
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-3
@@ -1,22 +1,36 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlySnapshotList(cmd *commander.Command, args []string) error {
|
func aptlySnapshotList(cmd *commander.Command, args []string) error {
|
||||||
var err error
|
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jsonFlag := cmd.Flag.Lookup("json").Value.Get().(bool)
|
||||||
|
|
||||||
|
if jsonFlag {
|
||||||
|
return aptlySnapshotListJSON(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
return aptlySnapshotListTxt(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func aptlySnapshotListTxt(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
|
raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
|
||||||
sortMethodString := cmd.Flag.Lookup("sort").Value.Get().(string)
|
sortMethodString := cmd.Flag.Lookup("sort").Value.Get().(string)
|
||||||
|
|
||||||
collection := context.CollectionFactory().SnapshotCollection()
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
collection := collectionFactory.SnapshotCollection()
|
||||||
|
|
||||||
if raw {
|
if raw {
|
||||||
collection.ForEachSorted(sortMethodString, func(snapshot *deb.Snapshot) error {
|
collection.ForEachSorted(sortMethodString, func(snapshot *deb.Snapshot) error {
|
||||||
@@ -45,6 +59,29 @@ func aptlySnapshotList(cmd *commander.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func aptlySnapshotListJSON(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
sortMethodString := cmd.Flag.Lookup("sort").Value.Get().(string)
|
||||||
|
|
||||||
|
collection := context.NewCollectionFactory().SnapshotCollection()
|
||||||
|
|
||||||
|
jsonSnapshots := make([]*deb.Snapshot, collection.Len())
|
||||||
|
i := 0
|
||||||
|
collection.ForEachSorted(sortMethodString, func(snapshot *deb.Snapshot) error {
|
||||||
|
jsonSnapshots[i] = snapshot
|
||||||
|
i++
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if output, e := json.MarshalIndent(jsonSnapshots, "", " "); e == nil {
|
||||||
|
fmt.Println(string(output))
|
||||||
|
} else {
|
||||||
|
err = e
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func makeCmdSnapshotList() *commander.Command {
|
func makeCmdSnapshotList() *commander.Command {
|
||||||
cmd := &commander.Command{
|
cmd := &commander.Command{
|
||||||
Run: aptlySnapshotList,
|
Run: aptlySnapshotList,
|
||||||
@@ -59,6 +96,7 @@ Example:
|
|||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.Flag.Bool("json", false, "display list in JSON format")
|
||||||
cmd.Flag.Bool("raw", false, "display list in machine-readable format")
|
cmd.Flag.Bool("raw", false, "display list in machine-readable format")
|
||||||
cmd.Flag.String("sort", "name", "display list in 'name' or creation 'time' order")
|
cmd.Flag.String("sort", "name", "display list in 'name' or creation 'time' order")
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"github.com/smira/commander"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/smira/commander"
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlySnapshotMerge(cmd *commander.Command, args []string) error {
|
func aptlySnapshotMerge(cmd *commander.Command, args []string) error {
|
||||||
@@ -14,15 +15,16 @@ func aptlySnapshotMerge(cmd *commander.Command, args []string) error {
|
|||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
sources := make([]*deb.Snapshot, len(args)-1)
|
sources := make([]*deb.Snapshot, len(args)-1)
|
||||||
|
|
||||||
for i := 0; i < len(args)-1; i++ {
|
for i := 0; i < len(args)-1; i++ {
|
||||||
sources[i], err = context.CollectionFactory().SnapshotCollection().ByName(args[i+1])
|
sources[i], err = collectionFactory.SnapshotCollection().ByName(args[i+1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to load snapshot: %s", err)
|
return fmt.Errorf("unable to load snapshot: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(sources[i])
|
err = collectionFactory.SnapshotCollection().LoadComplete(sources[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to load snapshot: %s", err)
|
return fmt.Errorf("unable to load snapshot: %s", err)
|
||||||
}
|
}
|
||||||
@@ -55,7 +57,7 @@ func aptlySnapshotMerge(cmd *commander.Command, args []string) error {
|
|||||||
destination := deb.NewSnapshotFromRefList(args[0], sources, result,
|
destination := deb.NewSnapshotFromRefList(args[0], sources, result,
|
||||||
fmt.Sprintf("Merged from sources: %s", strings.Join(sourceDescription, ", ")))
|
fmt.Sprintf("Merged from sources: %s", strings.Join(sourceDescription, ", ")))
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().Add(destination)
|
err = collectionFactory.SnapshotCollection().Add(destination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create snapshot: %s", err)
|
return fmt.Errorf("unable to create snapshot: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-12
@@ -2,12 +2,13 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"github.com/smira/aptly/query"
|
|
||||||
"github.com/smira/commander"
|
|
||||||
"github.com/smira/flag"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/query"
|
||||||
|
"github.com/smira/commander"
|
||||||
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlySnapshotPull(cmd *commander.Command, args []string) error {
|
func aptlySnapshotPull(cmd *commander.Command, args []string) error {
|
||||||
@@ -20,25 +21,26 @@ func aptlySnapshotPull(cmd *commander.Command, args []string) error {
|
|||||||
noDeps := context.Flags().Lookup("no-deps").Value.Get().(bool)
|
noDeps := context.Flags().Lookup("no-deps").Value.Get().(bool)
|
||||||
noRemove := context.Flags().Lookup("no-remove").Value.Get().(bool)
|
noRemove := context.Flags().Lookup("no-remove").Value.Get().(bool)
|
||||||
allMatches := context.Flags().Lookup("all-matches").Value.Get().(bool)
|
allMatches := context.Flags().Lookup("all-matches").Value.Get().(bool)
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
|
||||||
// Load <name> snapshot
|
// Load <name> snapshot
|
||||||
snapshot, err := context.CollectionFactory().SnapshotCollection().ByName(args[0])
|
snapshot, err := collectionFactory.SnapshotCollection().ByName(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to pull: %s", err)
|
return fmt.Errorf("unable to pull: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot)
|
err = collectionFactory.SnapshotCollection().LoadComplete(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to pull: %s", err)
|
return fmt.Errorf("unable to pull: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load <source> snapshot
|
// Load <source> snapshot
|
||||||
source, err := context.CollectionFactory().SnapshotCollection().ByName(args[1])
|
source, err := collectionFactory.SnapshotCollection().ByName(args[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to pull: %s", err)
|
return fmt.Errorf("unable to pull: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(source)
|
err = collectionFactory.SnapshotCollection().LoadComplete(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to pull: %s", err)
|
return fmt.Errorf("unable to pull: %s", err)
|
||||||
}
|
}
|
||||||
@@ -48,12 +50,12 @@ func aptlySnapshotPull(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
// Convert snapshot to package list
|
// Convert snapshot to package list
|
||||||
context.Progress().Printf("Loading packages (%d)...\n", snapshot.RefList().Len()+source.RefList().Len())
|
context.Progress().Printf("Loading packages (%d)...\n", snapshot.RefList().Len()+source.RefList().Len())
|
||||||
packageList, err := deb.NewPackageListFromRefList(snapshot.RefList(), context.CollectionFactory().PackageCollection(), context.Progress())
|
packageList, err := deb.NewPackageListFromRefList(snapshot.RefList(), collectionFactory.PackageCollection(), context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to load packages: %s", err)
|
return fmt.Errorf("unable to load packages: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sourcePackageList, err := deb.NewPackageListFromRefList(source.RefList(), context.CollectionFactory().PackageCollection(), context.Progress())
|
sourcePackageList, err := deb.NewPackageListFromRefList(source.RefList(), collectionFactory.PackageCollection(), context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to load packages: %s", err)
|
return fmt.Errorf("unable to load packages: %s", err)
|
||||||
}
|
}
|
||||||
@@ -95,7 +97,7 @@ func aptlySnapshotPull(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Filter with dependencies as requested
|
// Filter with dependencies as requested
|
||||||
result, err := sourcePackageList.Filter(queries, !noDeps, packageList, context.DependencyOptions(), architecturesList)
|
result, err := sourcePackageList.FilterWithProgress(queries, !noDeps, packageList, context.DependencyOptions(), architecturesList, context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to pull: %s", err)
|
return fmt.Errorf("unable to pull: %s", err)
|
||||||
}
|
}
|
||||||
@@ -136,7 +138,7 @@ func aptlySnapshotPull(cmd *commander.Command, args []string) error {
|
|||||||
destination := deb.NewSnapshotFromPackageList(args[2], []*deb.Snapshot{snapshot, source}, packageList,
|
destination := deb.NewSnapshotFromPackageList(args[2], []*deb.Snapshot{snapshot, source}, packageList,
|
||||||
fmt.Sprintf("Pulled into '%s' with '%s' as source, pull request was: '%s'", snapshot.Name, source.Name, strings.Join(args[3:], " ")))
|
fmt.Sprintf("Pulled into '%s' with '%s' as source, pull request was: '%s'", snapshot.Name, source.Name, strings.Join(args[3:], " ")))
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().Add(destination)
|
err = collectionFactory.SnapshotCollection().Add(destination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create snapshot: %s", err)
|
return fmt.Errorf("unable to create snapshot: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,19 +19,20 @@ func aptlySnapshotRename(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
oldName, newName := args[0], args[1]
|
oldName, newName := args[0], args[1]
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
|
||||||
snapshot, err = context.CollectionFactory().SnapshotCollection().ByName(oldName)
|
snapshot, err = collectionFactory.SnapshotCollection().ByName(oldName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to rename: %s", err)
|
return fmt.Errorf("unable to rename: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = context.CollectionFactory().SnapshotCollection().ByName(newName)
|
_, err = collectionFactory.SnapshotCollection().ByName(newName)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return fmt.Errorf("unable to rename: snapshot %s already exists", newName)
|
return fmt.Errorf("unable to rename: snapshot %s already exists", newName)
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshot.Name = newName
|
snapshot.Name = newName
|
||||||
err = context.CollectionFactory().SnapshotCollection().Update(snapshot)
|
err = collectionFactory.SnapshotCollection().Update(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to rename: %s", err)
|
return fmt.Errorf("unable to rename: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+40
-22
@@ -2,56 +2,65 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
"sort"
|
||||||
"github.com/smira/aptly/query"
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/query"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
"sort"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlySnapshotMirrorRepoSearch(cmd *commander.Command, args []string) error {
|
func aptlySnapshotMirrorRepoSearch(cmd *commander.Command, args []string) error {
|
||||||
var err error
|
var (
|
||||||
if len(args) != 2 {
|
err error
|
||||||
|
q deb.PackageQuery
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(args) < 1 || len(args) > 2 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
command := cmd.Parent.Name()
|
command := cmd.Parent.Name()
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
|
||||||
var reflist *deb.PackageRefList
|
var reflist *deb.PackageRefList
|
||||||
|
|
||||||
if command == "snapshot" {
|
if command == "snapshot" { // nolint: goconst
|
||||||
snapshot, err := context.CollectionFactory().SnapshotCollection().ByName(name)
|
var snapshot *deb.Snapshot
|
||||||
|
snapshot, err = collectionFactory.SnapshotCollection().ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to search: %s", err)
|
return fmt.Errorf("unable to search: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot)
|
err = collectionFactory.SnapshotCollection().LoadComplete(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to search: %s", err)
|
return fmt.Errorf("unable to search: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
reflist = snapshot.RefList()
|
reflist = snapshot.RefList()
|
||||||
} else if command == "mirror" {
|
} else if command == "mirror" {
|
||||||
repo, err := context.CollectionFactory().RemoteRepoCollection().ByName(name)
|
var repo *deb.RemoteRepo
|
||||||
|
repo, err = collectionFactory.RemoteRepoCollection().ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to search: %s", err)
|
return fmt.Errorf("unable to search: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().RemoteRepoCollection().LoadComplete(repo)
|
err = collectionFactory.RemoteRepoCollection().LoadComplete(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to search: %s", err)
|
return fmt.Errorf("unable to search: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
reflist = repo.RefList()
|
reflist = repo.RefList()
|
||||||
} else if command == "repo" {
|
} else if command == "repo" { // nolint: goconst
|
||||||
repo, err := context.CollectionFactory().LocalRepoCollection().ByName(name)
|
var repo *deb.LocalRepo
|
||||||
|
repo, err = collectionFactory.LocalRepoCollection().ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to search: %s", err)
|
return fmt.Errorf("unable to search: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
|
err = collectionFactory.LocalRepoCollection().LoadComplete(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to search: %s", err)
|
return fmt.Errorf("unable to search: %s", err)
|
||||||
}
|
}
|
||||||
@@ -61,17 +70,21 @@ func aptlySnapshotMirrorRepoSearch(cmd *commander.Command, args []string) error
|
|||||||
panic("unknown command")
|
panic("unknown command")
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := deb.NewPackageListFromRefList(reflist, context.CollectionFactory().PackageCollection(), context.Progress())
|
list, err := deb.NewPackageListFromRefList(reflist, collectionFactory.PackageCollection(), context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to search: %s", err)
|
return fmt.Errorf("unable to search: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
list.PrepareIndex()
|
list.PrepareIndex()
|
||||||
|
|
||||||
q, err := query.Parse(args[1])
|
if len(args) == 2 {
|
||||||
|
q, err = query.Parse(args[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to search: %s", err)
|
return fmt.Errorf("unable to search: %s", err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
q = &deb.MatchAllQuery{}
|
||||||
|
}
|
||||||
|
|
||||||
withDeps := context.Flags().Lookup("with-deps").Value.Get().(bool)
|
withDeps := context.Flags().Lookup("with-deps").Value.Get().(bool)
|
||||||
architecturesList := []string{}
|
architecturesList := []string{}
|
||||||
@@ -90,16 +103,18 @@ func aptlySnapshotMirrorRepoSearch(cmd *commander.Command, args []string) error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := list.Filter([]deb.PackageQuery{q}, withDeps,
|
result, err := list.FilterWithProgress([]deb.PackageQuery{q}, withDeps,
|
||||||
nil, context.DependencyOptions(), architecturesList)
|
nil, context.DependencyOptions(), architecturesList, context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to search: %s", err)
|
return fmt.Errorf("unable to search: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
result.ForEach(func(p *deb.Package) error {
|
if result.Len() == 0 {
|
||||||
context.Progress().Printf("%s\n", p)
|
return fmt.Errorf("no results")
|
||||||
return nil
|
}
|
||||||
})
|
|
||||||
|
format := context.Flags().Lookup("format").Value.String()
|
||||||
|
PrintPackageList(result, format, "")
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -107,11 +122,13 @@ func aptlySnapshotMirrorRepoSearch(cmd *commander.Command, args []string) error
|
|||||||
func makeCmdSnapshotSearch() *commander.Command {
|
func makeCmdSnapshotSearch() *commander.Command {
|
||||||
cmd := &commander.Command{
|
cmd := &commander.Command{
|
||||||
Run: aptlySnapshotMirrorRepoSearch,
|
Run: aptlySnapshotMirrorRepoSearch,
|
||||||
UsageLine: "search <name> <package-query>",
|
UsageLine: "search <name> [<package-query>]",
|
||||||
Short: "search snapshot for packages matching query",
|
Short: "search snapshot for packages matching query",
|
||||||
Long: `
|
Long: `
|
||||||
Command search displays list of packages in snapshot that match package query
|
Command search displays list of packages in snapshot that match package query
|
||||||
|
|
||||||
|
If query is not specified, all the packages are displayed.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
$ aptly snapshot search wheezy-main '$Architecture (i386), Name (% *-dev)'
|
$ aptly snapshot search wheezy-main '$Architecture (i386), Name (% *-dev)'
|
||||||
@@ -120,6 +137,7 @@ Example:
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flag.Bool("with-deps", false, "include dependencies into search results")
|
cmd.Flag.Bool("with-deps", false, "include dependencies into search results")
|
||||||
|
cmd.Flag.String("format", "", "custom format for result printing")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
+124
-5
@@ -1,26 +1,41 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
"github.com/smira/flag"
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlySnapshotShow(cmd *commander.Command, args []string) error {
|
func aptlySnapshotShow(cmd *commander.Command, args []string) error {
|
||||||
var err error
|
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return commander.ErrCommandError
|
return commander.ErrCommandError
|
||||||
}
|
}
|
||||||
|
|
||||||
name := args[0]
|
jsonFlag := cmd.Flag.Lookup("json").Value.Get().(bool)
|
||||||
|
|
||||||
snapshot, err := context.CollectionFactory().SnapshotCollection().ByName(name)
|
if jsonFlag {
|
||||||
|
return aptlySnapshotShowJSON(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
return aptlySnapshotShowTxt(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func aptlySnapshotShowTxt(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
name := args[0]
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
|
|
||||||
|
snapshot, err := collectionFactory.SnapshotCollection().ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to show: %s", err)
|
return fmt.Errorf("unable to show: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot)
|
err = collectionFactory.SnapshotCollection().LoadComplete(snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to show: %s", err)
|
return fmt.Errorf("unable to show: %s", err)
|
||||||
}
|
}
|
||||||
@@ -29,10 +44,113 @@ func aptlySnapshotShow(cmd *commander.Command, args []string) error {
|
|||||||
fmt.Printf("Created At: %s\n", snapshot.CreatedAt.Format("2006-01-02 15:04:05 MST"))
|
fmt.Printf("Created At: %s\n", snapshot.CreatedAt.Format("2006-01-02 15:04:05 MST"))
|
||||||
fmt.Printf("Description: %s\n", snapshot.Description)
|
fmt.Printf("Description: %s\n", snapshot.Description)
|
||||||
fmt.Printf("Number of packages: %d\n", snapshot.NumPackages())
|
fmt.Printf("Number of packages: %d\n", snapshot.NumPackages())
|
||||||
|
if len(snapshot.SourceIDs) > 0 {
|
||||||
|
fmt.Printf("Sources:\n")
|
||||||
|
for _, sourceID := range snapshot.SourceIDs {
|
||||||
|
var name string
|
||||||
|
if snapshot.SourceKind == deb.SourceSnapshot {
|
||||||
|
var source *deb.Snapshot
|
||||||
|
source, err = collectionFactory.SnapshotCollection().ByUUID(sourceID)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
name = source.Name
|
||||||
|
} else if snapshot.SourceKind == deb.SourceLocalRepo {
|
||||||
|
var source *deb.LocalRepo
|
||||||
|
source, err = collectionFactory.LocalRepoCollection().ByUUID(sourceID)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
name = source.Name
|
||||||
|
} else if snapshot.SourceKind == deb.SourceRemoteRepo {
|
||||||
|
var source *deb.RemoteRepo
|
||||||
|
source, err = collectionFactory.RemoteRepoCollection().ByUUID(sourceID)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
name = source.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
if name != "" {
|
||||||
|
fmt.Printf(" %s [%s]\n", name, snapshot.SourceKind)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
withPackages := context.Flags().Lookup("with-packages").Value.Get().(bool)
|
withPackages := context.Flags().Lookup("with-packages").Value.Get().(bool)
|
||||||
if withPackages {
|
if withPackages {
|
||||||
ListPackagesRefList(snapshot.RefList())
|
ListPackagesRefList(snapshot.RefList(), collectionFactory)
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func aptlySnapshotShowJSON(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
name := args[0]
|
||||||
|
|
||||||
|
snapshot, err := context.NewCollectionFactory().SnapshotCollection().ByName(name)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to show: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = context.NewCollectionFactory().SnapshotCollection().LoadComplete(snapshot)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to show: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// include the sources
|
||||||
|
if len(snapshot.SourceIDs) > 0 {
|
||||||
|
for _, sourceID := range snapshot.SourceIDs {
|
||||||
|
if snapshot.SourceKind == deb.SourceSnapshot {
|
||||||
|
var source *deb.Snapshot
|
||||||
|
source, err = context.NewCollectionFactory().SnapshotCollection().ByUUID(sourceID)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
snapshot.Snapshots = append(snapshot.Snapshots, source)
|
||||||
|
} else if snapshot.SourceKind == deb.SourceLocalRepo {
|
||||||
|
var source *deb.LocalRepo
|
||||||
|
source, err = context.NewCollectionFactory().LocalRepoCollection().ByUUID(sourceID)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
snapshot.LocalRepos = append(snapshot.LocalRepos, source)
|
||||||
|
} else if snapshot.SourceKind == deb.SourceRemoteRepo {
|
||||||
|
var source *deb.RemoteRepo
|
||||||
|
source, err = context.NewCollectionFactory().RemoteRepoCollection().ByUUID(sourceID)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
snapshot.RemoteRepos = append(snapshot.RemoteRepos, source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// include packages if requested
|
||||||
|
withPackages := context.Flags().Lookup("with-packages").Value.Get().(bool)
|
||||||
|
if withPackages {
|
||||||
|
if snapshot.RefList() != nil {
|
||||||
|
var list *deb.PackageList
|
||||||
|
list, err = deb.NewPackageListFromRefList(snapshot.RefList(), context.NewCollectionFactory().PackageCollection(), context.Progress())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to get package list: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
list.PrepareIndex()
|
||||||
|
list.ForEachIndexed(func(p *deb.Package) error {
|
||||||
|
snapshot.Packages = append(snapshot.Packages, p.GetFullName())
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
sort.Strings(snapshot.Packages)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var output []byte
|
||||||
|
if output, err = json.MarshalIndent(snapshot, "", " "); err == nil {
|
||||||
|
fmt.Println(string(output))
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
@@ -53,6 +171,7 @@ Example:
|
|||||||
Flag: *flag.NewFlagSet("aptly-snapshot-show", flag.ExitOnError),
|
Flag: *flag.NewFlagSet("aptly-snapshot-show", flag.ExitOnError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.Flag.Bool("json", false, "display record in JSON format")
|
||||||
cmd.Flag.Bool("with-packages", false, "show list of packages")
|
cmd.Flag.Bool("with-packages", false, "show list of packages")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|||||||
+12
-10
@@ -2,9 +2,10 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"github.com/smira/commander"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/smira/commander"
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlySnapshotVerify(cmd *commander.Command, args []string) error {
|
func aptlySnapshotVerify(cmd *commander.Command, args []string) error {
|
||||||
@@ -15,13 +16,14 @@ func aptlySnapshotVerify(cmd *commander.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
snapshots := make([]*deb.Snapshot, len(args))
|
snapshots := make([]*deb.Snapshot, len(args))
|
||||||
|
collectionFactory := context.NewCollectionFactory()
|
||||||
for i := range snapshots {
|
for i := range snapshots {
|
||||||
snapshots[i], err = context.CollectionFactory().SnapshotCollection().ByName(args[i])
|
snapshots[i], err = collectionFactory.SnapshotCollection().ByName(args[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to verify: %s", err)
|
return fmt.Errorf("unable to verify: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = context.CollectionFactory().SnapshotCollection().LoadComplete(snapshots[i])
|
err = collectionFactory.SnapshotCollection().LoadComplete(snapshots[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to verify: %s", err)
|
return fmt.Errorf("unable to verify: %s", err)
|
||||||
}
|
}
|
||||||
@@ -29,27 +31,27 @@ func aptlySnapshotVerify(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
context.Progress().Printf("Loading packages...\n")
|
context.Progress().Printf("Loading packages...\n")
|
||||||
|
|
||||||
packageList, err := deb.NewPackageListFromRefList(snapshots[0].RefList(), context.CollectionFactory().PackageCollection(), context.Progress())
|
packageList, err := deb.NewPackageListFromRefList(snapshots[0].RefList(), collectionFactory.PackageCollection(), context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Errorf("unable to load packages: %s", err)
|
return fmt.Errorf("unable to load packages: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sourcePackageList := deb.NewPackageList()
|
sourcePackageList := deb.NewPackageList()
|
||||||
err = sourcePackageList.Append(packageList)
|
err = sourcePackageList.Append(packageList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Errorf("unable to merge sources: %s", err)
|
return fmt.Errorf("unable to merge sources: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var pL *deb.PackageList
|
var pL *deb.PackageList
|
||||||
for i := 1; i < len(snapshots); i++ {
|
for i := 1; i < len(snapshots); i++ {
|
||||||
pL, err = deb.NewPackageListFromRefList(snapshots[i].RefList(), context.CollectionFactory().PackageCollection(), context.Progress())
|
pL, err = deb.NewPackageListFromRefList(snapshots[i].RefList(), collectionFactory.PackageCollection(), context.Progress())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Errorf("unable to load packages: %s", err)
|
return fmt.Errorf("unable to load packages: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = sourcePackageList.Append(pL)
|
err = sourcePackageList.Append(pL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Errorf("unable to merge sources: %s", err)
|
return fmt.Errorf("unable to merge sources: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -20,7 +20,7 @@ func aptlyTaskRun(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
var finfo os.FileInfo
|
var finfo os.FileInfo
|
||||||
if finfo, err = os.Stat(filename); os.IsNotExist(err) || finfo.IsDir() {
|
if finfo, err = os.Stat(filename); os.IsNotExist(err) || finfo.IsDir() {
|
||||||
return fmt.Errorf("no such file, %s\n", filename)
|
return fmt.Errorf("no such file, %s", filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print("Reading file...\n\n")
|
fmt.Print("Reading file...\n\n")
|
||||||
@@ -82,7 +82,7 @@ func aptlyTaskRun(cmd *commander.Command, args []string) error {
|
|||||||
|
|
||||||
for i, command := range cmdList {
|
for i, command := range cmdList {
|
||||||
if !commandErrored {
|
if !commandErrored {
|
||||||
err := context.ReOpenDatabase()
|
err = context.ReOpenDatabase()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to reopen DB: %s", err)
|
return fmt.Errorf("failed to reopen DB: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -2,7 +2,8 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/aptly"
|
|
||||||
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
"github.com/smira/commander"
|
"github.com/smira/commander"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
coverage:
|
||||||
|
status:
|
||||||
|
project:
|
||||||
|
default:
|
||||||
|
target: auto
|
||||||
|
threshold: 0%
|
||||||
|
if_ci_failed: error
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
# aptly-zsh
|
||||||
|
zsh completion for aptly
|
||||||
|
|
||||||
|
The zsh completion function and this README were imported from
|
||||||
|
[steinymity's repository](https://github.com/steinymity/aptly-zsh).
|
||||||
|
|
||||||
|
[Aptly](https://www.aptly.info/) is a great tool to setup Debian APT repositories
|
||||||
|
and mirrors. However, it's sometimes hard to remember all the command line
|
||||||
|
syntax and names of all options. Therefore I wrote this zsh completion modules
|
||||||
|
for aptly.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This project is licensed under the terms of the MIT license. See file `LICENSE`
|
||||||
|
for details.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Clone/copy the file `_aptly` to a place in your `$fpath` (show with
|
||||||
|
`echo $fpath`), or create a new directory and extend the fpath:
|
||||||
|
|
||||||
|
mkdir -p ~/.zsh/functions
|
||||||
|
fpath=(~/.zsh/functions $fpath)
|
||||||
|
editor ~/.zsh/functions/_aptly
|
||||||
|
|
||||||
|
To profit most from the provided help messages and completions, make sure that
|
||||||
|
your zsh is setup properly. I have tested with the grml-zsh configuration that
|
||||||
|
is [available on Github](https://github.com/grml/grml-etc-core/) and on the
|
||||||
|
[grml homepage](http://grml.org/zsh/).
|
||||||
|
|
||||||
|
## Compatibility
|
||||||
|
|
||||||
|
The command line completion was developed based on the manpage of aptly 1.2.0
|
||||||
|
(currently in Debian Testing). However, most completions will work on older
|
||||||
|
versions (e.g., 0.9.7 in Debian Stable), too.
|
||||||
|
|
||||||
|
The completion function completes most arguments and options that can be passed
|
||||||
|
to aptly, including mirror/repository/snapshot/publish names. However, not all
|
||||||
|
arguments are handled yet. See the next section for known limitations.
|
||||||
|
|
||||||
|
## Known Bugs and Limitation
|
||||||
|
|
||||||
|
* Boolean options are always completed with an explicit value `true` or
|
||||||
|
`false`, although omitting the value is implicitly interpreted as `true`.
|
||||||
|
* The source and destination names of copy and move operations must not be the
|
||||||
|
same. This is currently not enforced.
|
||||||
|
* The package query and display format strings are currently not completed.
|
||||||
|
* Endpoints are not completed.
|
||||||
|
* In `publish snapshot` there is no connection between the number of
|
||||||
|
components passed to `-component` and the number of given snapshots to
|
||||||
|
publish. Furthermore, the help text for `endpoint:prefix` disappears
|
||||||
|
after its first possible location.
|
||||||
|
* In `publish switch` the distribution can be set independently of the
|
||||||
|
`endpoint:prefix` (i.e., all published distributions can be combined with
|
||||||
|
all published `endpoint:prefix`).
|
||||||
|
* Neither `publish switch` nor `publish update` check if publish was created
|
||||||
|
from a snapshot or directly from a local repo.
|
||||||
|
* Task commands are not completed. There are no commas added.
|
||||||
|
* `help` won't complete after a sub command (i.e., `aptly mirror list help`).
|
||||||
|
* Probably more, feel free to open issues, and submit patches/merge requests.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Maximilian Stein <m@steiny.biz>
|
||||||
|
2018-02-03
|
||||||
@@ -0,0 +1,622 @@
|
|||||||
|
#compdef aptly
|
||||||
|
################################################################################
|
||||||
|
# Copyright (C) 2018 Maximilian Stein <m@steiny.biz>
|
||||||
|
# Acknowledgement: Many texts where copied from aptly(1)
|
||||||
|
#
|
||||||
|
# This project is licensed under the terms of the MIT license.
|
||||||
|
# See file LICENSE for details.
|
||||||
|
################################################################################
|
||||||
|
# zsh completion script for Aptly (http://aptly.info/)
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
# see https://man.cx/aptly
|
||||||
|
|
||||||
|
local curcontext="$curcontext" state line cmd subcmd ret=1
|
||||||
|
|
||||||
|
local arch_list=(amd64 arm64 armel armhf i386 mips mipsel mips64el ppc64el s390x)
|
||||||
|
local bool="bool:{_wanted -V values expl 'bool' compadd true false}"
|
||||||
|
local dists=({wheezy,jessie,stretch}{,-updates,-backports,-backports-sloopy} buster sid experimental)
|
||||||
|
local components=(main contrib non-free)
|
||||||
|
local aptly_query="aptly package query: "
|
||||||
|
local aptly_format="aptly package display format: "
|
||||||
|
local aptly_uploaders="-uploaders-file=[uploaders.json to be used when including .changes into this repository]:uploaders file:_files -g '*.json'"
|
||||||
|
local keyring="*-keyring=[gpg keyring to use when verifying Release file (could be specified multiple times)]:keyring file:_files -g '*.gpg'"
|
||||||
|
|
||||||
|
# complete command
|
||||||
|
(( $+functions[_aptly-cmd] )) ||
|
||||||
|
_aptly-cmd() {
|
||||||
|
_values "aptly command category" \
|
||||||
|
"mirror[manage, update mirrors of remote repositories]" \
|
||||||
|
"repo[manage local package repositories, add, remove, move, copy packages]" \
|
||||||
|
"snapshot[create, merge, manage snapshots]" \
|
||||||
|
"package[perform operation on the whole collection of packages]" \
|
||||||
|
"publish[publish snapshot or local repository]" \
|
||||||
|
"db[cleanup database and package pool, recover database after failure]" \
|
||||||
|
"task[multi-command tasks]" \
|
||||||
|
"serve[quickly serve published repositories via HTTP]" \
|
||||||
|
"config[configuration management]" \
|
||||||
|
"graph[generate dependency graph]" \
|
||||||
|
"api[REST API service]"
|
||||||
|
ret=0
|
||||||
|
}
|
||||||
|
|
||||||
|
# complete subcommand
|
||||||
|
(( $+functions[_aptly-subcmd] )) ||
|
||||||
|
_aptly-subcmd() {
|
||||||
|
local cmd=$1
|
||||||
|
case $cmd in
|
||||||
|
mirror)
|
||||||
|
_values "mirror commands" \
|
||||||
|
"create[create new mirror of remote repository]" \
|
||||||
|
"list[show full list of mirrors]" \
|
||||||
|
"show[show details about a mirror]" \
|
||||||
|
"drop[delete a mirror]" \
|
||||||
|
"update[update a mirror]" \
|
||||||
|
"rename[change name of a mirror]" \
|
||||||
|
"edit[change settings of a mirror]" \
|
||||||
|
"search[search mirror for packages matching query]"
|
||||||
|
ret=0 ;;
|
||||||
|
repo)
|
||||||
|
_values "repo commands" \
|
||||||
|
"add[add packages to local repository]" \
|
||||||
|
"copy[copy packages between local repositories]" \
|
||||||
|
"create[create local repository]" \
|
||||||
|
"drop[delete local repository]" \
|
||||||
|
"edit[edit properties of local repository]" \
|
||||||
|
"import[import packages from mirror to local repository]" \
|
||||||
|
"list[list local repositories]" \
|
||||||
|
"move[move packages between local repositories]" \
|
||||||
|
"remove[remove packages from local repository]" \
|
||||||
|
"show[show details about local repository]" \
|
||||||
|
"rename[renames local repository]" \
|
||||||
|
"search[search repo for packages matching query]" \
|
||||||
|
"include[add packages to local repositories based on .changes files]"
|
||||||
|
ret=0 ;;
|
||||||
|
snapshot)
|
||||||
|
_values "snapshot commands" \
|
||||||
|
"create[create snapshot of mirror or local repository]" \
|
||||||
|
"list[list snapshots]" \
|
||||||
|
"show[show details about snapshot]" \
|
||||||
|
"verify[verify dependencies in snapshot]" \
|
||||||
|
"pull[pull packages from another snapshot]" \
|
||||||
|
"diff[show difference between two snapshots]" \
|
||||||
|
"merge[merge snapshots]" \
|
||||||
|
"drop[delete snapshot]" \
|
||||||
|
"rename[rename snapshot]" \
|
||||||
|
"search[search snapshot for packages matching query]" \
|
||||||
|
"filter[filter packages in snapshot producing another snapshot]"
|
||||||
|
ret=0 ;;
|
||||||
|
publish)
|
||||||
|
_values "publish commands" \
|
||||||
|
"drop[remove published repository]" \
|
||||||
|
"list[list published repositories]" \
|
||||||
|
"repo[publish local repository]" \
|
||||||
|
"snapshot[publish snapshot]" \
|
||||||
|
"switch[update published repository by switching to new snapshot]" \
|
||||||
|
"update[update published local repository]" \
|
||||||
|
"show[shows details of published repository]"
|
||||||
|
ret=0 ;;
|
||||||
|
package)
|
||||||
|
_values "package commands" \
|
||||||
|
"search[search for packages matching query]" \
|
||||||
|
"show[show details about packages matching query]"
|
||||||
|
ret=0 ;;
|
||||||
|
db)
|
||||||
|
_values "db commands" \
|
||||||
|
"cleanup[cleanup db and package pool]" \
|
||||||
|
"recover[recover db after crash]"
|
||||||
|
ret=0 ;;
|
||||||
|
serve)
|
||||||
|
# no subcommand here
|
||||||
|
_arguments '1:: :' \
|
||||||
|
'-listen=[host:port for HTTP listening]:host\:port: '
|
||||||
|
ret=0 ;;
|
||||||
|
api)
|
||||||
|
_values "api commands" \
|
||||||
|
"serve[start api http service]"
|
||||||
|
ret=0 ;;
|
||||||
|
graph)
|
||||||
|
# no subcommand here
|
||||||
|
_arguments '*:' \
|
||||||
|
'-format=[render graph to specified format]:image format:(png svg pdf)' \
|
||||||
|
'-layout=[create a more vertical or more horizontal graph layout]:layout:(horizontal vertical)' \
|
||||||
|
'-output=[specify output filename, default is to open result in viewer]:output file:_files'
|
||||||
|
ret=0 ;;
|
||||||
|
config)
|
||||||
|
_values "config commands" \
|
||||||
|
"show[show current aptly config]"
|
||||||
|
ret=0 ;;
|
||||||
|
task)
|
||||||
|
_values "task commands" \
|
||||||
|
"run[run aptly tasks]"
|
||||||
|
ret=0 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# complete parameters
|
||||||
|
(( $+functions[_aptly-param] )) ||
|
||||||
|
_aptly-param() {
|
||||||
|
local cmd=$1 subcmd=$2
|
||||||
|
|
||||||
|
local config=$opt_args[-config]
|
||||||
|
[[ -n $config ]] && config="-config=$config"
|
||||||
|
|
||||||
|
# get list of mirrors, or ' ' if none
|
||||||
|
get_mirrors() {
|
||||||
|
# retrieve list of mirrors
|
||||||
|
local mirrors=($(aptly $config mirror list -raw=true 2>/dev/null))
|
||||||
|
# a single space causes just the help text to be shown
|
||||||
|
[[ -z $mirrors ]] && mirrors=" " || mirrors="($mirrors)"
|
||||||
|
echo $mirrors
|
||||||
|
}
|
||||||
|
# get lists of repos or ' ' if none
|
||||||
|
get_repos() {
|
||||||
|
# retrieve repo list
|
||||||
|
local repos=($(aptly $config repo list -raw=true 2>/dev/null))
|
||||||
|
[[ -z $repos ]] && repos=" " || repos="($repos)"
|
||||||
|
echo $repos
|
||||||
|
}
|
||||||
|
# get list of snapshots or ' ' if none
|
||||||
|
get_snapshots() {
|
||||||
|
local snapshots=($(aptly $config snapshot list -raw=true 2>/dev/null))
|
||||||
|
[[ -z $snapshots ]] && snapshots=" " || snapshots="($snapshots)"
|
||||||
|
echo $snapshots
|
||||||
|
}
|
||||||
|
# get list of gpg keys or ' ' if none
|
||||||
|
get_gpg_key_ids() {
|
||||||
|
local gpg_keys=($(gpg --quiet --batch --keyid-format long --list-secret-keys --with-colons 2>/dev/null | grep '^sec' | cut -d ':' -f 5))
|
||||||
|
[[ -z $gpg_keys ]] && gpg_keys=" " || gpg_keys="($gpg_keys)"
|
||||||
|
echo $gpg_keys
|
||||||
|
}
|
||||||
|
|
||||||
|
ret=0
|
||||||
|
case $cmd in
|
||||||
|
mirror)
|
||||||
|
local mirrors=$(get_mirrors)
|
||||||
|
|
||||||
|
case $subcmd in
|
||||||
|
create)
|
||||||
|
_arguments \
|
||||||
|
"-filter=[filter packages in mirror]:$aptly_query" \
|
||||||
|
"-filter-with-deps=[when filtering, include dependencies of matching packages as well]:$bool" \
|
||||||
|
"-force-architecture=[(only with architecture list) skip check that requested architectures are listed in Release file]:$bool" \
|
||||||
|
"-force-components=[(only with component list) skip check that requested components are listed in Release file]:$bool" \
|
||||||
|
"-ignore-signatures=[disable verification of Release file signatures]:$bool" \
|
||||||
|
$keyring \
|
||||||
|
"-with-sources=[download source packages in addition to binary packages]:$bool" \
|
||||||
|
"-with-udebs=[download .udeb packages (Debian installer support)]:$bool" \
|
||||||
|
"(-)2:new mirror name: " ":archive url:_urls" ":distribution:($dists)" "*:components:_values -s ' ' components $components"
|
||||||
|
;;
|
||||||
|
list)
|
||||||
|
_arguments '1:: :' \
|
||||||
|
"-raw=[display list in machine-readable format]:$bool"
|
||||||
|
;;
|
||||||
|
show)
|
||||||
|
_arguments \
|
||||||
|
"-with-packages=[show detailed list of packages and versions stored in the mirror]:$bool" \
|
||||||
|
"(-)2:mirror name:$mirrors"
|
||||||
|
;;
|
||||||
|
drop)
|
||||||
|
_arguments \
|
||||||
|
"-force=[force mirror deletion even if used by snapshots]:$bool" \
|
||||||
|
"(-)2:mirror name:$mirrors"
|
||||||
|
;;
|
||||||
|
update)
|
||||||
|
_arguments \
|
||||||
|
"-download-limit=[limit download speed (kB/s)]:kB/s: " \
|
||||||
|
"-downloader=[downloader to use]:str: " \
|
||||||
|
"-force=[force update mirror even if it is locked by another process]:$bool" \
|
||||||
|
"-ignore-checksums=[ignore checksum mismatches while downloading package files and metadata]:$bool" \
|
||||||
|
"-ignore-signatures=[disable verification of Release file signatures]:$bool" \
|
||||||
|
$keyring \
|
||||||
|
"-max-tries=[max download tries till process fails with download error]:number: " \
|
||||||
|
"-skip-existing-packages=[do not check file existence for packages listed in the internal database of the mirror]:$bool" \
|
||||||
|
"(-)2:mirror name:$mirrors"
|
||||||
|
;;
|
||||||
|
rename)
|
||||||
|
_arguments \
|
||||||
|
"2:old mirror name:$mirrors" ":new mirror name: "
|
||||||
|
;;
|
||||||
|
edit)
|
||||||
|
_arguments \
|
||||||
|
"-filter=[filter packages in mirror]:$aptly_query" \
|
||||||
|
"-filter-with-deps=[when filtering, include dependencies of matching packages as well]:$bool" \
|
||||||
|
"-with-sources=[download source packages in addition to binary packages]:$bool" \
|
||||||
|
"-with-udebs=[download .udeb packages (Debian installer support)]:$bool" \
|
||||||
|
"(-)2:mirror name:$mirrors"
|
||||||
|
;;
|
||||||
|
search)
|
||||||
|
_arguments \
|
||||||
|
"-format=[custom format for result printing]:$aptly_format" \
|
||||||
|
"-with-deps=[include dependencies into search results]:$bool" \
|
||||||
|
"(-)2:mirror name:$mirrors" ":$aptly_query"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
|
||||||
|
repo)
|
||||||
|
|
||||||
|
|
||||||
|
local repos=$(get_repos)
|
||||||
|
|
||||||
|
local create_edit=("-comment=[any text that would be used to described local repository]:comment: "
|
||||||
|
"-component=[default component when publishing]:component:($components)"
|
||||||
|
"-distribution=[default distribution when publishing]:distribution:($dists)"
|
||||||
|
$aptly_uploaders
|
||||||
|
)
|
||||||
|
|
||||||
|
case $subcmd in
|
||||||
|
add)
|
||||||
|
_arguments \
|
||||||
|
"-force-replace=[when adding package that conflicts with existing package, remove existing package]:$bool" \
|
||||||
|
"-remove-files=[remove files that have been imported successfully into repository]:$bool" \
|
||||||
|
"(-)2:repo name:$repos" "*:package files:_files -g '*.{udeb,deb,dsc}'"
|
||||||
|
;;
|
||||||
|
copy)
|
||||||
|
_arguments \
|
||||||
|
"-dry-run=[don’t copy, just show what would be copied]:$bool" \
|
||||||
|
"-with-deps=[follow dependencies when processing package−spec]:$$bool" \
|
||||||
|
"(-)2:src repo name:$repos" ":dest repo name:$repos" "*:$aptly_query"
|
||||||
|
;;
|
||||||
|
create)
|
||||||
|
local snapshots=$(get_snapshots)
|
||||||
|
|
||||||
|
_arguments \
|
||||||
|
${create_edit[@]} \
|
||||||
|
"(-)2:new repo name: " \
|
||||||
|
"3:::('from')" "4:::('snapshot')" "5::snapshot:$snapshots"
|
||||||
|
;;
|
||||||
|
drop)
|
||||||
|
_arguments \
|
||||||
|
"-force=[force local repo deletion even if used by snapshots]:$bool" \
|
||||||
|
"(-)2:repo name:$repos"
|
||||||
|
;;
|
||||||
|
edit)
|
||||||
|
_arguments \
|
||||||
|
${create_edit[@]} \
|
||||||
|
"(-)2:repo name:$repos"
|
||||||
|
;;
|
||||||
|
import)
|
||||||
|
local mirrors=$(get_mirrors)
|
||||||
|
|
||||||
|
_arguments \
|
||||||
|
"-dry-run=[don’t import, just show what would be imported]:$bool" \
|
||||||
|
"-with-deps=[follow dependencies when processing package−spec]:$bool" \
|
||||||
|
"(-)2:src mirror name:$mirrors" ":dest repo name:$repos" "*:$aptly_query"
|
||||||
|
;;
|
||||||
|
list)
|
||||||
|
_arguments '1:: :' \
|
||||||
|
"-json=[display list in JSON format]:$bool" \
|
||||||
|
"-raw=[display list in machine−readable format]:$bool"
|
||||||
|
;;
|
||||||
|
move)
|
||||||
|
_arguments \
|
||||||
|
"-dry-run=[don’t move, just show what would be moved]:$bool" \
|
||||||
|
"-with-deps=[follow dependencies when processing package−spec]:$bool" \
|
||||||
|
"(-)2:srv repo name:$repos" ":dest repo name:$repos" "*:$aptly_query"
|
||||||
|
;;
|
||||||
|
remove)
|
||||||
|
_arguments \
|
||||||
|
"-dry-run=[don’t remove, just show what would be removed]:$bool" \
|
||||||
|
"(-)2:repo name:$repos" "*:$aptly_query"
|
||||||
|
;;
|
||||||
|
show)
|
||||||
|
_arguments \
|
||||||
|
"-json=[display record in JSON format]:$bool" \
|
||||||
|
"-with-packages=[show list of packages]:$bool" \
|
||||||
|
"(-)2:repo name:$repos"
|
||||||
|
;;
|
||||||
|
rename)
|
||||||
|
_arguments \
|
||||||
|
"2:old repo name:$repos" ":new repo name: "
|
||||||
|
;;
|
||||||
|
search)
|
||||||
|
_arguments \
|
||||||
|
"-format=[custom format for result printing]:$aptly_format" \
|
||||||
|
"-with-deps=[include dependencies into search results]:$bool" \
|
||||||
|
"(-)2:repo name:$repos" ":$aptly_query"
|
||||||
|
;;
|
||||||
|
include)
|
||||||
|
_arguments '1:: :' \
|
||||||
|
"-accept-unsigned=[accept unsigned .changes files]:$bool" \
|
||||||
|
"-force-replace=[when adding package that conflicts with existing package, remove existing package]:$bool" \
|
||||||
|
"-ignore-signatures=[disable verification of .changes file signature]:$bool" \
|
||||||
|
$keyring \
|
||||||
|
"-no-remove-files=[don’t remove files that have been imported successfully into repository]:$bool" \
|
||||||
|
"-repo=[which repo should files go to, defaults to Distribution field of .changes file]:repo name:$repos" \
|
||||||
|
$aptly_uploaders \
|
||||||
|
"(-)*:changes files/directories:_files -g '*.changes'"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
snapshot)
|
||||||
|
local snapshots=$(get_snapshots)
|
||||||
|
|
||||||
|
case $subcmd in
|
||||||
|
create)
|
||||||
|
local mirrors=$(get_mirrors)
|
||||||
|
local repos=$(get_repos)
|
||||||
|
|
||||||
|
_arguments -C \
|
||||||
|
'(-)2:new snapshot name: ' \
|
||||||
|
'3: :->src1' \
|
||||||
|
'4:: :->src2' '5:: :->src3'
|
||||||
|
|
||||||
|
case $state in
|
||||||
|
src1)
|
||||||
|
_values 'snapshot src' 'from' 'empty' ;;
|
||||||
|
src2)
|
||||||
|
if [[ $line[3] == from ]]; then
|
||||||
|
_values 'snapshot src' 'mirror' 'repo'
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
src3)
|
||||||
|
if [[ $line[3] == from ]]; then
|
||||||
|
case $line[4] in
|
||||||
|
mirror)
|
||||||
|
_arguments "5:mirror name:$mirrors" ;;
|
||||||
|
repo)
|
||||||
|
_arguments "5:repo name:$repos" ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
list)
|
||||||
|
_arguments '1:: :' \
|
||||||
|
"-raw=[display list in machine−readable format]:$bool" \
|
||||||
|
"-sort=[display list in ’name’ or creation ’time’ order]:sort order:((name\:'alphabetical order' time\:'chronological order'))"
|
||||||
|
;;
|
||||||
|
show)
|
||||||
|
_arguments \
|
||||||
|
"-with-packages=[show list of packages]:$bool" \
|
||||||
|
"(-)2:snapshot name:$snapshots"
|
||||||
|
;;
|
||||||
|
verify)
|
||||||
|
_arguments '1:: :' \
|
||||||
|
"(-)2:snapshot name:$snapshots" "*::more snapshots:$snapshots"
|
||||||
|
;;
|
||||||
|
pull)
|
||||||
|
_arguments \
|
||||||
|
"-all-matches=[pull all the packages that satisfy the dependency version requirements]:$bool" \
|
||||||
|
"-dry-run=[don’t create destination snapshot, just show what would be pulled]:$bool" \
|
||||||
|
"-no-deps=[don’t process dependencies, just pull listed packages]:$bool" \
|
||||||
|
"-no-remove=[don’t remove other package versions when pulling package]:$bool" \
|
||||||
|
"(-)2:to snapshot name:$snapshots" "3:src snapshot name:$snapshots" "4:new dest snapshot name: " \
|
||||||
|
"*:$aptly_query"
|
||||||
|
;;
|
||||||
|
diff)
|
||||||
|
_arguments \
|
||||||
|
"-only-matching=[display diff only for matching packages (don’t display missing packages)]:$bool" \
|
||||||
|
"(-)2:snapshot name a:$snapshots" "3:snapshot name b:$snapshots"
|
||||||
|
;;
|
||||||
|
merge)
|
||||||
|
_arguments \
|
||||||
|
"-latest=[use only the latest version of each package]:$bool" \
|
||||||
|
"-no-remove=[don’t remove duplicate arch/name packages]:$bool" \
|
||||||
|
"(-)2:new dest snapshot name: " "*:source snapshot name(s):$snapshots"
|
||||||
|
;;
|
||||||
|
drop)
|
||||||
|
_arguments \
|
||||||
|
"-force=[remove snapshot even if it was used as source for other snapshots]:$bool" \
|
||||||
|
"(-)2:snapshot name:$snapshots"
|
||||||
|
;;
|
||||||
|
rename)
|
||||||
|
_arguments '1:: :' \
|
||||||
|
"2:old snapshot name:$snapshots" "3:new snapshot name: "
|
||||||
|
;;
|
||||||
|
search)
|
||||||
|
_arguments \
|
||||||
|
"-format=[custom format for result printing]:$aptly_format" \
|
||||||
|
"-with-deps=[include dependencies into search results]:$bool" \
|
||||||
|
"(-)2:snapshot name:$snapshots" ":$aptly_query"
|
||||||
|
;;
|
||||||
|
filter)
|
||||||
|
_arguments \
|
||||||
|
"-with-deps=[include dependent packages as well]:$bool" \
|
||||||
|
"(-)2:src snapshot name:$snapshots" "3:new dest snapshot name: " "*:$aptly_query"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
publish)
|
||||||
|
# read lines of output into
|
||||||
|
# format of each item: <ep:prefix> <distribution>
|
||||||
|
local -a publish_prefixes
|
||||||
|
local -a publish_dists
|
||||||
|
for line in ${(@f)"$(aptly $config publish list -raw=true 2>/dev/null)"}
|
||||||
|
{
|
||||||
|
publish_prefixes+=($line[(ws: :)1])
|
||||||
|
publish_dists+=($line[(ws: :)2])
|
||||||
|
}
|
||||||
|
publish_prefixes_uniq=(${(@u)publish_prefixes})
|
||||||
|
publish_dists_uniq=(${(@u)publish_dists})
|
||||||
|
[[ -z $publish_prefixes_uniq ]] && publish_prefixes_uniq=" " || publish_prefixes_uniq="($publish_prefixes_uniq)"
|
||||||
|
[[ -z $publish_dists_uniq ]] && publish_dists_uniq=" " || publish_dists_uniq="($publish_dists_uniq)"
|
||||||
|
|
||||||
|
local gpg_keys=$(get_gpg_key_ids)
|
||||||
|
|
||||||
|
# common options for publishing
|
||||||
|
# TODO: is the keyring parameter correct?
|
||||||
|
local publish_update_options=(
|
||||||
|
"-batch=[run GPG with detached tty]:$bool"
|
||||||
|
"-force-overwrite=[overwrite files in package pool in case of mismatch]:$bool"
|
||||||
|
"-gpg-key=[GPG key ID to use when signing the release]:gpg key id:$gpg_keys"
|
||||||
|
"-keyring=[GPG keyring to use (instead of default)]:keyring file:_files -g '*.gpg'"
|
||||||
|
"-passphrase=[GPG passphrase for the key (warning: could be insecure)]:passphrase: "
|
||||||
|
"-passphrase-file=[GPG passphrase−file for the key (warning: could be insecure)]:passphrase file:_files"
|
||||||
|
"-secret-keyring=[GPG secret keyring to use (instead of default)]:secret-keyring:_files"
|
||||||
|
"-skip-contents=[don’t generate Contents indexes]:$bool"
|
||||||
|
"-skip-bz2=[don't generate bzipped indexes]:$bool"
|
||||||
|
"-skip-signing=[don’t sign Release files with GPG]:$bool"
|
||||||
|
)
|
||||||
|
local components_options=(
|
||||||
|
"-component=[component name to publish (for multi−component publishing, separate components with commas)]:components:_values -s , components $components"
|
||||||
|
)
|
||||||
|
local publish_options=(
|
||||||
|
"-butautomaticupgrades=[set value for ButAutomaticUpgrades field]:$bool"
|
||||||
|
"-distribution=[distribution name to publish]:distribution:($dists)"
|
||||||
|
"-label=[label to publish]:label: "
|
||||||
|
"-suite=[suite to publish]:suite: "
|
||||||
|
"-notautomatic=[set value for NotAutomatic field]:notautomatic: "
|
||||||
|
"-origin=[origin name to publish]:origin: "
|
||||||
|
${components_options[@]}
|
||||||
|
)
|
||||||
|
|
||||||
|
local endpoint_prefix="[endpoint\:]prefix"
|
||||||
|
|
||||||
|
case $subcmd in
|
||||||
|
repo)
|
||||||
|
local repos=$(get_repos)
|
||||||
|
_arguments \
|
||||||
|
${publish_options[@]} \
|
||||||
|
${publish_update_options[@]} \
|
||||||
|
"(-)2:repo name:$repos" "3::$endpoint_prefix: "
|
||||||
|
;;
|
||||||
|
snapshot)
|
||||||
|
local snapshots=$(get_snapshots)
|
||||||
|
_arguments '1:: :' \
|
||||||
|
${publish_options[@]} \
|
||||||
|
${publish_update_options[@]} \
|
||||||
|
"(-)*:snapshot name:$snapshots" "3::$endpoint_prefix: "
|
||||||
|
;;
|
||||||
|
switch)
|
||||||
|
local snapshots=$(get_snapshots)
|
||||||
|
_arguments \
|
||||||
|
${publish_update_options[@]} \
|
||||||
|
${components_options[@]} \
|
||||||
|
"(-)2:distribution:$publish_dists_uniq" "3::$endpoint_prefix:$publish_prefixes_uniq" \
|
||||||
|
"*:new snapshot name:$snapshots"
|
||||||
|
;;
|
||||||
|
update)
|
||||||
|
_arguments \
|
||||||
|
${publish_update_options[@]} \
|
||||||
|
"(-)2:distribution:$publish_dists_uniq" "3::$endpoint_prefix:$publish_prefixes_uniq"
|
||||||
|
;;
|
||||||
|
show)
|
||||||
|
_arguments '1:: :' \
|
||||||
|
"(-)2:distribution:$publish_dists_uniq" "3::$endpoint_prefix:$publish_prefixes_uniq"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
package)
|
||||||
|
case $subcmd in
|
||||||
|
search)
|
||||||
|
_arguments \
|
||||||
|
"-format=[custom format for result printing]:$aptly_format" \
|
||||||
|
"(-)2:$aptly_query"
|
||||||
|
;;
|
||||||
|
show)
|
||||||
|
_arguments \
|
||||||
|
"-with-files=[display information about files from package pool]:$bool" \
|
||||||
|
"-with-references=[display information about mirrors, snapshots and local repos referencing this package]:$bool" \
|
||||||
|
"(-)2:$aptly_query"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
db)
|
||||||
|
case $subcmd in
|
||||||
|
cleanup)
|
||||||
|
_arguments '1:: :' \
|
||||||
|
"-dry-run=[don’t delete anything]:$bool" \
|
||||||
|
"-verbose=[be verbose when loading objects/removing them]:$bool"
|
||||||
|
;;
|
||||||
|
recover)
|
||||||
|
# nothing to complete...
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
serve)
|
||||||
|
# completed in _aptly-subcmd
|
||||||
|
;;
|
||||||
|
api)
|
||||||
|
case $subcmd in
|
||||||
|
serve)
|
||||||
|
_arguments '1:: :' \
|
||||||
|
"-listen=[host:port for HTTP listening or unix://path to listen on a Unix domain socket]:host\:port or unix\://path: " \
|
||||||
|
"-no-lock=[don’t lock the database]:$bool"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
graph)
|
||||||
|
# completed in _aptly-subcmd
|
||||||
|
;;
|
||||||
|
config)
|
||||||
|
case $subcmd in
|
||||||
|
show)
|
||||||
|
# nothing to do
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
task)
|
||||||
|
case $subcmd in
|
||||||
|
run)
|
||||||
|
_arguments '1:: :' \
|
||||||
|
"(2)-filename=[specifies the filename that contains the commands to run]:filename:_files" \
|
||||||
|
"(-filename)*::comma-separated command list: "
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# main completion
|
||||||
|
_arguments -C \
|
||||||
|
"-architectures=[list of architectures to consider (comma−separated), default to all available]:architectures:_values -s , architectures $arch_list" \
|
||||||
|
"-config=[location of configuration file]:file:_files -g '*.conf'" \
|
||||||
|
"-db-open-attempts=[number of attempts to open DB if it’s locked by other instance]:number:()" \
|
||||||
|
"-dep-follow-all-variants=[when processing dependencies, follow a & b if dependency is ’a|b’]:$bool" \
|
||||||
|
"-dep-follow-recommends=[when processing dependencies, follow Recommends]:$bool" \
|
||||||
|
"-dep-follow-source=[when processing dependencies, follow from binary to Source packages]:$bool" \
|
||||||
|
"-dep-follow-suggests=[when processing dependencies, follow Suggests]:$bool" \
|
||||||
|
"-dep-verbose-resolve=[when processing dependencies, print detailed logs]:$bool" \
|
||||||
|
"-gpg-provider=[PGP implementation]:gpg provider:((gpg\:'external gpg' internal\:'Go internal implementation'))" \
|
||||||
|
'(-)1: :->cmds' \
|
||||||
|
'2: :->subcmd' \
|
||||||
|
'*:: :->args' && ret=0
|
||||||
|
|
||||||
|
cmd=$line[1]
|
||||||
|
subcmd=$line[2]
|
||||||
|
|
||||||
|
case $state in
|
||||||
|
cmds)
|
||||||
|
_aptly-cmd
|
||||||
|
_arguments '(-)1:: :((help\:integrated\ command\ help))'
|
||||||
|
;;
|
||||||
|
subcmd)
|
||||||
|
case $cmd in
|
||||||
|
help)
|
||||||
|
_aptly-cmd
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
_aptly-subcmd $cmd
|
||||||
|
_arguments '(-)2:: :((help\:integrated\ command\ help))'
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
|
||||||
|
args)
|
||||||
|
# help anywhere in line?
|
||||||
|
if [[ ${line[(i)help]} -le ${#line} ]]; then
|
||||||
|
if [[ ${#line} -le 3 ]]; then
|
||||||
|
if [[ $line[1] == help ]]; then
|
||||||
|
_aptly-subcmd $subcmd
|
||||||
|
elif [[ $line[2] == help ]]; then
|
||||||
|
_aptly-subcmd $cmd
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
_aptly-param $cmd $subcmd
|
||||||
|
# this somehow destroys parameter completion, so disable it for now
|
||||||
|
#_arguments '(-)3:: :((help\:integrated\ command\ help))'
|
||||||
|
fi
|
||||||
|
ret=0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
# mode: Shell-Script
|
||||||
|
# sh-indentation: 4
|
||||||
|
# indent-tabs-mode: nil
|
||||||
|
# sh-basic-offset: 4
|
||||||
|
# End:
|
||||||
|
# vim: ft=zsh sw=4 ts=4 et
|
||||||
@@ -0,0 +1,637 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# (The MIT License)
|
||||||
|
#
|
||||||
|
# Copyright (c) 2014 Andrey Smirnov
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
__aptly_mirror_list()
|
||||||
|
{
|
||||||
|
aptly mirror list -raw
|
||||||
|
}
|
||||||
|
|
||||||
|
__aptly_repo_list()
|
||||||
|
{
|
||||||
|
aptly repo list -raw
|
||||||
|
}
|
||||||
|
|
||||||
|
__aptly_snapshot_list()
|
||||||
|
{
|
||||||
|
aptly snapshot list -raw
|
||||||
|
}
|
||||||
|
|
||||||
|
__aptly_published_distributions()
|
||||||
|
{
|
||||||
|
aptly publish list -raw | cut -d ' ' -f 2 | sort | uniq
|
||||||
|
}
|
||||||
|
|
||||||
|
__aptly_published_prefixes()
|
||||||
|
{
|
||||||
|
aptly publish list -raw | cut -d ' ' -f 1 | sort | uniq
|
||||||
|
}
|
||||||
|
|
||||||
|
__aptly_prefixes_for_distribution()
|
||||||
|
{
|
||||||
|
aptly publish list -raw | awk -v dist="$1" '{ if (dist == $2) print $1 }' | sort | uniq
|
||||||
|
}
|
||||||
|
|
||||||
|
_aptly()
|
||||||
|
{
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
|
||||||
|
commands="api config db graph mirror package publish repo serve snapshot task version"
|
||||||
|
options="-architectures= -config= -db-open-attempts= -dep-follow-all-variants -dep-follow-recommends -dep-follow-source -dep-follow-suggests -dep-verbose-resolve -gpg-provider="
|
||||||
|
db_subcommands="cleanup recover"
|
||||||
|
mirror_subcommands="create drop edit show list rename search update"
|
||||||
|
publish_subcommands="drop list repo snapshot switch update"
|
||||||
|
snapshot_subcommands="create diff drop filter list merge pull rename search show verify"
|
||||||
|
repo_subcommands="add copy create drop edit import include list move remove rename search show"
|
||||||
|
package_subcommands="search show"
|
||||||
|
task_subcommands="run"
|
||||||
|
config_subcommands="show"
|
||||||
|
api_subcommands="serve"
|
||||||
|
|
||||||
|
local cmd subcmd numargs numoptions i
|
||||||
|
|
||||||
|
numargs=0
|
||||||
|
numoptions=0
|
||||||
|
|
||||||
|
for (( i=1; i < $COMP_CWORD; i++ )); do
|
||||||
|
if [[ -n "$cmd" ]]; then
|
||||||
|
if [[ ! -n "$subcmd" ]]; then
|
||||||
|
subcmd=${COMP_WORDS[i]}
|
||||||
|
numargs=$(( COMP_CWORD - i - 1 ))
|
||||||
|
else
|
||||||
|
if [[ "${COMP_WORDS[i]}" == -* ]]; then
|
||||||
|
numoptions=$(( numoptions + 1 ))
|
||||||
|
numargs=$(( numargs - 1 ))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [[ ! "${COMP_WORDS[i]}" == -* ]]; then
|
||||||
|
cmd=${COMP_WORDS[i]}
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ ! -n "$cmd" ]];
|
||||||
|
then
|
||||||
|
case "$cur" in
|
||||||
|
-*)
|
||||||
|
COMPREPLY=($(compgen -W "${options}" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -n "$subcmd" ]];
|
||||||
|
then
|
||||||
|
case "$prev" in
|
||||||
|
"db")
|
||||||
|
COMPREPLY=($(compgen -W "${db_subcommands}" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
"mirror")
|
||||||
|
COMPREPLY=($(compgen -W "${mirror_subcommands}" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
"repo")
|
||||||
|
COMPREPLY=($(compgen -W "${repo_subcommands}" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
"snapshot")
|
||||||
|
COMPREPLY=($(compgen -W "${snapshot_subcommands}" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
"publish")
|
||||||
|
COMPREPLY=($(compgen -W "${publish_subcommands}" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
"package")
|
||||||
|
COMPREPLY=($(compgen -W "${package_subcommands}" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
"task")
|
||||||
|
COMPREPLY=($(compgen -W "${task_subcommands}" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
"config")
|
||||||
|
COMPREPLY=($(compgen -W "${config_subcommands}" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
"api")
|
||||||
|
COMPREPLY=($(compgen -W "${api_subcommands}" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$cmd" in
|
||||||
|
"mirror")
|
||||||
|
case "$subcmd" in
|
||||||
|
"create")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-filter= -filter-with-deps -force-components -ignore-signatures -keyring= -with-installer -with-sources -with-udebs" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"edit")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-archive-url= -filter= -filter-with-deps -ignore-signatures -keyring= -with-installer -with-sources -with-udebs" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_mirror_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"show")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-with-packages" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_mirror_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"search")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-format= -with-deps" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_mirror_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"rename")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_mirror_list)" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"drop")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-force" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_mirror_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"list")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-raw" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"update")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-force -download-limit= -downloader= -ignore-checksums -ignore-signatures -keyring= -skip-existing-packages" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_mirror_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
"repo")
|
||||||
|
case "$subcmd" in
|
||||||
|
"add")
|
||||||
|
case $numargs in
|
||||||
|
0)
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-force-replace -remove-files" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_repo_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
1)
|
||||||
|
_filedir '@(deb|dsc|udeb)'
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
"copy"|"move")
|
||||||
|
case $numargs in
|
||||||
|
0)
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-with-deps -dry-run" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_repo_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
1)
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_repo_list)" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
"create")
|
||||||
|
case $numargs in
|
||||||
|
0)
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-comment= -distribution= -component= -uploaders-file=" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
1)
|
||||||
|
COMPREPLY=($(compgen -W "from" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
COMPREPLY=($(compgen -W "snapshot" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
3)
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_snapshot_list)" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
"drop")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-force" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_repo_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"edit")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-comment= -distribution= -component= -uploaders-file=" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_repo_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"search")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-format= -with-deps" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_repo_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"list")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-raw -json" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_repo_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"include")
|
||||||
|
case $numargs in
|
||||||
|
0)
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-accept-unsigned -force-replace -ignore-signatures -keyring= -no-remove-files -repo= -uploaders-file=" -- ${cur}))
|
||||||
|
else
|
||||||
|
comptopt -o filenames 2>/dev/null
|
||||||
|
COMPREPLY=($(compgen -f -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
"import")
|
||||||
|
case $numargs in
|
||||||
|
0)
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-with-deps -dry-run" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_mirror_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
1)
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_repo_list)" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
"remove")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-dry-run" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_repo_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"show")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-json -with-packages" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_repo_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"rename")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_repo_list)" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
"snapshot")
|
||||||
|
case "$subcmd" in
|
||||||
|
"create")
|
||||||
|
case $numargs in
|
||||||
|
1)
|
||||||
|
COMPREPLY=($(compgen -W "from empty" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
if [[ "$prev" == "from" ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "mirror repo" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
3)
|
||||||
|
if [[ "$prev" == "mirror" ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_mirror_list)" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
if [[ "$prev" == "repo" ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_repo_list)" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
"diff")
|
||||||
|
if [[ $numargs -eq 0 ]] && [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-only-matching" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $numargs -lt 2 ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_snapshot_list)" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"drop")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-force" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_snapshot_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"list")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-raw -sort=" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"merge")
|
||||||
|
if [[ $numargs -gt 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-latest" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_snapshot_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"pull")
|
||||||
|
if [[ $numargs -eq 0 ]] && [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-all-matches -dry-run -no-deps -no-remove" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $numargs -lt 2 ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_snapshot_list)" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"filter")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-with-deps" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_snapshot_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"show")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-with-packages" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_snapshot_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"search")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-format= -with-deps" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_snapshot_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"rename")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_snapshot_list)" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"verify")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_snapshot_list)" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
"publish")
|
||||||
|
case "$subcmd" in
|
||||||
|
"snapshot"|"repo")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-acquire-by-hash -batch -butautomaticupgrades= -component= -distribution= -force-overwrite -gpg-key= -keyring= -label= -suite= -notautomatic= -origin= -passphrase= -passphrase-file= -secret-keyring= -skip-contents -skip-bz2 -skip-signing" -- ${cur}))
|
||||||
|
else
|
||||||
|
if [[ "$subcmd" == "snapshot" ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_snapshot_list)" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_repo_list)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $numargs -eq 1 ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_published_prefixes)" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"list")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-raw" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"update")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-batch -force-overwrite -gpg-key= -keyring= -passphrase= -passphrase-file= -secret-keyring= -skip-cleanup -skip-contents -skip-bz2 -skip-signing" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_published_distributions)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $numargs -eq 1 ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_prefixes_for_distribution $prev)" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"switch")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-batch -force-overwrite -component= -gpg-key= -keyring= -passphrase= -passphrase-file= -secret-keyring= -skip-cleanup -skip-contents -skip-bz2 -skip-signing" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_published_distributions)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $numargs -eq 1 ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_prefixes_for_distribution $prev)" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $numargs -ge 2 ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_snapshot_list)" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"drop")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-force-drop -skip-cleanup" -- ${cur}))
|
||||||
|
else
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_published_distributions)" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $numargs -eq 1 ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "$(__aptly_prefixes_for_distribution $prev)" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
"package")
|
||||||
|
case "$subcmd" in
|
||||||
|
"search")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-format=" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"show")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-with-files -with-references" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
"serve")
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-listen=" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"graph")
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-format= -output=" -- ${cur}))
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"api")
|
||||||
|
case "$subcmd" in
|
||||||
|
"serve")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-listen=" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
"db")
|
||||||
|
case "$subcmd" in
|
||||||
|
"cleanup")
|
||||||
|
if [[ $numargs -eq 0 ]]; then
|
||||||
|
if [[ "$cur" == -* ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "-dry-run -verbose" -- ${cur}))
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
} && complete -F _aptly aptly
|
||||||
+37
-13
@@ -2,14 +2,17 @@ package console
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/cheggaaa/pb"
|
"os"
|
||||||
"github.com/smira/aptly/aptly"
|
|
||||||
"github.com/wsxiaoys/terminal/color"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/cheggaaa/pb"
|
||||||
|
"github.com/wsxiaoys/terminal/color"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
codePrint = iota
|
codePrint = iota
|
||||||
|
codePrintStdErr
|
||||||
codeProgress
|
codeProgress
|
||||||
codeHideProgress
|
codeHideProgress
|
||||||
codeStop
|
codeStop
|
||||||
@@ -27,7 +30,6 @@ type printTask struct {
|
|||||||
// Progress is a progress displaying subroutine, it allows to show download and other operations progress
|
// Progress is a progress displaying subroutine, it allows to show download and other operations progress
|
||||||
// mixed with progress bar
|
// mixed with progress bar
|
||||||
type Progress struct {
|
type Progress struct {
|
||||||
stop chan bool
|
|
||||||
stopped chan bool
|
stopped chan bool
|
||||||
queue chan printTask
|
queue chan printTask
|
||||||
bar *pb.ProgressBar
|
bar *pb.ProgressBar
|
||||||
@@ -67,7 +69,7 @@ func (p *Progress) Flush() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// InitBar starts progressbar for count bytes or count items
|
// InitBar starts progressbar for count bytes or count items
|
||||||
func (p *Progress) InitBar(count int64, isBytes bool) {
|
func (p *Progress) InitBar(count int64, isBytes bool, barType aptly.BarType) {
|
||||||
if p.bar != nil {
|
if p.bar != nil {
|
||||||
panic("bar already initialized")
|
panic("bar already initialized")
|
||||||
}
|
}
|
||||||
@@ -127,25 +129,41 @@ func (p *Progress) Printf(msg string, a ...interface{}) {
|
|||||||
p.queue <- printTask{code: codePrint, message: fmt.Sprintf(msg, a...)}
|
p.queue <- printTask{code: codePrint, message: fmt.Sprintf(msg, a...)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PrintfStdErr does printf but in safe manner to stderr
|
||||||
|
func (p *Progress) PrintfStdErr(msg string, a ...interface{}) {
|
||||||
|
p.queue <- printTask{code: codePrintStdErr, message: fmt.Sprintf(msg, a...)}
|
||||||
|
}
|
||||||
|
|
||||||
// ColoredPrintf does printf in colored way + newline
|
// ColoredPrintf does printf in colored way + newline
|
||||||
func (p *Progress) ColoredPrintf(msg string, a ...interface{}) {
|
func (p *Progress) ColoredPrintf(msg string, a ...interface{}) {
|
||||||
if RunningOnTerminal() {
|
if RunningOnTerminal() {
|
||||||
p.queue <- printTask{code: codePrint, message: color.Sprintf(msg, a...) + "\n"}
|
p.queue <- printTask{code: codePrint, message: color.Sprintf(msg, a...) + "\n"}
|
||||||
} else {
|
} else {
|
||||||
// stip color marks
|
// stip color marks
|
||||||
var prev rune
|
var inColorMark, inCurly bool
|
||||||
msg = strings.Map(func(r rune) rune {
|
msg = strings.Map(func(r rune) rune {
|
||||||
if prev == '@' {
|
if inColorMark {
|
||||||
prev = 0
|
if inCurly {
|
||||||
if r == '@' {
|
if r == '}' {
|
||||||
return r
|
inCurly = false
|
||||||
|
inColorMark = false
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if r == '{' {
|
||||||
|
inCurly = true
|
||||||
|
} else if r == '@' {
|
||||||
|
return '@'
|
||||||
|
} else {
|
||||||
|
inColorMark = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
prev = r
|
|
||||||
if r == '@' {
|
|
||||||
return -1
|
|
||||||
|
|
||||||
|
if r == '@' {
|
||||||
|
inColorMark = true
|
||||||
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
@@ -171,6 +189,12 @@ func (p *Progress) worker() {
|
|||||||
p.barShown = false
|
p.barShown = false
|
||||||
}
|
}
|
||||||
fmt.Print(task.message)
|
fmt.Print(task.message)
|
||||||
|
case codePrintStdErr:
|
||||||
|
if p.barShown {
|
||||||
|
fmt.Print("\r\033[2K")
|
||||||
|
p.barShown = false
|
||||||
|
}
|
||||||
|
fmt.Fprint(os.Stderr, task.message)
|
||||||
case codeProgress:
|
case codeProgress:
|
||||||
if hasBar {
|
if hasBar {
|
||||||
fmt.Print("\r" + task.message)
|
fmt.Print("\r" + task.message)
|
||||||
|
|||||||
+3
-2
@@ -1,11 +1,12 @@
|
|||||||
package console
|
package console
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"golang.org/x/crypto/ssh/terminal"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RunningOnTerminal checks whether stdout is terminal
|
// RunningOnTerminal checks whether stdout is terminal
|
||||||
func RunningOnTerminal() bool {
|
func RunningOnTerminal() bool {
|
||||||
return terminal.IsTerminal(syscall.Stdout)
|
return term.IsTerminal(syscall.Stdout)
|
||||||
}
|
}
|
||||||
|
|||||||
+216
-54
@@ -2,40 +2,50 @@
|
|||||||
package context
|
package context
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
gocontext "context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/smira/aptly/aptly"
|
"math/rand"
|
||||||
"github.com/smira/aptly/console"
|
|
||||||
"github.com/smira/aptly/database"
|
|
||||||
"github.com/smira/aptly/deb"
|
|
||||||
"github.com/smira/aptly/files"
|
|
||||||
"github.com/smira/aptly/http"
|
|
||||||
"github.com/smira/aptly/s3"
|
|
||||||
"github.com/smira/aptly/swift"
|
|
||||||
"github.com/smira/aptly/utils"
|
|
||||||
"github.com/smira/commander"
|
|
||||||
"github.com/smira/flag"
|
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/aptly-dev/aptly/aptly"
|
||||||
|
"github.com/aptly-dev/aptly/azure"
|
||||||
|
"github.com/aptly-dev/aptly/console"
|
||||||
|
"github.com/aptly-dev/aptly/database"
|
||||||
|
"github.com/aptly-dev/aptly/database/goleveldb"
|
||||||
|
"github.com/aptly-dev/aptly/deb"
|
||||||
|
"github.com/aptly-dev/aptly/files"
|
||||||
|
"github.com/aptly-dev/aptly/http"
|
||||||
|
"github.com/aptly-dev/aptly/pgp"
|
||||||
|
"github.com/aptly-dev/aptly/s3"
|
||||||
|
"github.com/aptly-dev/aptly/swift"
|
||||||
|
"github.com/aptly-dev/aptly/task"
|
||||||
|
"github.com/aptly-dev/aptly/utils"
|
||||||
|
"github.com/smira/commander"
|
||||||
|
"github.com/smira/flag"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AptlyContext is a common context shared by all commands
|
// AptlyContext is a common context shared by all commands
|
||||||
type AptlyContext struct {
|
type AptlyContext struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
|
||||||
|
gocontext.Context
|
||||||
|
|
||||||
flags, globalFlags *flag.FlagSet
|
flags, globalFlags *flag.FlagSet
|
||||||
configLoaded bool
|
configLoaded bool
|
||||||
|
|
||||||
progress aptly.Progress
|
progress aptly.Progress
|
||||||
downloader aptly.Downloader
|
downloader aptly.Downloader
|
||||||
|
taskList *task.List
|
||||||
database database.Storage
|
database database.Storage
|
||||||
packagePool aptly.PackagePool
|
packagePool aptly.PackagePool
|
||||||
publishedStorages map[string]aptly.PublishedStorage
|
publishedStorages map[string]aptly.PublishedStorage
|
||||||
collectionFactory *deb.CollectionFactory
|
|
||||||
dependencyOptions int
|
dependencyOptions int
|
||||||
architecturesList []string
|
architecturesList []string
|
||||||
// Debug features
|
// Debug features
|
||||||
@@ -99,7 +109,10 @@ func (context *AptlyContext) config() *utils.ConfigStructure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Config file not found, creating default config at %s\n\n", configLocations[0])
|
fmt.Fprintf(os.Stderr, "Config file not found, creating default config at %s\n\n", configLocations[0])
|
||||||
|
|
||||||
|
// as this is fresh aptly installation, we don't need to support legacy pool locations
|
||||||
|
utils.Config.SkipLegacyPool = true
|
||||||
utils.SaveConfig(configLocations[0], &utils.Config)
|
utils.SaveConfig(configLocations[0], &utils.Config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,6 +161,9 @@ func (context *AptlyContext) DependencyOptions() int {
|
|||||||
if context.lookupOption(context.config().DepFollowSource, "dep-follow-source") {
|
if context.lookupOption(context.config().DepFollowSource, "dep-follow-source") {
|
||||||
context.dependencyOptions |= deb.DepFollowSource
|
context.dependencyOptions |= deb.DepFollowSource
|
||||||
}
|
}
|
||||||
|
if context.lookupOption(context.config().DepVerboseResolve, "dep-verbose-resolve") {
|
||||||
|
context.dependencyOptions |= deb.DepVerboseResolve
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.dependencyOptions
|
return context.dependencyOptions
|
||||||
@@ -186,12 +202,17 @@ func (context *AptlyContext) _progress() aptly.Progress {
|
|||||||
return context.progress
|
return context.progress
|
||||||
}
|
}
|
||||||
|
|
||||||
// Downloader returns instance of current downloader
|
// NewDownloader returns instance of new downloader with given progress
|
||||||
func (context *AptlyContext) Downloader() aptly.Downloader {
|
func (context *AptlyContext) NewDownloader(progress aptly.Progress) aptly.Downloader {
|
||||||
context.Lock()
|
context.Lock()
|
||||||
defer context.Unlock()
|
defer context.Unlock()
|
||||||
|
|
||||||
if context.downloader == nil {
|
return context.newDownloader(progress)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDownloader returns instance of new downloader with given progress without locking
|
||||||
|
// so it can be used for internal usage.
|
||||||
|
func (context *AptlyContext) newDownloader(progress aptly.Progress) aptly.Downloader {
|
||||||
var downloadLimit int64
|
var downloadLimit int64
|
||||||
limitFlag := context.flags.Lookup("download-limit")
|
limitFlag := context.flags.Lookup("download-limit")
|
||||||
if limitFlag != nil {
|
if limitFlag != nil {
|
||||||
@@ -200,13 +221,47 @@ func (context *AptlyContext) Downloader() aptly.Downloader {
|
|||||||
if downloadLimit == 0 {
|
if downloadLimit == 0 {
|
||||||
downloadLimit = context.config().DownloadLimit
|
downloadLimit = context.config().DownloadLimit
|
||||||
}
|
}
|
||||||
context.downloader = http.NewDownloader(context.config().DownloadConcurrency,
|
maxTries := context.config().DownloadRetries + 1
|
||||||
downloadLimit*1024, context._progress())
|
maxTriesFlag := context.flags.Lookup("max-tries")
|
||||||
|
if maxTriesFlag != nil {
|
||||||
|
// If flag is defined prefer it to global setting
|
||||||
|
maxTries = maxTriesFlag.Value.Get().(int)
|
||||||
|
}
|
||||||
|
var downloader string = context.config().Downloader
|
||||||
|
downloaderFlag := context.flags.Lookup("downloader")
|
||||||
|
if downloaderFlag != nil {
|
||||||
|
downloader = downloaderFlag.Value.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
if downloader == "grab" {
|
||||||
|
return http.NewGrabDownloader(downloadLimit*1024, maxTries, progress)
|
||||||
|
}
|
||||||
|
return http.NewDownloader(downloadLimit*1024, maxTries, progress)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Downloader returns instance of current downloader
|
||||||
|
func (context *AptlyContext) Downloader() aptly.Downloader {
|
||||||
|
context.Lock()
|
||||||
|
defer context.Unlock()
|
||||||
|
|
||||||
|
if context.downloader == nil {
|
||||||
|
context.downloader = context.newDownloader(context._progress())
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.downloader
|
return context.downloader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TaskList returns instance of current task list
|
||||||
|
func (context *AptlyContext) TaskList() *task.List {
|
||||||
|
context.Lock()
|
||||||
|
defer context.Unlock()
|
||||||
|
|
||||||
|
if context.taskList == nil {
|
||||||
|
context.taskList = task.NewList()
|
||||||
|
}
|
||||||
|
return context.taskList
|
||||||
|
}
|
||||||
|
|
||||||
// DBPath builds path to database
|
// DBPath builds path to database
|
||||||
func (context *AptlyContext) DBPath() string {
|
func (context *AptlyContext) DBPath() string {
|
||||||
context.Lock()
|
context.Lock()
|
||||||
@@ -232,13 +287,40 @@ func (context *AptlyContext) _database() (database.Storage, error) {
|
|||||||
if context.database == nil {
|
if context.database == nil {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
context.database, err = database.OpenDB(context.dbPath())
|
context.database, err = goleveldb.NewDB(context.dbPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("can't open database: %s", err)
|
return nil, fmt.Errorf("can't instantiate database: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.database, nil
|
var tries int
|
||||||
|
if context.config().DatabaseOpenAttempts == -1 {
|
||||||
|
tries = context.flags.Lookup("db-open-attempts").Value.Get().(int)
|
||||||
|
} else {
|
||||||
|
tries = context.config().DatabaseOpenAttempts
|
||||||
|
}
|
||||||
|
|
||||||
|
const BaseDelay = 10 * time.Second
|
||||||
|
const Jitter = 1 * time.Second
|
||||||
|
|
||||||
|
for ; tries >= 0; tries-- {
|
||||||
|
err := context.database.Open()
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "resource temporarily unavailable") {
|
||||||
|
return context.database, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if tries > 0 {
|
||||||
|
delay := time.Duration(rand.NormFloat64()*float64(Jitter) + float64(BaseDelay))
|
||||||
|
if delay < 0 {
|
||||||
|
delay = time.Second
|
||||||
|
}
|
||||||
|
|
||||||
|
context._progress().PrintfStdErr("Unable to open database, sleeping %s, attempts left %d...\n", delay, tries)
|
||||||
|
time.Sleep(delay)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("unable to reopen the DB, maximum number of retries reached")
|
||||||
}
|
}
|
||||||
|
|
||||||
// CloseDatabase closes the db temporarily
|
// CloseDatabase closes the db temporarily
|
||||||
@@ -255,42 +337,21 @@ func (context *AptlyContext) CloseDatabase() error {
|
|||||||
|
|
||||||
// ReOpenDatabase reopens the db after close
|
// ReOpenDatabase reopens the db after close
|
||||||
func (context *AptlyContext) ReOpenDatabase() error {
|
func (context *AptlyContext) ReOpenDatabase() error {
|
||||||
context.Lock()
|
_, err := context.Database()
|
||||||
defer context.Unlock()
|
|
||||||
|
|
||||||
if context.database == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const MaxTries = 10
|
|
||||||
const Delay = 10 * time.Second
|
|
||||||
|
|
||||||
for try := 0; try < MaxTries; try++ {
|
|
||||||
err := context.database.ReOpen()
|
|
||||||
if err == nil || strings.Index(err.Error(), "resource temporarily unavailable") == -1 {
|
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
context._progress().Printf("Unable to reopen database, sleeping %s\n", Delay)
|
|
||||||
<-time.After(Delay)
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("unable to reopen the DB, maximum number of retries reached")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CollectionFactory builds factory producing all kinds of collections
|
// NewCollectionFactory builds factory producing all kinds of collections
|
||||||
func (context *AptlyContext) CollectionFactory() *deb.CollectionFactory {
|
func (context *AptlyContext) NewCollectionFactory() *deb.CollectionFactory {
|
||||||
context.Lock()
|
context.Lock()
|
||||||
defer context.Unlock()
|
defer context.Unlock()
|
||||||
|
|
||||||
if context.collectionFactory == nil {
|
|
||||||
db, err := context._database()
|
db, err := context._database()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatal(err)
|
Fatal(err)
|
||||||
}
|
}
|
||||||
context.collectionFactory = deb.NewCollectionFactory(db)
|
return deb.NewCollectionFactory(db)
|
||||||
}
|
|
||||||
|
|
||||||
return context.collectionFactory
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PackagePool returns instance of PackagePool
|
// PackagePool returns instance of PackagePool
|
||||||
@@ -299,7 +360,7 @@ func (context *AptlyContext) PackagePool() aptly.PackagePool {
|
|||||||
defer context.Unlock()
|
defer context.Unlock()
|
||||||
|
|
||||||
if context.packagePool == nil {
|
if context.packagePool == nil {
|
||||||
context.packagePool = files.NewPackagePool(context.config().RootDir)
|
context.packagePool = files.NewPackagePool(context.config().RootDir, !context.config().SkipLegacyPool)
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.packagePool
|
return context.packagePool
|
||||||
@@ -313,7 +374,14 @@ func (context *AptlyContext) GetPublishedStorage(name string) aptly.PublishedSto
|
|||||||
publishedStorage, ok := context.publishedStorages[name]
|
publishedStorage, ok := context.publishedStorages[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
if name == "" {
|
if name == "" {
|
||||||
publishedStorage = files.NewPublishedStorage(context.config().RootDir)
|
publishedStorage = files.NewPublishedStorage(filepath.Join(context.config().RootDir, "public"), "hardlink", "")
|
||||||
|
} else if strings.HasPrefix(name, "filesystem:") {
|
||||||
|
params, ok := context.config().FileSystemPublishRoots[name[11:]]
|
||||||
|
if !ok {
|
||||||
|
Fatal(fmt.Errorf("published local storage %v not configured", name[11:]))
|
||||||
|
}
|
||||||
|
|
||||||
|
publishedStorage = files.NewPublishedStorage(params.RootDir, params.LinkMethod, params.VerifyMethod)
|
||||||
} else if strings.HasPrefix(name, "s3:") {
|
} else if strings.HasPrefix(name, "s3:") {
|
||||||
params, ok := context.config().S3PublishRoots[name[3:]]
|
params, ok := context.config().S3PublishRoots[name[3:]]
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -321,9 +389,11 @@ func (context *AptlyContext) GetPublishedStorage(name string) aptly.PublishedSto
|
|||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
publishedStorage, err = s3.NewPublishedStorage(params.AccessKeyID, params.SecretAccessKey,
|
publishedStorage, err = s3.NewPublishedStorage(
|
||||||
params.Region, params.Bucket, params.ACL, params.Prefix, params.StorageClass,
|
params.AccessKeyID, params.SecretAccessKey, params.SessionToken,
|
||||||
params.EncryptionMethod, params.PlusWorkaround)
|
params.Region, params.Endpoint, params.Bucket, params.ACL, params.Prefix, params.StorageClass,
|
||||||
|
params.EncryptionMethod, params.PlusWorkaround, params.DisableMultiDel,
|
||||||
|
params.ForceSigV2, params.Debug)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatal(err)
|
Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -335,7 +405,19 @@ func (context *AptlyContext) GetPublishedStorage(name string) aptly.PublishedSto
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
publishedStorage, err = swift.NewPublishedStorage(params.UserName, params.Password,
|
publishedStorage, err = swift.NewPublishedStorage(params.UserName, params.Password,
|
||||||
params.AuthURL, params.Tenant, params.TenantID, params.Container, params.Prefix)
|
params.AuthURL, params.Tenant, params.TenantID, params.Domain, params.DomainID, params.TenantDomain, params.TenantDomainID, params.Container, params.Prefix)
|
||||||
|
if err != nil {
|
||||||
|
Fatal(err)
|
||||||
|
}
|
||||||
|
} else if strings.HasPrefix(name, "azure:") {
|
||||||
|
params, ok := context.config().AzurePublishRoots[name[6:]]
|
||||||
|
if !ok {
|
||||||
|
Fatal(fmt.Errorf("Published Azure storage %v not configured", name[6:]))
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
publishedStorage, err = azure.NewPublishedStorage(
|
||||||
|
params.AccountName, params.AccountKey, params.Container, params.Prefix, params.Endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatal(err)
|
Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -353,6 +435,66 @@ func (context *AptlyContext) UploadPath() string {
|
|||||||
return filepath.Join(context.Config().RootDir, "upload")
|
return filepath.Join(context.Config().RootDir, "upload")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (context *AptlyContext) pgpProvider() string {
|
||||||
|
var provider string
|
||||||
|
|
||||||
|
if context.globalFlags.IsSet("gpg-provider") {
|
||||||
|
provider = context.globalFlags.Lookup("gpg-provider").Value.String()
|
||||||
|
} else {
|
||||||
|
provider = context.config().GpgProvider
|
||||||
|
}
|
||||||
|
|
||||||
|
switch provider {
|
||||||
|
case "gpg": // nolint: goconst
|
||||||
|
case "gpg1": // nolint: goconst
|
||||||
|
case "gpg2": // nolint: goconst
|
||||||
|
case "internal": // nolint: goconst
|
||||||
|
default:
|
||||||
|
Fatal(fmt.Errorf("unknown gpg provider: %v", provider))
|
||||||
|
}
|
||||||
|
|
||||||
|
return provider
|
||||||
|
}
|
||||||
|
|
||||||
|
func (context *AptlyContext) getGPGFinder(provider string) pgp.GPGFinder {
|
||||||
|
switch context.pgpProvider() {
|
||||||
|
case "gpg1":
|
||||||
|
return pgp.GPG1Finder()
|
||||||
|
case "gpg2":
|
||||||
|
return pgp.GPG2Finder()
|
||||||
|
case "gpg":
|
||||||
|
return pgp.GPGDefaultFinder()
|
||||||
|
}
|
||||||
|
|
||||||
|
panic("uknown GPG provider type")
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSigner returns Signer with respect to provider
|
||||||
|
func (context *AptlyContext) GetSigner() pgp.Signer {
|
||||||
|
context.Lock()
|
||||||
|
defer context.Unlock()
|
||||||
|
|
||||||
|
provider := context.pgpProvider()
|
||||||
|
if provider == "internal" { // nolint: goconst
|
||||||
|
return &pgp.GoSigner{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pgp.NewGpgSigner(context.getGPGFinder(provider))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetVerifier returns Verifier with respect to provider
|
||||||
|
func (context *AptlyContext) GetVerifier() pgp.Verifier {
|
||||||
|
context.Lock()
|
||||||
|
defer context.Unlock()
|
||||||
|
|
||||||
|
provider := context.pgpProvider()
|
||||||
|
if provider == "internal" { // nolint: goconst
|
||||||
|
return &pgp.GoVerifier{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pgp.NewGpgVerifier(context.getGPGFinder(provider))
|
||||||
|
}
|
||||||
|
|
||||||
// UpdateFlags sets internal copy of flags in the context
|
// UpdateFlags sets internal copy of flags in the context
|
||||||
func (context *AptlyContext) UpdateFlags(flags *flag.FlagSet) {
|
func (context *AptlyContext) UpdateFlags(flags *flag.FlagSet) {
|
||||||
context.Lock()
|
context.Lock()
|
||||||
@@ -377,6 +519,27 @@ func (context *AptlyContext) GlobalFlags() *flag.FlagSet {
|
|||||||
return context.globalFlags
|
return context.globalFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GoContextHandleSignals upgrades context to handle ^C by aborting context
|
||||||
|
func (context *AptlyContext) GoContextHandleSignals() {
|
||||||
|
context.Lock()
|
||||||
|
defer context.Unlock()
|
||||||
|
|
||||||
|
// Catch ^C
|
||||||
|
sigch := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigch, os.Interrupt)
|
||||||
|
|
||||||
|
var cancel gocontext.CancelFunc
|
||||||
|
|
||||||
|
context.Context, cancel = gocontext.WithCancel(context.Context)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
<-sigch
|
||||||
|
signal.Stop(sigch)
|
||||||
|
context.Progress().PrintfStdErr("Aborting... press ^C once again to abort immediately\n")
|
||||||
|
cancel()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
// Shutdown shuts context down
|
// Shutdown shuts context down
|
||||||
func (context *AptlyContext) Shutdown() {
|
func (context *AptlyContext) Shutdown() {
|
||||||
context.Lock()
|
context.Lock()
|
||||||
@@ -403,7 +566,6 @@ func (context *AptlyContext) Shutdown() {
|
|||||||
context.database = nil
|
context.database = nil
|
||||||
}
|
}
|
||||||
if context.downloader != nil {
|
if context.downloader != nil {
|
||||||
context.downloader.Abort()
|
|
||||||
context.downloader = nil
|
context.downloader = nil
|
||||||
}
|
}
|
||||||
if context.progress != nil {
|
if context.progress != nil {
|
||||||
@@ -418,7 +580,6 @@ func (context *AptlyContext) Cleanup() {
|
|||||||
defer context.Unlock()
|
defer context.Unlock()
|
||||||
|
|
||||||
if context.downloader != nil {
|
if context.downloader != nil {
|
||||||
context.downloader.Shutdown()
|
|
||||||
context.downloader = nil
|
context.downloader = nil
|
||||||
}
|
}
|
||||||
if context.progress != nil {
|
if context.progress != nil {
|
||||||
@@ -435,6 +596,7 @@ func NewContext(flags *flag.FlagSet) (*AptlyContext, error) {
|
|||||||
flags: flags,
|
flags: flags,
|
||||||
globalFlags: flags,
|
globalFlags: flags,
|
||||||
dependencyOptions: -1,
|
dependencyOptions: -1,
|
||||||
|
Context: gocontext.TODO(),
|
||||||
publishedStorages: map[string]aptly.PublishedStorage{},
|
publishedStorages: map[string]aptly.PublishedStorage{},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user