Skip to content

Commit 9dd2d3b

Browse files
Merge pull request #279 from K900/maintenance
Boring maintenance work
2 parents 9f63407 + 6a1911e commit 9dd2d3b

File tree

14 files changed

+1316
-1094
lines changed

14 files changed

+1316
-1094
lines changed

Cargo.lock

Lines changed: 914 additions & 732 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ name = "nix-index"
2626
name = "nix-locate"
2727

2828
[dependencies]
29-
bincode = "1.3.3"
29+
bincode = { version = "2.0.1", features = ["serde"] }
3030
byteorder = "1.5.0"
31-
error-chain = "0.12.4"
3231
futures = "0.3.30"
3332
grep = "0.3.1"
3433
atty = "0.2.14"
@@ -38,22 +37,18 @@ indexmap = "2.2.6"
3837
owo-colors = { version = "4.0.0", features = ["supports-colors"] }
3938
rayon = "1.10.0"
4039
regex = "1.10.4"
41-
regex-syntax = "0.7.4"
42-
reqwest = { version = "0.12.3", features = [ "brotli" ] }
40+
regex-syntax = "0.8.5"
41+
reqwest = { version = "0.12.3", default-features = false, features = [ "brotli", "http2", "rustls-tls" ] }
4342
separator = "0.4.1"
4443
serde = { version = "1.0.198", features = [ "derive" ] }
4544
serde_bytes = "0.11.14"
4645
serde_json = "1.0.116"
46+
thiserror = "2.0.12"
4747
tokio-retry = "0.3.0"
48-
xdg = "2.5.2"
48+
xdg = "3.0.0"
4949
xml-rs = "0.8.20"
5050
xz2 = "0.1.7"
51-
zstd = { version = "0.12.4", features = [ "zstdmt" ] }
52-
53-
[dependencies.hyper]
54-
features = ["client", "http1", "http2", "runtime", "stream"]
55-
version = "0.14.27"
56-
51+
zstd = { version = "0.13.3", features = [ "zstdmt" ] }
5752

5853
[dependencies.tokio]
5954
features = ["full"]
@@ -65,7 +60,7 @@ features = ["derive", "env"]
6560

6661
[dependencies.rusqlite]
6762
features = ["backup"]
68-
version = "0.31.0"
63+
version = "0.37.0"
6964

7065
[[example]]
7166
name = "nix-index-debug"

flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@
3333
lockFile = ./Cargo.lock;
3434
};
3535

36-
nativeBuildInputs = [ pkg-config ];
37-
buildInputs = [ openssl curl sqlite ]
38-
++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security ];
36+
buildInputs = [ sqlite ];
3937

4038
postInstall = ''
4139
substituteInPlace command-not-found.sh \
@@ -66,18 +64,9 @@
6664
minimal = with nixpkgsFor.${system}; mkShell {
6765
name = "nix-index";
6866

69-
nativeBuildInputs = [
70-
pkg-config
71-
];
72-
73-
buildInputs = [
74-
openssl
75-
sqlite
76-
] ++ lib.optionals stdenv.isDarwin [
77-
darwin.apple_sdk.frameworks.Security
78-
];
67+
nativeBuildInputs = [ pkg-config ];
7968

80-
env.LD_LIBRARY_PATH = lib.makeLibraryPath [ openssl ];
69+
buildInputs = [ sqlite ];
8170
};
8271

8372
default = with nixpkgsFor.${system}; mkShell {
@@ -87,10 +76,7 @@
8776

8877
nativeBuildInputs = [ rustc cargo clippy rustfmt ];
8978

90-
env = {
91-
LD_LIBRARY_PATH = lib.makeLibraryPath [ openssl ];
92-
RUST_SRC_PATH = rustPlatform.rustLibSrc;
93-
};
79+
env.RUST_SRC_PATH = rustPlatform.rustLibSrc;
9480
};
9581
});
9682

src/bin/nix-channel-index.rs

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ use std::path::PathBuf;
66
use std::process;
77

88
use clap::Parser;
9-
use error_chain::ChainedError;
109
use futures::{future, StreamExt};
1110
use nix_index::files::{FileNode, FileType};
1211
use nix_index::hydra::Fetcher;
13-
use nix_index::listings::fetch_listings;
12+
use nix_index::listings;
1413
use nix_index::{errors::*, CACHE_URL};
15-
use rusqlite::{Connection, DatabaseName};
14+
use rusqlite::Connection;
1615

1716
/// The main function of this module: creates a new command-not-found database.
1817
async fn update_index(args: &Args) -> Result<()> {
19-
let fetcher = Fetcher::new(CACHE_URL.to_string()).map_err(ErrorKind::ParseProxy)?;
20-
let connection =
21-
Connection::open_in_memory().map_err(|_| ErrorKind::CreateDatabase(args.output.clone()))?;
18+
let fetcher = Fetcher::new(CACHE_URL.to_string()).map_err(Error::ParseProxy)?;
19+
let connection = Connection::open_in_memory().map_err(|e| Error::CreateDatabase {
20+
path: args.output.clone(),
21+
source: Box::new(e),
22+
})?;
2223

2324
connection
2425
.execute(
@@ -32,10 +33,15 @@ async fn update_index(args: &Args) -> Result<()> {
3233
"#,
3334
(),
3435
)
35-
.map_err(|_| ErrorKind::CreateDatabase(args.output.clone()))?;
36-
37-
let debug_connection = Connection::open_in_memory()
38-
.map_err(|_| ErrorKind::CreateDatabase(args.debug_output.clone()))?;
36+
.map_err(|e| Error::CreateDatabase {
37+
path: args.output.clone(),
38+
source: Box::new(e),
39+
})?;
40+
41+
let debug_connection = Connection::open_in_memory().map_err(|e| Error::CreateDatabase {
42+
path: args.debug_output.clone(),
43+
source: Box::new(e),
44+
})?;
3945
debug_connection
4046
.execute(
4147
r#"
@@ -48,7 +54,10 @@ async fn update_index(args: &Args) -> Result<()> {
4854
"#,
4955
(),
5056
)
51-
.map_err(|_| ErrorKind::CreateDatabase(args.debug_output.clone()))?;
57+
.map_err(|e| Error::CreateDatabase {
58+
path: args.debug_output.clone(),
59+
source: Box::new(e),
60+
})?;
5261

5362
let systems = match &args.systems {
5463
Some(systems) => systems.iter().map(|x| Some(x.as_str())).collect(),
@@ -57,12 +66,12 @@ async fn update_index(args: &Args) -> Result<()> {
5766

5867
eprint!("+ querying available packages");
5968
let (files, watch) =
60-
fetch_listings(&fetcher, args.jobs, &args.nixpkgs, systems, args.show_trace)?;
69+
listings::fetch(&fetcher, args.jobs, &args.nixpkgs, systems, args.show_trace)?;
6170

6271
// Treat request errors as if the file list were missing
6372
let files = files.map(|r| {
6473
r.unwrap_or_else(|e| {
65-
eprint!("\n{}", e.display_chain());
74+
eprint!("\n{:?}", e);
6675
None
6776
})
6877
});
@@ -117,7 +126,7 @@ async fn update_index(args: &Args) -> Result<()> {
117126
"insert or replace into Programs(name, system, package) values (?, ?, ?)",
118127
(binary, system, attr),
119128
)
120-
.map_err(|_| ErrorKind::CreateDatabase(args.output.clone()))?;
129+
.map_err(|e| Error::CreateDatabase { path: args.output.clone(), source: Box::new(e) })?;
121130
}
122131

123132
if let Ok(debuginfo) = path.strip_prefix("/lib/debug/.build-id") {
@@ -139,7 +148,7 @@ async fn update_index(args: &Args) -> Result<()> {
139148
"insert or replace into DebugInfo(build_id, url, filename) values (?, ?, ?)",
140149
(build_id, format!("../{}", nar), path.to_string_lossy().strip_prefix('/')),
141150
)
142-
.map_err(|_| ErrorKind::CreateDatabase(args.debug_output.clone()))?;
151+
.map_err(|e| Error::CreateDatabase { path: args.debug_output.clone(), source: Box::new(e) })?;
143152
}
144153
}
145154
}
@@ -149,12 +158,18 @@ async fn update_index(args: &Args) -> Result<()> {
149158
eprint!("+ dumping index");
150159

151160
connection
152-
.backup(DatabaseName::Main, &args.output, None)
153-
.map_err(|_| ErrorKind::CreateDatabase(args.output.clone()))?;
161+
.backup("main", &args.output, None)
162+
.map_err(|e| Error::CreateDatabase {
163+
path: args.output.clone(),
164+
source: Box::new(e),
165+
})?;
154166

155167
debug_connection
156-
.backup(DatabaseName::Main, &args.debug_output, None)
157-
.map_err(|_| ErrorKind::CreateDatabase(args.debug_output.clone()))?;
168+
.backup("main", &args.debug_output, None)
169+
.map_err(|e| Error::CreateDatabase {
170+
path: args.debug_output.clone(),
171+
source: Box::new(e),
172+
})?;
158173

159174
Ok(())
160175
}
@@ -192,15 +207,7 @@ async fn main() {
192207
let args = Args::parse();
193208

194209
if let Err(e) = update_index(&args).await {
195-
eprintln!("error: {}", e);
196-
197-
for e in e.iter().skip(1) {
198-
eprintln!("caused by: {}", e);
199-
}
200-
201-
if let Some(backtrace) = e.backtrace() {
202-
eprintln!("backtrace: {:?}", backtrace);
203-
}
210+
eprintln!("error: {:?}", e);
204211
process::exit(2);
205212
}
206213
}

src/bin/nix-index.rs

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ use std::path::PathBuf;
66
use std::process;
77

88
use clap::Parser;
9-
use error_chain::ChainedError;
109
use futures::future::Either;
1110
use futures::{future, StreamExt};
1211
use nix_index::database::Writer;
1312
use nix_index::errors::*;
1413
use nix_index::files::FileTree;
1514
use nix_index::hydra::Fetcher;
16-
use nix_index::listings::{fetch_listings, try_load_paths_cache};
15+
use nix_index::listings::{self, try_load_paths_cache};
1716
use nix_index::package::StorePath;
1817
use nix_index::CACHE_URL;
1918
use separator::Separatable;
@@ -31,11 +30,11 @@ async fn update_index(args: &Args) -> Result<()> {
3130
};
3231

3332
eprintln!("+ querying available packages");
34-
let fetcher = Fetcher::new(CACHE_URL.to_string()).map_err(ErrorKind::ParseProxy)?;
33+
let fetcher = Fetcher::new(CACHE_URL.to_string()).map_err(Error::ParseProxy)?;
3534
let (files, watch) = match cached {
3635
Some((f, w)) => (Either::Left(f), w),
3736
None => {
38-
let (f, w) = fetch_listings(
37+
let (f, w) = listings::fetch(
3938
&fetcher,
4039
args.jobs,
4140
&args.nixpkgs,
@@ -49,7 +48,7 @@ async fn update_index(args: &Args) -> Result<()> {
4948
// Treat request errors as if the file list were missing
5049
let files = files.map(|r| {
5150
r.unwrap_or_else(|e| {
52-
eprint!("\n{}", e.display_chain());
51+
eprint!("\n{:?}", e);
5352
None
5453
})
5554
});
@@ -76,10 +75,17 @@ async fn update_index(args: &Args) -> Result<()> {
7675
eprint!(" (filtering by `{}`)", args.filter_prefix);
7776
}
7877
eprint!("\r");
79-
fs::create_dir_all(&args.database)
80-
.chain_err(|| ErrorKind::CreateDatabaseDir(args.database.clone()))?;
81-
let mut db = Writer::create(args.database.join("files"), args.compression_level)
82-
.chain_err(|| ErrorKind::CreateDatabase(args.database.clone()))?;
78+
fs::create_dir_all(&args.database).map_err(|e| Error::CreateDatabaseDir {
79+
path: args.database.clone(),
80+
source: e,
81+
})?;
82+
let mut db =
83+
Writer::create(args.database.join("files"), args.compression_level).map_err(|e| {
84+
Error::CreateDatabase {
85+
path: args.database.clone(),
86+
source: Box::new(e),
87+
}
88+
})?;
8389

8490
let mut results: Vec<(StorePath, String, FileTree)> = Vec::new();
8591
while let Some(entry) = files.next().await {
@@ -88,29 +94,38 @@ async fn update_index(args: &Args) -> Result<()> {
8894
}
8995
let (path, _, files) = entry;
9096
db.add(path, files, args.filter_prefix.as_bytes())
91-
.chain_err(|| ErrorKind::WriteDatabase(args.database.clone()))?;
97+
.map_err(|e| Error::WriteDatabase {
98+
path: args.database.clone(),
99+
source: e,
100+
})?;
92101
}
93102
eprintln!();
94103

95104
if args.path_cache {
96105
eprintln!("+ writing path cache");
97-
let mut output = io::BufWriter::new(
98-
File::create("paths.cache").chain_err(|| ErrorKind::WritePathsCache)?,
99-
);
100-
bincode::serialize_into(&mut output, &results).chain_err(|| ErrorKind::WritePathsCache)?;
106+
let mut output = io::BufWriter::new(File::create("paths.cache").map_err(|e| {
107+
Error::WritePathsCache {
108+
source: Box::new(e),
109+
}
110+
})?);
111+
bincode::serde::encode_into_std_write(&results, &mut output, bincode::config::standard())
112+
.map_err(|e| Error::WritePathsCache {
113+
source: Box::new(e),
114+
})?;
101115
}
102116

103-
let index_size = db
104-
.finish()
105-
.chain_err(|| ErrorKind::WriteDatabase(args.database.clone()))?;
117+
let index_size = db.finish().map_err(|e| Error::WriteDatabase {
118+
path: args.database.clone(),
119+
source: e,
120+
})?;
106121
eprintln!("+ wrote index of {} bytes", index_size.separated_string());
107122

108123
Ok(())
109124
}
110125

111126
fn cache_dir() -> &'static OsStr {
112-
let base = xdg::BaseDirectories::with_prefix("nix-index").unwrap();
113-
let cache_dir = Box::new(base.get_cache_home());
127+
let base = xdg::BaseDirectories::with_prefix("nix-index");
128+
let cache_dir = Box::new(base.get_cache_home().unwrap());
114129
let cache_dir = Box::leak(cache_dir);
115130
cache_dir.as_os_str()
116131
}
@@ -160,15 +175,7 @@ async fn main() {
160175
let args = Args::parse();
161176

162177
if let Err(e) = update_index(&args).await {
163-
eprintln!("error: {}", e);
164-
165-
for e in e.iter().skip(1) {
166-
eprintln!("caused by: {}", e);
167-
}
168-
169-
if let Some(backtrace) = e.backtrace() {
170-
eprintln!("backtrace: {:?}", backtrace);
171-
}
178+
eprintln!("error: {:?}", e);
172179
process::exit(2);
173180
}
174181
}

0 commit comments

Comments
 (0)