summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xCargo.lock511
-rwxr-xr-xCargo.toml3
-rwxr-xr-xsrc/apply.rs21
-rwxr-xr-xsrc/check.rs25
-rwxr-xr-xsrc/config.rs15
-rw-r--r--src/delete.rs8
-rwxr-xr-xsrc/group.rs29
-rw-r--r--src/install.rs276
-rw-r--r--src/main.rs153
-rw-r--r--src/parallel.rs60
-rwxr-xr-xsrc/progress.rs1
-rwxr-xr-xsrc/repo.rs83
-rwxr-xr-xsrc/resolver.rs90
-rwxr-xr-xsrc/rootfs.rs77
-rwxr-xr-xsrc/sync.rs161
-rwxr-xr-xsrc/update.rs33
16 files changed, 841 insertions, 705 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 6593774..75a7042 100755
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -27,7 +27,7 @@ checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0"
dependencies = [
"cfg-if",
"cipher",
- "cpufeatures",
+ "cpufeatures 0.2.17",
]
[[package]]
@@ -153,7 +153,7 @@ checksum = "3c3610892ee6e0cbce8ae2700349fcf8f98adb0dbfbee85aec3c9179d29cc072"
dependencies = [
"base64ct",
"blake2",
- "cpufeatures",
+ "cpufeatures 0.2.17",
"password-hash",
"zeroize",
]
@@ -379,6 +379,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
+name = "chacha20"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06"
+dependencies = [
+ "cfg-if",
+ "cpufeatures 0.3.0",
+ "rand_core 0.10.1",
+]
+
+[[package]]
name = "chrono"
version = "0.4.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -533,36 +544,25 @@ dependencies = [
]
[[package]]
-name = "core-foundation"
-version = "0.9.4"
+name = "core-foundation-sys"
+version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"
-dependencies = [
- "core-foundation-sys",
- "libc",
-]
+checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
-name = "core-foundation"
-version = "0.10.1"
+name = "cpufeatures"
+version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6"
+checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
dependencies = [
- "core-foundation-sys",
"libc",
]
[[package]]
-name = "core-foundation-sys"
-version = "0.8.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
-
-[[package]]
name = "cpufeatures"
-version = "0.2.17"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
+checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201"
dependencies = [
"libc",
]
@@ -595,7 +595,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76"
dependencies = [
"generic-array",
- "rand_core",
+ "rand_core 0.6.4",
"subtle",
"zeroize",
]
@@ -607,7 +607,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
dependencies = [
"generic-array",
- "rand_core",
+ "rand_core 0.6.4",
"typenum",
]
@@ -627,7 +627,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be"
dependencies = [
"cfg-if",
- "cpufeatures",
+ "cpufeatures 0.2.17",
"curve25519-dalek-derive",
"digest",
"fiat-crypto",
@@ -656,7 +656,7 @@ dependencies = [
"crypto-bigint",
"elliptic-curve",
"pkcs8",
- "rand_core",
+ "rand_core 0.6.4",
"serdect 0.3.0",
"sha3",
"signature",
@@ -875,7 +875,7 @@ checksum = "70e796c081cee67dc755e1a36a0a172b897fab85fc3f6bc48307991f64e4eca9"
dependencies = [
"curve25519-dalek",
"ed25519",
- "rand_core",
+ "rand_core 0.6.4",
"serde",
"sha2",
"subtle",
@@ -898,7 +898,7 @@ dependencies = [
"hkdf",
"pem-rfc7468",
"pkcs8",
- "rand_core",
+ "rand_core 0.6.4",
"sec1",
"serde_json",
"serdect 0.2.0",
@@ -945,7 +945,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393"
dependencies = [
"bitvec",
- "rand_core",
+ "rand_core 0.6.4",
"subtle",
]
@@ -990,21 +990,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
-name = "foreign-types"
-version = "0.3.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
-dependencies = [
- "foreign-types-shared",
-]
-
-[[package]]
-name = "foreign-types-shared"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
-
-[[package]]
name = "form_urlencoded"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1125,8 +1110,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
dependencies = [
"cfg-if",
+ "js-sys",
"libc",
"wasi",
+ "wasm-bindgen",
]
[[package]]
@@ -1137,33 +1124,32 @@ checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
dependencies = [
"cfg-if",
"libc",
- "r-efi",
+ "r-efi 5.3.0",
"wasip2",
]
[[package]]
-name = "ghash"
-version = "0.5.1"
+name = "getrandom"
+version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1"
+checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
dependencies = [
- "opaque-debug",
- "polyval",
+ "cfg-if",
+ "js-sys",
+ "libc",
+ "r-efi 6.0.0",
+ "rand_core 0.10.1",
+ "wasm-bindgen",
]
[[package]]
-name = "git2"
-version = "0.19.0"
+name = "ghash"
+version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b903b73e45dc0c6c596f2d37eccece7c1c8bb6e4407b001096387c63d0d93724"
+checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1"
dependencies = [
- "bitflags",
- "libc",
- "libgit2-sys",
- "log",
- "openssl-probe 0.1.6",
- "openssl-sys",
- "url",
+ "opaque-debug",
+ "polyval",
]
[[package]]
@@ -1173,30 +1159,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63"
dependencies = [
"ff",
- "rand_core",
+ "rand_core 0.6.4",
"subtle",
]
[[package]]
-name = "h2"
-version = "0.4.13"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2f44da3a8150a6703ed5d34e164b875fd14c2cdab9af1252a9a1020bde2bdc54"
-dependencies = [
- "atomic-waker",
- "bytes",
- "fnv",
- "futures-core",
- "futures-sink",
- "http",
- "indexmap",
- "slab",
- "tokio",
- "tokio-util",
- "tracing",
-]
-
-[[package]]
name = "hashbrown"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1300,7 +1267,6 @@ dependencies = [
"bytes",
"futures-channel",
"futures-core",
- "h2",
"http",
"http-body",
"httparse",
@@ -1326,22 +1292,7 @@ dependencies = [
"tokio",
"tokio-rustls",
"tower-service",
-]
-
-[[package]]
-name = "hyper-tls"
-version = "0.6.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0"
-dependencies = [
- "bytes",
- "http-body-util",
- "hyper",
- "hyper-util",
- "native-tls",
- "tokio",
- "tokio-native-tls",
- "tower-service",
+ "webpki-roots",
]
[[package]]
@@ -1362,11 +1313,9 @@ dependencies = [
"percent-encoding",
"pin-project-lite",
"socket2",
- "system-configuration",
"tokio",
"tower-service",
"tracing",
- "windows-registry",
]
[[package]]
@@ -1608,7 +1557,7 @@ version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb26cec98cce3a3d96cbb7bced3c4b16e3d13f27ec56dbd62cbc8f39cfb9d653"
dependencies = [
- "cpufeatures",
+ "cpufeatures 0.2.17",
]
[[package]]
@@ -1633,20 +1582,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
[[package]]
-name = "libgit2-sys"
-version = "0.17.0+1.8.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "10472326a8a6477c3c20a64547b0059e4b0d086869eee31e6d7da728a8eb7224"
-dependencies = [
- "cc",
- "libc",
- "libssh2-sys",
- "libz-sys",
- "openssl-sys",
- "pkg-config",
-]
-
-[[package]]
name = "libm"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1664,32 +1599,6 @@ dependencies = [
]
[[package]]
-name = "libssh2-sys"
-version = "0.3.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "220e4f05ad4a218192533b300327f5150e809b54c4ec83b5a1d91833601811b9"
-dependencies = [
- "cc",
- "libc",
- "libz-sys",
- "openssl-sys",
- "pkg-config",
- "vcpkg",
-]
-
-[[package]]
-name = "libz-sys"
-version = "1.1.28"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fc3a226e576f50782b3305c5ccf458698f92798987f551c6a02efe8276721e22"
-dependencies = [
- "cc",
- "libc",
- "pkg-config",
- "vcpkg",
-]
-
-[[package]]
name = "linux-raw-sys"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1708,6 +1617,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
[[package]]
+name = "lru-slab"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"
+
+[[package]]
name = "lzma-sys"
version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1735,12 +1650,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
[[package]]
-name = "mime"
-version = "0.3.17"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
-
-[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1768,23 +1677,6 @@ dependencies = [
]
[[package]]
-name = "native-tls"
-version = "0.2.18"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "465500e14ea162429d264d44189adc38b199b62b1c21eea9f69e4b73cb03bbf2"
-dependencies = [
- "libc",
- "log",
- "openssl",
- "openssl-probe 0.2.1",
- "openssl-sys",
- "schannel",
- "security-framework",
- "security-framework-sys",
- "tempfile",
-]
-
-[[package]]
name = "nix"
version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1826,7 +1718,7 @@ dependencies = [
"num-integer",
"num-iter",
"num-traits",
- "rand",
+ "rand 0.8.6",
"serde",
"smallvec",
"zeroize",
@@ -1915,56 +1807,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
[[package]]
-name = "openssl"
-version = "0.10.76"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "951c002c75e16ea2c65b8c7e4d3d51d5530d8dfa7d060b4776828c88cfb18ecf"
-dependencies = [
- "bitflags",
- "cfg-if",
- "foreign-types",
- "libc",
- "once_cell",
- "openssl-macros",
- "openssl-sys",
-]
-
-[[package]]
-name = "openssl-macros"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
-name = "openssl-probe"
-version = "0.1.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e"
-
-[[package]]
-name = "openssl-probe"
-version = "0.2.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe"
-
-[[package]]
-name = "openssl-sys"
-version = "0.9.112"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "57d55af3b3e226502be1526dfdba67ab0e9c96fc293004e79576b2b9edb0dbdb"
-dependencies = [
- "cc",
- "libc",
- "pkg-config",
- "vcpkg",
-]
-
-[[package]]
name = "ordered-multimap"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2008,7 +1850,7 @@ dependencies = [
"ecdsa",
"elliptic-curve",
"primeorder",
- "rand_core",
+ "rand_core 0.6.4",
"sha2",
]
@@ -2019,7 +1861,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166"
dependencies = [
"base64ct",
- "rand_core",
+ "rand_core 0.6.4",
"subtle",
]
@@ -2139,7 +1981,7 @@ dependencies = [
"p256",
"p384",
"p521",
- "rand",
+ "rand 0.8.6",
"regex",
"replace_with",
"ripemd",
@@ -2202,7 +2044,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25"
dependencies = [
"cfg-if",
- "cpufeatures",
+ "cpufeatures 0.2.17",
"opaque-debug",
"universal-hash",
]
@@ -2253,6 +2095,62 @@ dependencies = [
]
[[package]]
+name = "quinn"
+version = "0.11.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0c1a41e437b6bbd489372cd4971de128e85c855f56c57f283d20ff016cf7c0a8"
+dependencies = [
+ "bytes",
+ "cfg_aliases",
+ "pin-project-lite",
+ "quinn-proto",
+ "quinn-udp",
+ "rustc-hash",
+ "rustls",
+ "socket2",
+ "thiserror",
+ "tokio",
+ "tracing",
+ "web-time",
+]
+
+[[package]]
+name = "quinn-proto"
+version = "0.11.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "04759210543be93709136e28212294a659ef5001836ff4eab4d663e4529bba83"
+dependencies = [
+ "bytes",
+ "getrandom 0.4.3",
+ "lru-slab",
+ "rand 0.10.2",
+ "rand_pcg",
+ "ring",
+ "rustc-hash",
+ "rustls",
+ "rustls-pki-types",
+ "slab",
+ "thiserror",
+ "tinyvec",
+ "tracing",
+ "web-time",
+]
+
+[[package]]
+name = "quinn-udp"
+version = "0.5.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "35a133f956daabe89a61a685c2649f13d82d5aa4bd5d12d1277e1072a21c0694"
+dependencies = [
+ "cfg_aliases",
+ "libc",
+ "once_cell",
+ "socket2",
+ "tracing",
+ "windows-sys 0.52.0",
+]
+
+[[package]]
name = "quote"
version = "1.0.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2268,6 +2166,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
[[package]]
+name = "r-efi"
+version = "6.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
+
+[[package]]
name = "radium"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2281,7 +2185,18 @@ checksum = "5ca0ecfa931c29007047d1bc58e623ab12e5590e8c7cc53200d5202b69266d8a"
dependencies = [
"libc",
"rand_chacha",
- "rand_core",
+ "rand_core 0.6.4",
+]
+
+[[package]]
+name = "rand"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80"
+dependencies = [
+ "chacha20",
+ "getrandom 0.4.3",
+ "rand_core 0.10.1",
]
[[package]]
@@ -2291,7 +2206,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
- "rand_core",
+ "rand_core 0.6.4",
]
[[package]]
@@ -2304,6 +2219,21 @@ dependencies = [
]
[[package]]
+name = "rand_core"
+version = "0.10.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
+
+[[package]]
+name = "rand_pcg"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a"
+dependencies = [
+ "rand_core 0.10.1",
+]
+
+[[package]]
name = "redox_syscall"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2355,31 +2285,28 @@ checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147"
dependencies = [
"base64 0.22.1",
"bytes",
- "encoding_rs",
"futures-channel",
"futures-core",
"futures-util",
- "h2",
"http",
"http-body",
"http-body-util",
"hyper",
"hyper-rustls",
- "hyper-tls",
"hyper-util",
"js-sys",
"log",
- "mime",
- "native-tls",
"percent-encoding",
"pin-project-lite",
+ "quinn",
+ "rustls",
"rustls-pki-types",
"serde",
"serde_json",
"serde_urlencoded",
"sync_wrapper",
"tokio",
- "tokio-native-tls",
+ "tokio-rustls",
"tokio-util",
"tower",
"tower-http",
@@ -2389,6 +2316,7 @@ dependencies = [
"wasm-bindgen-futures",
"wasm-streams",
"web-sys",
+ "webpki-roots",
]
[[package]]
@@ -2447,7 +2375,6 @@ dependencies = [
"config",
"flate2",
"futures",
- "git2",
"nix",
"once_cell",
"pgp",
@@ -2478,7 +2405,7 @@ dependencies = [
"num-traits",
"pkcs1",
"pkcs8",
- "rand_core",
+ "rand_core 0.6.4",
"signature",
"spki",
"subtle",
@@ -2496,6 +2423,12 @@ dependencies = [
]
[[package]]
+name = "rustc-hash"
+version = "2.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
+
+[[package]]
name = "rustc_version"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2524,6 +2457,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c665f33d38cea657d9614f766881e4d510e0eda4239891eea56b4cadcf01801b"
dependencies = [
"once_cell",
+ "ring",
"rustls-pki-types",
"rustls-webpki",
"subtle",
@@ -2536,6 +2470,7 @@ version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd"
dependencies = [
+ "web-time",
"zeroize",
]
@@ -2572,15 +2507,6 @@ dependencies = [
]
[[package]]
-name = "schannel"
-version = "0.1.28"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1"
-dependencies = [
- "windows-sys 0.61.2",
-]
-
-[[package]]
name = "sec1"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2596,29 +2522,6 @@ dependencies = [
]
[[package]]
-name = "security-framework"
-version = "3.7.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d"
-dependencies = [
- "bitflags",
- "core-foundation 0.10.1",
- "core-foundation-sys",
- "libc",
- "security-framework-sys",
-]
-
-[[package]]
-name = "security-framework-sys"
-version = "2.17.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3"
-dependencies = [
- "core-foundation-sys",
- "libc",
-]
-
-[[package]]
name = "semver"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2728,7 +2631,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba"
dependencies = [
"cfg-if",
- "cpufeatures",
+ "cpufeatures 0.2.17",
"digest",
]
@@ -2750,7 +2653,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
dependencies = [
"cfg-if",
- "cpufeatures",
+ "cpufeatures 0.2.17",
"digest",
]
@@ -2787,7 +2690,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"
dependencies = [
"digest",
- "rand_core",
+ "rand_core 0.6.4",
]
[[package]]
@@ -2905,27 +2808,6 @@ dependencies = [
]
[[package]]
-name = "system-configuration"
-version = "0.7.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b"
-dependencies = [
- "bitflags",
- "core-foundation 0.9.4",
- "system-configuration-sys",
-]
-
-[[package]]
-name = "system-configuration-sys"
-version = "0.6.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4"
-dependencies = [
- "core-foundation-sys",
- "libc",
-]
-
-[[package]]
name = "tap"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2995,6 +2877,21 @@ dependencies = [
]
[[package]]
+name = "tinyvec"
+version = "1.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bb4ebadaa0af04fab11ae01eb5f9fdb5f9c5b875506e210e71c07873528baa7f"
+dependencies = [
+ "tinyvec_macros",
+]
+
+[[package]]
+name = "tinyvec_macros"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
+
+[[package]]
name = "tokio"
version = "1.49.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3022,16 +2919,6 @@ dependencies = [
]
[[package]]
-name = "tokio-native-tls"
-version = "0.3.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
-dependencies = [
- "native-tls",
- "tokio",
-]
-
-[[package]]
name = "tokio-rustls"
version = "0.26.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3281,12 +3168,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
-name = "vcpkg"
-version = "0.2.15"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
-
-[[package]]
name = "version_check"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3409,6 +3290,25 @@ dependencies = [
]
[[package]]
+name = "web-time"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb"
+dependencies = [
+ "js-sys",
+ "wasm-bindgen",
+]
+
+[[package]]
+name = "webpki-roots"
+version = "1.0.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a"
+dependencies = [
+ "rustls-pki-types",
+]
+
+[[package]]
name = "winapi-util"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3459,17 +3359,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
-name = "windows-registry"
-version = "0.6.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720"
-dependencies = [
- "windows-link",
- "windows-result",
- "windows-strings",
-]
-
-[[package]]
name = "windows-result"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3698,7 +3587,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7e468321c81fb07fa7f4c636c3972b9100f0346e5b6a9f2bd0603a52f7ed277"
dependencies = [
"curve25519-dalek",
- "rand_core",
+ "rand_core 0.6.4",
"serde",
"zeroize",
]
diff --git a/Cargo.toml b/Cargo.toml
index f0cebab..199da27 100755
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,10 +13,9 @@ clap = { version = "4", features = ["derive"] }
colored = "2"
config = { version = "0.14", features = ["ini"] }
flate2 = "1"
-git2 = "0.19"
nix = { version = "0.29", features = ["mount", "process", "fs", "signal"] }
once_cell = "1"
-reqwest = { version = "0.12", features = ["blocking", "json", "stream"] }
+reqwest = { version = "0.12", default-features = false, features = ["rustls-tls", "blocking", "json", "stream"] }
semver = "1"
pgp = "0.19.0"
serde = { version = "1", features = ["derive"] }
diff --git a/src/apply.rs b/src/apply.rs
index 423a8bc..dd5268d 100755
--- a/src/apply.rs
+++ b/src/apply.rs
@@ -163,16 +163,17 @@ pub fn apply_system(cfg: &Config, dry_run: bool, custom_config: Option<&Path>) -
let installed_set: HashSet<String> = db.packages.keys().cloned().collect();
let mut to_remove: Vec<String> = installed_set.difference(&target_state).cloned().collect();
- if let Err(conflict_err) = resolver::check_conflicts(&required, &db) {
- let msg = conflict_err.to_string();
- eprintln!("{} {}", "[ror]".yellow().bold(), msg);
- if let Some(pkg_conflict) = msg.split("'").nth(3) {
- let pkg = pkg_conflict.to_string();
- if !to_remove.contains(&pkg) {
- to_remove.push(pkg);
- }
- } else {
- return Err(conflict_err);
+ let installed_conflicts = resolver::find_installed_conflicts(&required, &db);
+ for (req_pkg, inst_pkg) in installed_conflicts {
+ eprintln!(
+ "{} Package '{}' conflicts with installed '{}'. Scheduling removal of '{}'.",
+ "[ror]".yellow().bold(),
+ req_pkg,
+ inst_pkg,
+ inst_pkg
+ );
+ if !to_remove.contains(&inst_pkg) {
+ to_remove.push(inst_pkg);
}
}
diff --git a/src/check.rs b/src/check.rs
index 530814f..f7e3126 100755
--- a/src/check.rs
+++ b/src/check.rs
@@ -2,7 +2,7 @@ use colored::Colorize;
use sha2::{Sha256, Digest};
use std::collections::HashMap;
use std::fs;
-use std::io::Write;
+use std::io::{Write, IsTerminal};
use std::path::{Path};
use tempfile::tempdir;
@@ -189,15 +189,22 @@ pub fn check_integrity(cfg: &Config) {
"[ror]".yellow().bold(),
broken_packages.join(", ")
);
- print!("{} Reinstall them? [y/N]: ", "[ror]".blue().bold());
- std::io::stdout().flush().ok();
- let mut answer = String::new();
- std::io::stdin().read_line(&mut answer).ok();
- if answer.trim().eq_ignore_ascii_case("y") {
- for pkg in broken_packages {
- println!("{} Reinstalling {} ...", ">>>".cyan(), pkg);
- crate::install::install_package(&pkg, cfg);
+ if std::io::stdin().is_terminal() {
+ print!("{} Reinstall them? [y/N]: ", "[ror]".blue().bold());
+ std::io::stdout().flush().ok();
+ let mut answer = String::new();
+ std::io::stdin().read_line(&mut answer).ok();
+ if answer.trim().eq_ignore_ascii_case("y") {
+ for pkg in broken_packages {
+ println!("{} Reinstalling {} ...", ">>>".cyan(), pkg);
+ crate::install::install_package(&pkg, cfg);
+ }
}
+ } else {
+ eprintln!(
+ "{} Non-interactive mode: skipping automatic reinstall of broken packages",
+ "[ror]".yellow()
+ );
}
}
}
diff --git a/src/config.rs b/src/config.rs
index 2ff93d8..9a4a22e 100755
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,8 +1,11 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fs;
+use std::io::Write;
+use std::os::unix::fs::PermissionsExt;
use std::path::Path;
use colored::Colorize;
+use tempfile::NamedTempFile;
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct RepositoryConfig {
@@ -155,7 +158,11 @@ impl Config {
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)?;
}
- fs::write(path, ini)
+ let mut tmp = NamedTempFile::new_in(path.parent().unwrap_or(Path::new(".")))?;
+ tmp.write_all(ini.as_bytes())?;
+ fs::set_permissions(tmp.path(), std::fs::Permissions::from_mode(0o644))?;
+ tmp.persist(path)?;
+ Ok(())
}
pub fn to_ini(&self) -> Result<String, config::ConfigError> {
@@ -225,7 +232,11 @@ impl Config {
"gpg_key = \"rorka.pub\"\n",
);
fs::create_dir_all(path.parent().unwrap())?;
- fs::write(path, ini)
+ let mut tmp = NamedTempFile::new_in(path.parent().unwrap_or(Path::new(".")))?;
+ tmp.write_all(ini.as_bytes())?;
+ fs::set_permissions(tmp.path(), std::fs::Permissions::from_mode(0o644))?;
+ tmp.persist(path)?;
+ Ok(())
}
}
diff --git a/src/delete.rs b/src/delete.rs
index 6966f82..094e4c4 100644
--- a/src/delete.rs
+++ b/src/delete.rs
@@ -175,7 +175,13 @@ pub fn remove_package_files_only(_pkg_name: &str, files: &[String]) -> bool {
let mut failed = false;
for rel_path in files {
- let full_path = Path::new("/").join(rel_path);
+ let clean = rel_path.trim_start_matches('/');
+ if clean.contains("..") || clean.is_empty() {
+ eprintln!("{} Skipping suspicious path: {}", "[ror]".red().bold(), rel_path);
+ failed = true;
+ continue;
+ }
+ let full_path = Path::new("/").join(clean);
if full_path.exists() {
debug!("Removing file {}", full_path.display());
if let Err(e) = fs::remove_file(&full_path) {
diff --git a/src/group.rs b/src/group.rs
index 3f1844b..8ce4a88 100755
--- a/src/group.rs
+++ b/src/group.rs
@@ -5,6 +5,21 @@ use colored::Colorize;
use crate::config;
use crate::install;
+const GROUPS_DIR: &str = "/var/ror/packages/groups";
+
+fn sanitize_group_name(name: &str) -> Result<(), String> {
+ if name.is_empty() {
+ return Err("Group name is empty".to_string());
+ }
+ if name.contains('/') || name.contains('\\') || name.contains("..") || name.contains('\0') {
+ return Err(format!("Invalid group name: '{}' contains path traversal characters", name));
+ }
+ if name.starts_with('-') {
+ return Err(format!("Invalid group name: '{}' starts with dash", name));
+ }
+ Ok(())
+}
+
#[derive(Debug, Deserialize)]
pub struct Group {
#[allow(dead_code)]
@@ -34,7 +49,11 @@ pub struct Group {
#[allow(dead_code)]
pub fn install_group(group_name: &str, cfg: &config::Config) {
- let group_file = format!("/var/ror/packages/groups/{}.yaml", group_name);
+ if let Err(e) = sanitize_group_name(group_name) {
+ eprintln!("{} {}", "[ror]".red().bold(), e);
+ return;
+ }
+ let group_file = format!("{}/{}.yaml", GROUPS_DIR, group_name);
if !Path::new(&group_file).exists() {
eprintln!("{} Group '{}' not found!", "[ror]".red().bold(), group_name);
return;
@@ -76,7 +95,8 @@ pub fn install_group(group_name: &str, cfg: &config::Config) {
}
pub fn load_group(group_name: &str) -> Result<Group, String> {
- let group_file = format!("/var/ror/packages/groups/{}.yaml", group_name);
+ sanitize_group_name(group_name)?;
+ let group_file = format!("{}/{}.yaml", GROUPS_DIR, group_name);
let content = fs::read_to_string(&group_file)
.map_err(|e| format!("Failed to read group file: {}", e))?;
let group: Group = serde_yaml::from_str(&content)
@@ -85,14 +105,13 @@ pub fn load_group(group_name: &str) -> Result<Group, String> {
}
pub fn list_groups() {
- let groups_dir = "/var/ror/packages/groups";
- if !Path::new(groups_dir).exists() {
+ if !Path::new(GROUPS_DIR).exists() {
println!("{} Groups directory not found.", "[ror]".yellow());
return;
}
println!("{} Available package groups:", "[ror]".blue().bold());
- if let Ok(entries) = std::fs::read_dir(groups_dir) {
+ if let Ok(entries) = std::fs::read_dir(GROUPS_DIR) {
let mut groups: Vec<String> = entries.flatten()
.filter_map(|e| e.file_name().to_str().map(|s| s.to_string()))
.filter(|n| n.ends_with(".yaml"))
diff --git a/src/install.rs b/src/install.rs
index 48c9c05..8a66118 100644
--- a/src/install.rs
+++ b/src/install.rs
@@ -2,14 +2,14 @@ use serde::{Deserialize, Serialize};
use std::fs;
use std::io::{BufReader, Read, Write};
use std::path::{Path, PathBuf};
-use std::ffi::CStr;
use colored::Colorize;
use reqwest::blocking::Client;
use sha2::{Sha256, Digest};
use walkdir::WalkDir;
use chrono::Local;
use std::collections::HashMap;
-use std::os::unix::fs::symlink;
+use std::os::unix::fs::{symlink, PermissionsExt};
+use tempfile::{NamedTempFile, tempdir};
use crate::config;
use crate::progress::{Spinner, format_bytes};
use crate::debug;
@@ -19,6 +19,47 @@ use pgp::composed::{Deserializable, SignedPublicKey, DetachedSignature};
const REPO_ROOT: &str = "/var/ror/packages";
+fn validate_symlink_target(target: &Path, dst: &Path, expected_root: &Path) -> Result<(), String> {
+ let candidate = if target.is_relative() {
+ let parent = dst.parent().unwrap_or(expected_root);
+ parent.join(target)
+ } else {
+ target.to_path_buf()
+ };
+
+ let mut normalized = PathBuf::new();
+ for comp in candidate.components() {
+ match comp {
+ std::path::Component::Prefix(p) => normalized.push(p.as_os_str()),
+ std::path::Component::RootDir => normalized.push("/"),
+ std::path::Component::CurDir => {}
+ std::path::Component::ParentDir => {
+ normalized.pop();
+ }
+ std::path::Component::Normal(c) => normalized.push(c),
+ }
+ }
+
+ if target.is_relative() && !normalized.starts_with(expected_root) {
+ return Err(format!(
+ "Relative symlink escapes target root: {} -> {}",
+ dst.display(),
+ target.display()
+ ));
+ }
+ Ok(())
+}
+
+fn enforce_https(url: &str, context: &str) -> Result<(), String> {
+ if url.starts_with("http://") {
+ return Err(format!(
+ "Insecure HTTP URL rejected for {}: {}. Only HTTPS is allowed.",
+ context, url
+ ));
+ }
+ Ok(())
+}
+
#[derive(Debug, Clone, PartialEq)]
pub enum VerOp { Ge, Gt, Le, Lt, Eq }
@@ -95,10 +136,8 @@ pub struct Package {
pub libc: Option<String>,
#[serde(default)]
pub depends: Vec<Dependency>,
- #[serde(default, rename = "musl.depends")]
- pub musl_depends: Vec<Dependency>,
- #[serde(default, rename = "glibc.depends")]
- pub glibc_depends: Vec<Dependency>,
+ #[serde(default, flatten)]
+ pub libc_depends: HashMap<String, Vec<Dependency>>,
#[serde(default)]
pub conflicts: Vec<String>,
#[serde(default)]
@@ -109,17 +148,17 @@ pub struct Package {
impl Package {
pub fn effective_depends(&self, libc: &str) -> impl Iterator<Item = &Dependency> {
- let specific: Box<dyn Iterator<Item = &Dependency>> = match libc {
- "musl" => Box::new(self.musl_depends.iter()),
- _ => Box::new(self.glibc_depends.iter()),
+ let libc_key = format!("{}.depends", libc);
+ let specific: Box<dyn Iterator<Item = &Dependency>> = match self.libc_depends.get(&libc_key) {
+ Some(deps) => Box::new(deps.iter()),
+ None => Box::new(std::iter::empty()),
};
self.depends.iter().chain(specific)
}
pub fn all_depends(&self) -> impl Iterator<Item = &Dependency> {
self.depends.iter()
- .chain(self.musl_depends.iter())
- .chain(self.glibc_depends.iter())
+ .chain(self.libc_depends.values().flatten())
}
}
@@ -194,7 +233,11 @@ impl InstalledDB {
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)?;
}
- fs::write(path, json)
+ let mut tmp = NamedTempFile::new_in(path.parent().unwrap_or(Path::new("/")))?;
+ tmp.write_all(json.as_bytes())?;
+ fs::set_permissions(tmp.path(), std::fs::Permissions::from_mode(0o644))?;
+ tmp.persist(path)?;
+ Ok(())
}
pub fn add_package(&mut self, pkg: InstalledPackage) {
@@ -238,6 +281,8 @@ fn sort_mirrors_by_speed(mirrors: &[String]) -> Vec<String> {
pub fn download_and_verify(url: &str, expected_sha: &str, _cfg: &config::Config) -> Result<PathBuf, String> {
debug!("Downloading {} (expected SHA256: {})", url, if expected_sha.is_empty() { "none" } else { expected_sha });
+ enforce_https(url, "package download")?;
+
let client = Client::builder()
.connect_timeout(std::time::Duration::from_secs(30))
.build()
@@ -258,70 +303,64 @@ pub fn download_and_verify(url: &str, expected_sha: &str, _cfg: &config::Config)
.and_then(|v| v.to_str().ok())
.and_then(|s| s.parse::<u64>().ok());
- let tmp_dir = Path::new("/tmp/ror-download");
- fs::create_dir_all(tmp_dir).map_err(|e| format!("Failed to create tmp dir: {}", e))?;
-
- let file_name = url.split('/').last().unwrap_or("archive.tmp");
- let file_path = tmp_dir.join(file_name);
-
- {
- let mut file = fs::File::create(&file_path)
- .map_err(|e| format!("Failed to create temp file: {}", e))?;
- let mut hasher = Sha256::new();
- let mut reader = response;
- let mut buf = [0u8; 65536];
- let mut downloaded: u64 = 0;
-
- loop {
- let n = reader
- .read(&mut buf)
- .map_err(|e| format!("Failed to read response body: {}", e))?;
- if n == 0 {
- break;
+ let mut tmp_file = NamedTempFile::new()
+ .map_err(|e| format!("Failed to create temp file: {}", e))?;
+ let file_path = tmp_file.path().to_path_buf();
+
+ let mut hasher = Sha256::new();
+ let mut reader = response;
+ let mut buf = [0u8; 65536];
+ let mut downloaded: u64 = 0;
+
+ loop {
+ let n = reader
+ .read(&mut buf)
+ .map_err(|e| format!("Failed to read response body: {}", e))?;
+ if n == 0 {
+ break;
+ }
+ hasher.update(&buf[..n]);
+ tmp_file.write_all(&buf[..n])
+ .map_err(|e| format!("Failed to write to temp file: {}", e))?;
+ downloaded += n as u64;
+
+ match total_size {
+ Some(total) if total > 0 => {
+ let pct = downloaded * 40 / total;
+ let bar = format!(
+ "{}>{}",
+ "=".repeat(pct.saturating_sub(1) as usize),
+ " ".repeat((40 - pct) as usize)
+ );
+ eprint!(
+ "\r\x1b[K\x1b[36m[{}]\x1b[0m {} / {}",
+ bar,
+ format_bytes(downloaded),
+ format_bytes(total)
+ );
}
- hasher.update(&buf[..n]);
- file.write_all(&buf[..n])
- .map_err(|e| format!("Failed to write to temp file: {}", e))?;
- downloaded += n as u64;
-
- match total_size {
- Some(total) if total > 0 => {
- let pct = downloaded * 40 / total;
- let bar = format!(
- "{}>{}",
- "=".repeat(pct.saturating_sub(1) as usize),
- " ".repeat((40 - pct) as usize)
- );
- eprint!(
- "\r\x1b[K\x1b[36m[{}]\x1b[0m {} / {}",
- bar,
- format_bytes(downloaded),
- format_bytes(total)
- );
- }
- _ => {
- eprint!("\r\x1b[K{} downloaded", format_bytes(downloaded));
- }
+ _ => {
+ eprint!("\r\x1b[K{} downloaded", format_bytes(downloaded));
}
- std::io::stderr().flush().ok();
}
+ std::io::stderr().flush().ok();
+ }
- eprintln!("\r\x1b[K\x1b[32m✓\x1b[0m Downloaded {}", format_bytes(downloaded));
-
- if !expected_sha.is_empty() {
- let hash = format!("{:x}", hasher.finalize());
- if hash != expected_sha {
- let _ = fs::remove_file(&file_path);
- debug!("SHA256 mismatch: expected {}, got {}", expected_sha, hash);
- return Err(format!(
- "SHA256 mismatch: expected {}, got {}",
- expected_sha, hash
- ));
- }
- debug!("SHA256 verified successfully");
+ eprintln!("\r\x1b[K\x1b[32m✓\x1b[0m Downloaded {}", format_bytes(downloaded));
+
+ if !expected_sha.is_empty() {
+ let hash = format!("{:x}", hasher.finalize());
+ if hash != expected_sha {
+ debug!("SHA256 mismatch: expected {}, got {}", expected_sha, hash);
+ return Err(format!(
+ "SHA256 mismatch: expected {}, got {}",
+ expected_sha, hash
+ ));
}
+ debug!("SHA256 verified successfully");
}
+ drop(tmp_file);
Ok(file_path)
}
@@ -877,6 +916,9 @@ pub fn install_package_with_result(pkg_name: &str, cfg: &config::Config) -> Resu
}
};
let key_file = gpg_key.unwrap();
+ if key_file.contains("..") || key_file.contains('/') {
+ return Err(format!("Invalid GPG key path: {}", key_file));
+ }
let pubkey_path = Path::new(REPO_ROOT).join(key_file);
spinner.tick(&format!("Verifying GPG signature for {}...", pkg_name));
if let Err(e) = verify_gpg_signature(&archive_path, &asc_path, &pubkey_path) {
@@ -889,8 +931,8 @@ pub fn install_package_with_result(pkg_name: &str, cfg: &config::Config) -> Resu
spinner.finish(&format!("GPG signature OK for {}", pkg_name));
}
- let work_dir = Path::new("/tmp/ror-install").join(&pkg.name);
- let _ = fs::remove_dir_all(&work_dir);
+ let shadow = tempdir().map_err(|e| format!("Failed to create temp dir: {}", e))?;
+ let work_dir = shadow.path().join(&pkg.name);
fs::create_dir_all(&work_dir).map_err(|e| format!("Failed to create temp dir: {}", e))?;
let pkg_type = binary.pkg_type.as_deref().unwrap_or("tar.xz");
@@ -932,7 +974,6 @@ pub fn install_package_with_result(pkg_name: &str, cfg: &config::Config) -> Resu
sp2.finish(&format!("Installed {} files", all_installed_files.len()));
debug!("Total installed files: {}", all_installed_files.len());
- let _ = fs::remove_dir_all(&work_dir);
let _ = fs::remove_file(&archive_path);
downloaded = true;
break;
@@ -1018,15 +1059,32 @@ fn strip_package_prefix(target_dir: &Path) -> Result<(), String> {
if !prefix_dir.is_dir() {
return Ok(());
}
- let mut todo: Vec<(PathBuf, PathBuf)> = Vec::new();
+
+ let has_standard_subdir = fs::read_dir(&prefix_dir).ok().map(|rd| {
+ rd.flatten().any(|e| {
+ e.file_name().to_str().map(|n| STANDARD_DIRS.contains(&n)).unwrap_or(false)
+ })
+ }).unwrap_or(false);
+
+ if !has_standard_subdir {
+ return Ok(());
+ }
+
+ let mut todo_dirs = Vec::new();
+ let mut todo_files = Vec::new();
for entry in WalkDir::new(&prefix_dir).into_iter().filter_map(|e| e.ok()) {
- if entry.file_type().is_file() || entry.file_type().is_symlink() {
- let rel = entry.path().strip_prefix(&prefix_dir).unwrap();
- let dst = target_dir.join(rel);
- todo.push((entry.path().to_path_buf(), dst));
+ let rel = entry.path().strip_prefix(&prefix_dir).unwrap();
+ let dst = target_dir.join(rel);
+ if entry.file_type().is_dir() {
+ todo_dirs.push(dst);
+ } else if entry.file_type().is_file() || entry.file_type().is_symlink() {
+ todo_files.push((entry.path().to_path_buf(), dst));
}
}
- for (src, dst) in &todo {
+ for dir in todo_dirs {
+ let _ = fs::create_dir_all(&dir);
+ }
+ for (src, dst) in &todo_files {
if let Some(parent) = dst.parent() {
let _ = fs::create_dir_all(parent);
}
@@ -1119,6 +1177,7 @@ fn install_files(source_dir: &Path, prefix: &str, files: &[String]) -> Result<Ve
if meta.is_symlink() {
let target = fs::read_link(&src)
.map_err(|e| format!("Failed to read link {}: {}", src.display(), e))?;
+ validate_symlink_target(&target, &dst, prefix_path)?;
let _ = fs::remove_file(&dst);
symlink(&target, &dst)
.map_err(|e| format!("Failed to create symlink {}: {}", dst.display(), e))?;
@@ -1150,6 +1209,7 @@ pub fn install_files_to_root(source_dir: &Path, root: &Path, files: &[String]) -
if meta.is_symlink() {
let target = fs::read_link(&src)
.map_err(|e| format!("Failed to read link {}: {}", src.display(), e))?;
+ validate_symlink_target(&target, &dst, root)?;
let _ = fs::remove_file(&dst);
symlink(&target, &dst)
.map_err(|e| format!("Failed to create symlink {}: {}", dst.display(), e))?;
@@ -1167,47 +1227,19 @@ pub fn run_commands(steps: &str, work_dir: &Path) -> Result<(), String> {
if steps.trim().is_empty() {
return Ok(());
}
- use nix::unistd::{fork, ForkResult, chdir, execve};
- use nix::sys::wait::{waitpid, WaitStatus};
- use std::ffi::CString;
-
- let script = format!("#!/bin/sh\nset -e\n{}", steps);
- let tmp_script = "/tmp/ror-install-step.sh";
- fs::write(tmp_script, &script).map_err(|e| format!("Cannot write script: {}", e))?;
-
- match unsafe { fork() } {
- Ok(ForkResult::Child) => {
- if chdir(work_dir).is_err() { std::process::exit(1); }
- let shell = CString::new("/bin/sh").unwrap();
- let arg0 = CString::new("sh").unwrap();
- let arg1 = CString::new(tmp_script).unwrap();
- let _ = execve::<&CStr, &CStr>(&shell, &[&arg0, &arg1], &[]);
- std::process::exit(1);
- }
- Ok(ForkResult::Parent { child }) => {
- match waitpid(child, None) {
- Ok(WaitStatus::Exited(_, code)) => {
- let _ = fs::remove_file(tmp_script);
- if code == 0 {
- Ok(())
- } else {
- Err(format!("Install script failed with code {}", code))
- }
- }
- Ok(_) => {
- let _ = fs::remove_file(tmp_script);
- Err("Install script terminated by signal".to_string())
- }
- Err(e) => {
- let _ = fs::remove_file(tmp_script);
- Err(format!("waitpid failed: {}", e))
- }
- }
- }
- Err(e) => {
- let _ = fs::remove_file(tmp_script);
- Err(format!("Fork failed: {}", e))
- }
+
+ let status = std::process::Command::new("/bin/sh")
+ .arg("-e")
+ .arg("-c")
+ .arg(steps)
+ .current_dir(work_dir)
+ .status()
+ .map_err(|e| format!("Failed to execute install script: {}", e))?;
+
+ if status.success() {
+ Ok(())
+ } else {
+ Err(format!("Install script failed with exit status: {}", status))
}
}
@@ -1288,8 +1320,8 @@ pub fn install_local_package_with_result(archive_path: &Path, _cfg: &config::Con
let version = "local".to_string();
debug!("Local package: name={}, version={}, extension={}", name, version, ext);
- let work_dir = Path::new("/tmp/ror-local").join(&name);
- let _ = fs::remove_dir_all(&work_dir);
+ let shadow = tempdir().map_err(|e| format!("Failed to create temp dir: {}", e))?;
+ let work_dir = shadow.path().join(&name);
fs::create_dir_all(&work_dir).map_err(|e| format!("Failed to create temp dir: {}", e))?;
let mut spinner = Spinner::new(&format!("Installing local package {}", name));
@@ -1316,8 +1348,6 @@ pub fn install_local_package_with_result(archive_path: &Path, _cfg: &config::Con
spinner.finish(&format!("Installed {} files", installed_files.len()));
debug!("Local installation complete, {} files", installed_files.len());
- let _ = fs::remove_dir_all(&work_dir);
-
Ok(InstalledPackage {
name,
version,
diff --git a/src/main.rs b/src/main.rs
index 4e326f0..c2725ee 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -230,10 +230,22 @@ async fn main() {
let db = install::InstalledDB::load();
- for pkg_name in &packages {
- if pkg_name.starts_with('@') {
- continue;
+ let mut all_packages = Vec::new();
+ for item in packages {
+ if let Some(group_name) = item.strip_prefix('@') {
+ match group::load_group(group_name) {
+ Ok(grp) => all_packages.extend(grp.packages),
+ Err(e) => {
+ eprintln!("{} Failed to load group '{}': {}", "[ror]".red().bold(), group_name, e);
+ return;
+ }
+ }
+ } else {
+ all_packages.push(item);
}
+ }
+
+ for pkg_name in &all_packages {
let is_local = pkg_name.starts_with('/')
|| pkg_name.starts_with("./")
|| pkg_name.ends_with(".ror")
@@ -247,62 +259,40 @@ async fn main() {
}
}
- if packages[0].starts_with('@') {
-
- let group_name = &packages[0][1..];
- match group::load_group(group_name) {
- Ok(group) => {
- if let Err(e) = parallel::install_packages_parallel(
- &group.packages,
- Arc::clone(&cfg),
- )
- .await
- {
- eprintln!("{} {}", "[ror]".red().bold(), e);
- }
- }
- Err(e) => eprintln!("{} {}", "[ror]".red().bold(), e),
- }
- } else {
-
- let (local_pkgs, remote_pkgs): (Vec<String>, Vec<String>) = packages
- .iter()
- .cloned()
- .partition(|p| {
- p.starts_with('/')
- || p.starts_with("./")
- || p.ends_with(".ror")
- || p.ends_with(".sror")
- });
-
-
- for path_str in &local_pkgs {
- install::install_local_package(
- std::path::Path::new(path_str),
- &cfg,
- );
- }
+ let (local_pkgs, remote_pkgs): (Vec<String>, Vec<String>) = all_packages
+ .into_iter()
+ .partition(|p| {
+ p.starts_with('/')
+ || p.starts_with("./")
+ || p.ends_with(".ror")
+ || p.ends_with(".sror")
+ });
+
+ for path_str in &local_pkgs {
+ install::install_local_package(
+ std::path::Path::new(path_str),
+ &cfg,
+ );
+ }
- let remote_pkgs: Vec<String> = remote_pkgs.into_iter().map(|p| {
- let (name, variant) = install::parse_package_spec(&p);
- install::resolve_package_name(&name).map(|canonical| {
- match variant {
- Some(v) => format!("{}{{{}}}", canonical, v),
- None => canonical,
- }
- }).unwrap_or(p)
- }).collect();
-
-
- if !remote_pkgs.is_empty() {
- if let Err(e) = parallel::install_packages_parallel(
- &remote_pkgs,
- Arc::clone(&cfg),
- )
- .await
- {
- eprintln!("{} {}", "[ror]".red().bold(), e);
+ let remote_pkgs: Vec<String> = remote_pkgs.into_iter().map(|p| {
+ let (name, variant) = install::parse_package_spec(&p);
+ install::resolve_package_name(&name).map(|canonical| {
+ match variant {
+ Some(v) => format!("{}{{{}}}", canonical, v),
+ None => canonical,
}
+ }).unwrap_or(p)
+ }).collect();
+
+ if !remote_pkgs.is_empty() {
+ if let Err(e) = parallel::install_packages_parallel(
+ &remote_pkgs,
+ Arc::clone(&cfg),
+ )
+ .await
+ {
+ eprintln!("{} {}", "[ror]".red().bold(), e);
}
}
}
@@ -378,22 +368,29 @@ fn run_di(del_pkg: String, inst_pkg: String, cfg: Arc<config::Config>) {
inst_pkg
);
- let del_pkg_c = del_pkg.clone();
- let inst_pkg_c = inst_pkg.clone();
- let cfg_c = Arc::clone(&cfg);
-
- let del_handle = std::thread::spawn(move || {
- delete::remove_package_files_only(&del_pkg_c, &record_files)
- });
+ let installed_pkg = match install::install_package_with_result(&inst_pkg, &cfg) {
+ Ok(pkg) => pkg,
+ Err(e) => {
+ eprintln!(
+ "{} Failed to install '{}': {}. Old package remains intact.",
+ "[ror]".red().bold(),
+ inst_pkg,
+ e
+ );
+ return;
+ }
+ };
- let inst_handle = std::thread::spawn(move || {
- install::install_package_with_result(&inst_pkg_c, &cfg_c)
- });
+ let new_files: std::collections::HashSet<_> = installed_pkg.files.iter().collect();
+ let obsolete_files: Vec<_> = record_files.into_iter()
+ .filter(|f| !new_files.contains(f))
+ .collect();
- let del_ok = del_handle.join().unwrap_or(false);
- let inst_result = inst_handle
- .join()
- .unwrap_or_else(|_| Err("panicked".to_string()));
+ let del_ok = if obsolete_files.is_empty() {
+ true
+ } else {
+ delete::remove_package_files_only(&del_pkg, &obsolete_files)
+ };
let mut db = install::InstalledDB::load();
@@ -401,19 +398,7 @@ fn run_di(del_pkg: String, inst_pkg: String, cfg: Arc<config::Config>) {
db.packages.remove(&del_pkg);
}
- match inst_result {
- Ok(p) => {
- db.add_package(p);
- }
- Err(e) => {
- eprintln!(
- "{} Failed to install '{}': {}",
- "[ror]".red().bold(),
- inst_pkg,
- e
- );
- }
- }
+ db.add_package(installed_pkg);
if let Err(e) = db.save() {
eprintln!("{} Failed to save DB: {}", "[ror]".red().bold(), e);
diff --git a/src/parallel.rs b/src/parallel.rs
index ed4671f..a3a722b 100644
--- a/src/parallel.rs
+++ b/src/parallel.rs
@@ -1,8 +1,3 @@
-// parallel.rs
-#![allow(dead_code)]
-#![allow(unused_imports)]
-#![allow(unused_variables)]
-
use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
@@ -11,7 +6,6 @@ use std::time::Duration;
use std::io::Write;
use colored::Colorize;
-use futures::StreamExt;
use sha2::{Digest, Sha256};
use tokio::sync::oneshot;
use tokio::task;
@@ -60,12 +54,12 @@ impl InstalledDB {
}
struct AtomicInstaller {
- shadow: tempfile::TempDir,
+ _shadow: tempfile::TempDir,
}
impl AtomicInstaller {
fn new(shadow: tempfile::TempDir) -> Self {
- Self { shadow }
+ Self { _shadow: shadow }
}
fn commit(
@@ -90,8 +84,21 @@ impl AtomicInstaller {
std::fs::create_dir_all(parent)
.map_err(|e| format!("Create parent {}: {}", parent.display(), e))?;
- let bak_path = dst.with_extension("ror-old");
if dst.exists() && dst.is_file() {
+ let mut bak_num = 0u32;
+ let bak_path = loop {
+ let mut p = dst.as_os_str().to_os_string();
+ if bak_num == 0 {
+ p.push(".ror-old");
+ } else {
+ p.push(format!(".ror-old.{}", bak_num));
+ }
+ let p = PathBuf::from(p);
+ if !p.exists() {
+ break p;
+ }
+ bak_num += 1;
+ };
if let Err(e) = std::fs::rename(&dst, &bak_path) {
return Err(format!("Cannot backup {}: {}", dst.display(), e));
}
@@ -100,19 +107,14 @@ impl AtomicInstaller {
let rename_err = std::fs::rename(&src, &dst).err();
if let Some(e) = rename_err {
- use std::io::ErrorKind;
if e.raw_os_error() == Some(18) {
if let Err(ce) = std::fs::copy(&src, &dst) {
- if let Some((last_bak, orig)) = backup_paths.pop() {
- let _ = std::fs::rename(&last_bak, &orig);
- }
+ Self::rollback(&backup_paths);
return Err(format!("Failed to install (copy) {}: {}", dst.display(), ce));
}
let _ = std::fs::remove_file(&src);
} else {
- if let Some((last_bak, orig)) = backup_paths.pop() {
- let _ = std::fs::rename(&last_bak, &orig);
- }
+ Self::rollback(&backup_paths);
return Err(format!("Failed to install {}: {}", dst.display(), e));
}
}
@@ -128,9 +130,21 @@ impl AtomicInstaller {
Ok(installed)
}
+
+ fn rollback(backup_paths: &[(PathBuf, PathBuf)]) {
+ for (bak, orig) in backup_paths {
+ if bak.exists() {
+ let _ = std::fs::rename(bak, orig);
+ }
+ }
+ }
}
async fn download_one(url: &str, expected_sha: &str, _cfg: &Config) -> Result<PathBuf, String> {
+ if url.starts_with("http://") {
+ return Err(format!("Insecure HTTP URL rejected: {}. Only HTTPS allowed.", url));
+ }
+
let result = timeout(Duration::from_secs(60), async {
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
@@ -147,24 +161,17 @@ async fn download_one(url: &str, expected_sha: &str, _cfg: &Config) -> Result<Pa
return Err(format!("HTTP {} for {}", res.status(), url));
}
- let tmp_dir = Path::new("/tmp/ror-download");
- std::fs::create_dir_all(tmp_dir).map_err(|e| e.to_string())?;
- let file_name = url.rsplit('/').next().unwrap_or("archive.tmp");
- let file_path = tmp_dir.join(file_name);
-
- let mut file = std::fs::File::create(&file_path).map_err(|e| e.to_string())?;
+ let mut tmp_file = NamedTempFile::new().map_err(|e| e.to_string())?;
+ let file_path = tmp_file.path().to_path_buf();
let mut hasher = Sha256::new();
let body = res.bytes().await.map_err(|e| e.to_string())?;
hasher.update(&body);
- file.write_all(&body).map_err(|e| e.to_string())?;
-
- drop(file);
+ tmp_file.write_all(&body).map_err(|e| e.to_string())?;
if !expected_sha.is_empty() {
let hash = format!("{:x}", hasher.finalize());
if hash != expected_sha {
- let _ = std::fs::remove_file(&file_path);
return Err(format!(
"SHA256 mismatch: expected {}, got {}",
expected_sha, hash
@@ -172,6 +179,7 @@ async fn download_one(url: &str, expected_sha: &str, _cfg: &Config) -> Result<Pa
}
}
+ drop(tmp_file);
Ok(file_path)
})
.await
diff --git a/src/progress.rs b/src/progress.rs
index bd9c806..ec97b79 100755
--- a/src/progress.rs
+++ b/src/progress.rs
@@ -1,4 +1,3 @@
-// src/progress.rs
use std::io::{self, Write};
pub struct ProgressBar {
diff --git a/src/repo.rs b/src/repo.rs
index a6d4b41..34cbbd6 100755
--- a/src/repo.rs
+++ b/src/repo.rs
@@ -1,45 +1,78 @@
use colored::Colorize;
-use std::io::{self, Write};
+use std::io::{self, Write, IsTerminal};
use crate::config::{Config, RepositoryConfig};
+fn is_interactive() -> bool {
+ io::stdin().is_terminal() && io::stdout().is_terminal()
+}
+
pub fn add_repository(name: &str, url: &str, mirror: Option<&str>) -> Result<(), String> {
let mut cfg = Config::load();
if cfg.repositories.contains_key(name) {
return Err(format!("Repository '{}' already exists", name));
}
- print!(
- "{} Enable GPG verification for '{}'? [Y/n]: ",
- "[ror]".blue().bold(),
- name
- );
- io::stdout().flush().ok();
- let mut answer = String::new();
- io::stdin().read_line(&mut answer).ok();
- let gpg_support = !answer.trim().eq_ignore_ascii_case("n");
+ if url.starts_with("http://") {
+ return Err(format!(
+ "Insecure HTTP URL rejected for repository '{}': {}. Only HTTPS is allowed.",
+ name, url
+ ));
+ }
+ if let Some(m) = mirror {
+ if m.starts_with("http://") {
+ return Err(format!(
+ "Insecure HTTP mirror URL rejected for repository '{}': {}. Only HTTPS is allowed.",
+ name, m
+ ));
+ }
+ }
- if !gpg_support {
+ let gpg_support = if is_interactive() {
print!(
- "{} Repository '{}' will have GPG disabled. It may be unsafe. Continue? [y/N]: ",
- "[ror]".yellow().bold(),
+ "{} Enable GPG verification for '{}'? [Y/n]: ",
+ "[ror]".blue().bold(),
name
);
io::stdout().flush().ok();
- let mut confirm = String::new();
- io::stdin().read_line(&mut confirm).ok();
- if !confirm.trim().eq_ignore_ascii_case("y") {
- println!("{} Aborted.", "[ror]".yellow());
- return Ok(());
+ let mut answer = String::new();
+ io::stdin().read_line(&mut answer).ok();
+ let gpg = !answer.trim().eq_ignore_ascii_case("n");
+
+ if !gpg {
+ print!(
+ "{} Repository '{}' will have GPG disabled. It may be unsafe. Continue? [y/N]: ",
+ "[ror]".yellow().bold(),
+ name
+ );
+ io::stdout().flush().ok();
+ let mut confirm = String::new();
+ io::stdin().read_line(&mut confirm).ok();
+ if !confirm.trim().eq_ignore_ascii_case("y") {
+ println!("{} Aborted.", "[ror]".yellow());
+ return Ok(());
+ }
}
- }
+ gpg
+ } else {
+ eprintln!(
+ "{} Non-interactive mode: GPG enabled by default for '{}'",
+ "[ror]".yellow(),
+ name
+ );
+ true
+ };
let gpg_key = if gpg_support {
- print!("{} GPG key filename (e.g. rorka.pub): ", "[ror]".blue().bold());
- io::stdout().flush().ok();
- let mut key = String::new();
- io::stdin().read_line(&mut key).ok();
- let key = key.trim().to_string();
- if key.is_empty() { None } else { Some(key) }
+ if is_interactive() {
+ print!("{} GPG key filename (e.g. rorka.pub): ", "[ror]".blue().bold());
+ io::stdout().flush().ok();
+ let mut key = String::new();
+ io::stdin().read_line(&mut key).ok();
+ let key = key.trim().to_string();
+ if key.is_empty() { None } else { Some(key) }
+ } else {
+ None
+ }
} else {
None
};
diff --git a/src/resolver.rs b/src/resolver.rs
index 1141980..72ddf92 100755
--- a/src/resolver.rs
+++ b/src/resolver.rs
@@ -21,18 +21,13 @@ impl DependencyGraph {
pub fn compute_levels(&self) -> Vec<Vec<String>> {
let mut in_degree: HashMap<String, usize> = HashMap::new();
- for (pkg, deps) in &self.edges {
+ for pkg in self.edges.keys().chain(self.reverse.keys()) {
in_degree.entry(pkg.clone()).or_insert(0);
- for dep in deps {
- *in_degree.entry(dep.clone()).or_insert(0) += 1;
- }
}
- for (pkg, children) in &self.reverse {
- in_degree.entry(pkg.clone()).or_insert(0);
- for child in children {
- in_degree.entry(child.clone()).or_insert(0);
- }
+ for (pkg, deps) in &self.edges {
+ in_degree.insert(pkg.clone(), deps.len());
}
+
let mut levels = Vec::new();
let mut queue: VecDeque<String> = in_degree.iter()
.filter(|&(_, &deg)| deg == 0)
@@ -43,12 +38,14 @@ impl DependencyGraph {
let level_pkgs: Vec<String> = queue.drain(..).collect();
levels.push(level_pkgs.clone());
for pkg in &level_pkgs {
- if let Some(children) = self.reverse.get(pkg) {
- for child in children {
- if let Some(deg) = in_degree.get_mut(child) {
- *deg -= 1;
- if *deg == 0 {
- queue.push_back(child.clone());
+ if let Some(dependents) = self.reverse.get(pkg) {
+ for dep in dependents {
+ if let Some(deg) = in_degree.get_mut(dep) {
+ if *deg > 0 {
+ *deg -= 1;
+ if *deg == 0 {
+ queue.push_back(dep.clone());
+ }
}
}
}
@@ -56,15 +53,17 @@ impl DependencyGraph {
}
}
- let cyclic: Vec<_> = in_degree.iter()
+ let cyclic: Vec<String> = in_degree.iter()
.filter(|&(_, &d)| d > 0)
- .map(|(name, _)| name.as_str())
+ .map(|(name, _)| name.clone())
.collect();
if !cyclic.is_empty() {
eprintln!(
- "{} Warning: cycle detected among packages, they will be installed in arbitrary order",
- "[ror]".yellow().bold()
+ "{} Warning: cycle detected among packages, installing them together: {}",
+ "[ror]".yellow().bold(),
+ cyclic.join(", ")
);
+ levels.push(cyclic);
}
levels
}
@@ -272,3 +271,56 @@ pub fn check_conflicts(required: &HashSet<String>, installed_db: &InstalledDB) -
Ok(())
}
+pub fn find_installed_conflicts(required: &HashSet<String>, installed_db: &InstalledDB) -> Vec<(String, String)> {
+ let mut conflicts = Vec::new();
+ for pkg_name in required {
+ if let Some(pkg) = load_package(pkg_name) {
+ for conflict in &pkg.conflicts {
+ if installed_db.is_installed(conflict) {
+ conflicts.push((pkg_name.clone(), conflict.clone()));
+ }
+ }
+ }
+ }
+ conflicts
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_compute_levels_ordering() {
+ let mut graph = DependencyGraph::new();
+ // A depends on B, B depends on C
+ graph.add_dep("A".into(), "B".into());
+ graph.add_dep("B".into(), "C".into());
+ // D has no deps
+ graph.edges.entry("D".into()).or_default();
+
+ let levels = graph.compute_levels();
+
+ // C and D must be installed first (level 0)
+ assert_eq!(levels.len(), 3);
+ assert!(levels[0].contains(&"C".to_string()));
+ assert!(levels[0].contains(&"D".to_string()));
+ // B must be installed second (level 1)
+ assert_eq!(levels[1], vec!["B".to_string()]);
+ // A must be installed third (level 2)
+ assert_eq!(levels[2], vec!["A".to_string()]);
+ }
+
+ #[test]
+ fn test_cycle_does_not_drop_packages() {
+ let mut graph = DependencyGraph::new();
+ // A depends on B, B depends on A
+ graph.add_dep("A".into(), "B".into());
+ graph.add_dep("B".into(), "A".into());
+
+ let levels = graph.compute_levels();
+ let flattened: Vec<_> = levels.into_iter().flatten().collect();
+ assert!(flattened.contains(&"A".to_string()));
+ assert!(flattened.contains(&"B".to_string()));
+ }
+}
+
diff --git a/src/rootfs.rs b/src/rootfs.rs
index e31444d..65208a0 100755
--- a/src/rootfs.rs
+++ b/src/rootfs.rs
@@ -1,4 +1,3 @@
-// src/rootfs.rs
use std::collections::HashMap;
use std::fs;
use std::path::Path;
@@ -83,8 +82,8 @@ fn build_download_tasks(packages: &[String], target_arch: &str, target_libc: &st
let effective_filename = resolve_filename(&pkg, binary);
- // Prefer local package files when available
- let workspace = std::env::var("ROR_WORKSPACE").unwrap_or_else(|_| "/home/rorka/rorkos".to_string());
+ //prefer local package files when available
+ let workspace = std::env::var("ROR_WORKSPACE").unwrap_or_else(|_| "/var/ror/cache".to_string());
let local_path = Path::new(&workspace).join(&effective_filename);
let urls: Vec<String> = if local_path.exists() {
vec![format!("file://{}", local_path.display())]
@@ -128,11 +127,8 @@ fn download_file_quiet(
bytes_expected_global: &Arc<AtomicU64>,
) -> Result<(std::path::PathBuf, u64), String> {
use sha2::{Sha256, Digest};
-
- let tmp_dir = Path::new("/tmp/ror-download");
- std::fs::create_dir_all(tmp_dir).map_err(|e| e.to_string())?;
- let file_name = url.split('/').last().unwrap_or("archive.tmp");
- let file_path = tmp_dir.join(file_name);
+ use std::io::Write;
+ use tempfile::NamedTempFile;
if let Some(local) = url.strip_prefix("file://") {
let src = Path::new(local);
@@ -141,14 +137,22 @@ fn download_file_quiet(
}
let size = std::fs::metadata(&src).map_err(|e| e.to_string())?.len();
bytes_expected_global.fetch_add(size, Ordering::Relaxed);
- std::fs::copy(&src, &file_path).map_err(|e| e.to_string())?;
- // Also copy the accompanying .dict file if it exists (for zstd dictionary decompression)
+ let mut tmp_file = NamedTempFile::new().map_err(|e| e.to_string())?;
+ let file_path = tmp_file.path().to_path_buf();
+ let mut src_file = std::fs::File::open(src).map_err(|e| e.to_string())?;
+ let mut buf = [0u8; 65536];
+ loop {
+ let n = src_file.read(&mut buf).map_err(|e| e.to_string())?;
+ if n == 0 { break; }
+ tmp_file.write_all(&buf[..n]).map_err(|e| e.to_string())?;
+ }
let dict_src = src.with_extension("dict");
if dict_src.exists() {
- let dict_dst = file_path.with_extension("dict");
+ let dict_dst = tmp_file.path().with_extension("dict");
let _ = std::fs::copy(&dict_src, &dict_dst);
}
bytes_done_global.fetch_add(size, Ordering::Relaxed);
+ drop(tmp_file);
return Ok((file_path, size));
}
@@ -173,7 +177,8 @@ fn download_file_quiet(
bytes_expected_global.fetch_add(len, Ordering::Relaxed);
}
- let mut file = std::fs::File::create(&file_path).map_err(|e| e.to_string())?;
+ let mut tmp_file = NamedTempFile::new().map_err(|e| e.to_string())?;
+ let file_path = tmp_file.path().to_path_buf();
let mut hasher = Sha256::new();
let mut buf = [0u8; 65536];
let mut downloaded: u64 = 0;
@@ -183,7 +188,7 @@ fn download_file_quiet(
let n = reader.read(&mut buf).map_err(|e| e.to_string())?;
if n == 0 { break; }
hasher.update(&buf[..n]);
- file.write_all(&buf[..n]).map_err(|e| e.to_string())?;
+ tmp_file.write_all(&buf[..n]).map_err(|e| e.to_string())?;
downloaded += n as u64;
bytes_done_global.fetch_add(n as u64, Ordering::Relaxed);
}
@@ -191,11 +196,11 @@ fn download_file_quiet(
if !expected_sha.is_empty() {
let hash = format!("{:x}", hasher.finalize());
if hash != expected_sha {
- let _ = std::fs::remove_file(&file_path);
return Err(format!("SHA256 mismatch: expected {}, got {}", expected_sha, hash));
}
}
+ drop(tmp_file);
Ok((file_path, downloaded))
}
@@ -341,13 +346,8 @@ fn install_from_archive(
root_dir: &Path,
pkg_type: &str,
) -> Result<Vec<String>, String> {
- let work_dir = std::path::Path::new("/tmp/ror-rootfs").join(pkg_name);
- if work_dir.exists() {
- fs::remove_dir_all(&work_dir)
- .map_err(|e| format!("Failed to clean temp dir for '{}': {}", pkg_name, e))?;
- }
- fs::create_dir_all(&work_dir)
- .map_err(|e| format!("Failed to create temp dir for '{}': {}", pkg_name, e))?;
+ let shadow = tempfile::tempdir().map_err(|e| format!("Failed to create temp dir: {}", e))?;
+ let work_dir = shadow.path().join(pkg_name);
let extracted = if pkg_type == "ror" {
extract_ror(archive_path, &work_dir)
@@ -365,7 +365,6 @@ fn install_from_archive(
let installed = install_files_to_root(&work_dir, root_dir, &extracted)?;
- let _ = fs::remove_dir_all(&work_dir);
let _ = fs::remove_file(archive_path);
Ok(installed)
@@ -586,7 +585,13 @@ fn find_working_shell(root_dir: &Path) -> Option<(&'static str, Option<&'static
vec![arg0, script_c]
};
let args_refs: Vec<&CStr> = args.iter().map(|s| s.as_c_str()).collect();
- let _ = execve::<&CStr, &CStr>(&shell_c, &args_refs, &[]);
+ let env_c = [
+ CString::new("PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin").unwrap(),
+ CString::new("HOME=/root").unwrap(),
+ CString::new("TERM=xterm").unwrap(),
+ ];
+ let env_refs: Vec<&CStr> = env_c.iter().map(|s| s.as_c_str()).collect();
+ let _ = execve::<&CStr, &CStr>(&shell_c, &args_refs, &env_refs);
std::process::exit(1);
}
Ok(ForkResult::Parent { child }) => {
@@ -634,7 +639,15 @@ fn run_install_steps_in_chroot(
} else {
vec![arg0, script_c]
};
- let _ = execve::<&CStr, &CStr>(&shell_c, &args.iter().map(|s| s.as_ref()).collect::<Vec<_>>(), &[]);
+ let args_refs: Vec<&CStr> = args.iter().map(|s| s.as_c_str()).collect();
+ let env_c = [
+ CString::new("PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin").unwrap(),
+ CString::new("HOME=/root").unwrap(),
+ CString::new("TERM=xterm").unwrap(),
+ CString::new("USER=root").unwrap(),
+ ];
+ let env_refs: Vec<&CStr> = env_c.iter().map(|s| s.as_c_str()).collect();
+ let _ = execve::<&CStr, &CStr>(&shell_c, &args_refs, &env_refs);
std::process::exit(1);
}
Ok(ForkResult::Parent { child }) => {
@@ -665,13 +678,25 @@ fn run_install_steps_in_chroot(
}
fn run_ldconfig_in_root(root_dir: &Path) -> Result<(), String> {
+ let ldconfig_path = if root_dir.join("sbin/ldconfig").exists() {
+ "/sbin/ldconfig"
+ } else if root_dir.join("usr/sbin/ldconfig").exists() {
+ "/usr/sbin/ldconfig"
+ } else {
+ return Ok(());
+ };
+
match unsafe { fork() } {
Ok(ForkResult::Child) => {
if chroot(root_dir).is_err() { std::process::exit(1); }
if chdir("/").is_err() { std::process::exit(1); }
- let ldconfig = CString::new("/sbin/ldconfig").unwrap();
+ let ldconfig = CString::new(ldconfig_path).unwrap();
let arg0 = CString::new("ldconfig").unwrap();
- let _ = execve::<&CString, &CStr>(&ldconfig, &[&arg0], &[]);
+ let env_c = [
+ CString::new("PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin").unwrap(),
+ ];
+ let env_refs: Vec<&CStr> = env_c.iter().map(|s| s.as_c_str()).collect();
+ let _ = execve::<&CStr, &CStr>(&ldconfig, &[&arg0], &env_refs);
std::process::exit(1);
}
Ok(ForkResult::Parent { child }) => {
diff --git a/src/sync.rs b/src/sync.rs
index ad36aea..2d1b6b7 100755
--- a/src/sync.rs
+++ b/src/sync.rs
@@ -1,21 +1,75 @@
use colored::*;
-use std::path::{Path};
-use git2::{Repository, RemoteCallbacks, FetchOptions, build::RepoBuilder};
+use std::path::Path;
+use std::process::Command;
use crate::config::Config;
const REPOS_DIR: &str = "/var/ror/packages";
+fn enforce_repo_https(url: &str) -> Result<(), String> {
+ if url.starts_with("http://") {
+ return Err(format!(
+ "Insecure HTTP URL rejected: {}. Only HTTPS is allowed for repositories.",
+ url
+ ));
+ }
+ Ok(())
+}
+
+fn check_repo_permissions() {
+ let repo_path = Path::new(REPOS_DIR);
+ if !repo_path.exists() {
+ return;
+ }
+ match std::fs::metadata(repo_path) {
+ Ok(meta) => {
+ use std::os::unix::fs::MetadataExt;
+ let uid = meta.uid();
+ if uid != 0 {
+ eprintln!(
+ "{} WARNING: Repository directory '{}' is owned by UID {} (not root). \
+ This is a security risk — any user can modify packages.",
+ "[ror]".yellow().bold(),
+ REPOS_DIR,
+ uid
+ );
+ }
+ let mode = meta.mode() & 0o7777;
+ if mode & 0o002 != 0 {
+ eprintln!(
+ "{} WARNING: Repository directory '{}' is world-writable (mode {:o}). \
+ This is a security risk — any user can inject malicious packages.",
+ "[ror]".yellow().bold(),
+ REPOS_DIR,
+ mode
+ );
+ }
+ }
+ Err(_) => {}
+ }
+}
+
pub fn run_sync(cfg: &Config) {
if cfg.repositories.is_empty() {
eprintln!("{} No repositories configured.", "[ror]".red().bold());
return;
}
+ check_repo_permissions();
for (name, repo) in &cfg.repositories {
+ if let Err(e) = enforce_repo_https(&repo.url) {
+ eprintln!("{} {}: {}", "[ror]".red().bold(), name, e);
+ continue;
+ }
+ if let Some(ref mirror) = repo.mirror {
+ if let Err(e) = enforce_repo_https(mirror) {
+ eprintln!("{} {}: {}", "[ror]".red().bold(), name, e);
+ continue;
+ }
+ }
println!("{} Syncing repository '{}'...", "[ror]".blue().bold(), name);
let repo_path = Path::new(REPOS_DIR).join(name);
if repo_path.exists() {
println!("{} Updating {}...", ">>>".green(), name);
- if let Err(e) = pull_or_clone(&repo_path, &repo.url) {
+ if let Err(e) = pull_repo(&repo_path, repo.mirror.as_deref()) {
eprintln!("{} {}", "[ror]".red(), e);
} else {
println!("{} Repository updated.", ">>>".green());
@@ -33,66 +87,57 @@ pub fn run_sync(cfg: &Config) {
fn clone_repo(name: &str, primary: &str, mirror: Option<&str>) -> Result<(), String> {
let path = Path::new(REPOS_DIR).join(name);
- let cb = RemoteCallbacks::new();
- let mut fo = FetchOptions::new();
- fo.remote_callbacks(cb);
- let result = RepoBuilder::new()
- .fetch_options(fo)
- .clone(primary, &path);
- if result.is_err() {
- if let Some(mirror_url) = mirror {
- let cb2 = RemoteCallbacks::new();
- let mut fo2 = FetchOptions::new();
- fo2.remote_callbacks(cb2);
- RepoBuilder::new()
- .fetch_options(fo2)
- .clone(mirror_url, &path)
- .map_err(|e| format!("Failed to clone from primary and mirror: {}", e))?;
- } else {
- return Err(format!("Clone failed: {}", result.err().unwrap()));
+ if let Some(parent) = path.parent() {
+ std::fs::create_dir_all(parent).map_err(|e| format!("Failed to create repos dir: {}", e))?;
+ }
+
+ let status = Command::new("git")
+ .args(["clone", primary, path.to_str().unwrap()])
+ .status()
+ .map_err(|e| format!("Failed to run git: {}", e))?;
+
+ if status.success() {
+ return Ok(());
+ }
+
+ if let Some(mirror_url) = mirror {
+ eprintln!("{} Primary clone failed, trying mirror...", "[ror]".yellow());
+ let mirror_status = Command::new("git")
+ .args(["clone", mirror_url, path.to_str().unwrap()])
+ .status()
+ .map_err(|e| format!("Failed to run git clone for mirror: {}", e))?;
+
+ if mirror_status.success() {
+ return Ok(());
}
}
- Ok(())
+
+ Err(format!("Failed to clone repository '{}'", name))
}
-fn pull_or_clone(repo_path: &Path, primary: &str) -> Result<(), String> {
- let repo = Repository::open(repo_path)
- .map_err(|e| format!("Cannot open repository: {}", e))?;
- let mut remote = repo.find_remote("origin")
- .or_else(|_| {
- repo.remote_set_url("origin", primary)?;
- repo.find_remote("origin")
- })
- .map_err(|e| format!("Remote error: {}", e))?;
- let cb = RemoteCallbacks::new();
- let mut fo = FetchOptions::new();
- fo.remote_callbacks(cb);
- remote.fetch(&["refs/heads/*:refs/heads/*"], Some(&mut fo), None)
- .map_err(|e| format!("Fetch failed: {}", e))?;
- let fetch_head = repo.find_reference("FETCH_HEAD")
- .map_err(|e| format!("FETCH_HEAD missing: {}", e))?;
- let fetch_commit = repo.reference_to_annotated_commit(&fetch_head)
- .map_err(|e| format!("Annotated commit error: {}", e))?;
- let (analysis, _) = repo.merge_analysis(&[&fetch_commit])
- .map_err(|e| format!("Merge analysis failed: {}", e))?;
- if analysis.is_fast_forward() {
- let mut refname = "refs/heads/master".to_string();
- if let Ok(head) = repo.head() {
- if let Some(name) = head.name() {
- refname = name.to_string();
- }
+fn pull_repo(repo_path: &Path, mirror: Option<&str>) -> Result<(), String> {
+ let path_str = repo_path.to_str().ok_or("Invalid repo path")?;
+ let status = Command::new("git")
+ .args(["-C", path_str, "pull"])
+ .status()
+ .map_err(|e| format!("Failed to run git pull: {}", e))?;
+
+ if status.success() {
+ return Ok(());
+ }
+
+ if let Some(mirror_url) = mirror {
+ eprintln!("{} Pull from primary failed, trying mirror...", "[ror]".yellow());
+ let mirror_status = Command::new("git")
+ .args(["-C", path_str, "pull", mirror_url])
+ .status()
+ .map_err(|e| format!("Failed to run git pull from mirror: {}", e))?;
+
+ if mirror_status.success() {
+ return Ok(());
}
- let mut reference = repo.find_reference(&refname)
- .map_err(|e| format!("Reference not found: {}", e))?;
- reference.set_target(fetch_commit.id(), "fast-forward merge")
- .map_err(|e| format!("Set target failed: {}", e))?;
- repo.set_head(&refname)
- .map_err(|e| format!("Set head failed: {}", e))?;
- repo.checkout_head(Some(git2::build::CheckoutBuilder::new().force()))
- .map_err(|e| format!("Checkout failed: {}", e))?;
- } else if analysis.is_normal() {
- return Err("Non-fast-forward update requires manual merge".to_string());
}
- Ok(())
+
+ Err(format!("Failed to pull repository at '{}'", path_str))
}
diff --git a/src/update.rs b/src/update.rs
index 1cceccc..62be1b5 100755
--- a/src/update.rs
+++ b/src/update.rs
@@ -83,9 +83,36 @@ pub fn update_package(pkg_name: &str, cfg: &config::Config, dry_run: bool) -> bo
return true;
}
- delete::remove_package(pkg_name);
- install::install_package(pkg_name, cfg);
- true
+ let old_files = db.packages.get(pkg_name).map(|r| r.files.clone()).unwrap_or_default();
+
+ match install::install_package_with_result(pkg_name, cfg) {
+ Ok(new_pkg) => {
+ let new_files: std::collections::HashSet<_> = new_pkg.files.iter().collect();
+ let obsolete_files: Vec<_> = old_files.into_iter()
+ .filter(|f| !new_files.contains(f))
+ .collect();
+ let mut db = InstalledDB::load();
+ db.packages.remove(pkg_name);
+ db.add_package(new_pkg);
+ if let Err(e) = db.save() {
+ eprintln!("{} Failed to save DB: {}", "[ror]".red().bold(), e);
+ }
+ if !obsolete_files.is_empty() {
+ delete::remove_package_files_only(pkg_name, &obsolete_files);
+ }
+ println!("{} '{}' updated successfully.", "[ror]".green().bold(), pkg_name);
+ true
+ }
+ Err(e) => {
+ eprintln!(
+ "{} Failed to install new version of '{}': {}. Old version remains intact.",
+ "[ror]".red().bold(),
+ pkg_name,
+ e
+ );
+ false
+ }
+ }
}
#[allow(dead_code)]