Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6421c81

Browse filesBrowse files
committed
chore: replace regex with regex-lite to reduce dependencies
1 parent 283fde0 commit 6421c81
Copy full SHA for 6421c81

File tree

Expand file treeCollapse file tree

18 files changed

+66
-42
lines changed
Filter options
Expand file treeCollapse file tree

18 files changed

+66
-42
lines changed

‎Cargo.lock

Copy file name to clipboardExpand all lines: Cargo.lock
+8-2Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

Copy file name to clipboardExpand all lines: Cargo.toml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ postgres = "0.19.9"
4545
quick-xml = "0.37.1"
4646
r2d2_postgres = "0.18.1"
4747
rand = "0.8.5"
48-
regex = "1.11.1"
48+
regex-lite = "0.1.6"
4949
reqwest = { version = "0.12.12", default-features = false }
5050
reqwest-middleware = "0.4.0"
5151
reqwest-retry = "0.7.0"

‎postgresql_archive/Cargo.toml

Copy file name to clipboardExpand all lines: postgresql_archive/Cargo.toml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ liblzma = { workspace = true }
1919
md-5 = { workspace = true, optional = true }
2020
num-format = { workspace = true }
2121
quick-xml = { workspace = true, features = ["serialize"], optional = true }
22-
regex = { workspace = true }
22+
regex-lite = { workspace = true }
2323
reqwest = { workspace = true, default-features = false, features = ["json", "stream"] }
2424
reqwest-middleware = { workspace = true }
2525
reqwest-retry = { workspace = true }

‎postgresql_archive/src/archive.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/archive.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use crate::error::Result;
55
use crate::{extractor, repository};
6-
use regex::Regex;
6+
use regex_lite::Regex;
77
use semver::{Version, VersionReq};
88
use std::path::{Path, PathBuf};
99
use tracing::instrument;

‎postgresql_archive/src/configuration/theseus/extractor.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/configuration/theseus/extractor.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::extractor::{tar_gz_extract, ExtractDirectories};
22
use crate::Error::Unexpected;
33
use crate::Result;
4-
use regex::Regex;
4+
use regex_lite::Regex;
55
use std::fs::{create_dir_all, remove_dir_all, remove_file, rename};
66
use std::path::{Path, PathBuf};
77
use std::thread::sleep;

‎postgresql_archive/src/configuration/zonky/extractor.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/configuration/zonky/extractor.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::extractor::{tar_xz_extract, ExtractDirectories};
22
use crate::Error::Unexpected;
33
use crate::Result;
4-
use regex::Regex;
4+
use regex_lite::Regex;
55
use std::fs::{create_dir_all, remove_dir_all, remove_file, rename};
66
use std::io::Cursor;
77
use std::path::{Path, PathBuf};

‎postgresql_archive/src/error.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/error.rs
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ pub enum Error {
4848
VersionNotFound(String),
4949
}
5050

51-
/// Converts a [`regex::Error`] into an [`ParseError`](Error::ParseError)
52-
impl From<regex::Error> for Error {
53-
fn from(error: regex::Error) -> Self {
51+
/// Converts a [`regex_lite::Error`] into an [`ParseError`](Error::ParseError)
52+
impl From<regex_lite::Error> for Error {
53+
fn from(error: regex_lite::Error) -> Self {
5454
Error::ParseError(error.to_string())
5555
}
5656
}
@@ -125,9 +125,9 @@ mod test {
125125

126126
#[test]
127127
fn test_from_regex_error() {
128-
let regex_error = regex::Error::Syntax("test".to_string());
128+
let regex_error = regex_lite::Regex::new("(?=a)").expect_err("regex error");
129129
let error = Error::from(regex_error);
130-
assert_eq!(error.to_string(), "test");
130+
assert_eq!(error.to_string(), "look-around is not supported");
131131
}
132132

133133
#[tokio::test]

‎postgresql_archive/src/extractor/model.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/extractor/model.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{Error, Result};
2-
use regex::Regex;
2+
use regex_lite::Regex;
33
use std::fmt::Display;
44
use std::path::PathBuf;
55

‎postgresql_archive/src/extractor/registry.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/extractor/registry.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn get(url: &str) -> Result<ExtractFn> {
9898
#[cfg(test)]
9999
mod tests {
100100
use super::*;
101-
use regex::Regex;
101+
use regex_lite::Regex;
102102

103103
#[test]
104104
fn test_register() -> Result<()> {

‎postgresql_archive/src/repository/github/repository.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/repository/github/repository.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::Error::{
88
use crate::{hasher, matcher, Result};
99
use async_trait::async_trait;
1010
use futures_util::StreamExt;
11-
use regex::Regex;
11+
use regex_lite::Regex;
1212
use reqwest::header::HeaderMap;
1313
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
1414
use reqwest_retry::policies::ExponentialBackoff;

‎postgresql_extensions/Cargo.toml

Copy file name to clipboardExpand all lines: postgresql_extensions/Cargo.toml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ version.workspace = true
1414
async-trait = { workspace = true }
1515
postgresql_archive = { path = "../postgresql_archive", version = "0.17.4", default-features = false }
1616
postgresql_commands = { path = "../postgresql_commands", version = "0.17.4", default-features = false }
17-
regex = { workspace = true }
17+
regex-lite = { workspace = true }
1818
reqwest = { workspace = true, default-features = false, features = ["json"] }
1919
semver = { workspace = true, features = ["serde"] }
2020
serde = { workspace = true, features = ["derive"] }

‎postgresql_extensions/src/error.rs

Copy file name to clipboardExpand all lines: postgresql_extensions/src/error.rs
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ pub enum Error {
1414
#[error("extension not found '{0}'")]
1515
ExtensionNotFound(String),
1616
/// Error when an IO operation fails
17-
#[error(transparent)]
18-
IoError(#[from] std::io::Error),
17+
#[error("{0}")]
18+
IoError(String),
1919
/// Poisoned lock
2020
#[error("poisoned lock '{0}'")]
2121
PoisonedLock(String),
2222
/// Error when a regex operation fails
2323
#[error(transparent)]
24-
RegexError(#[from] regex::Error),
24+
RegexError(#[from] regex_lite::Error),
2525
/// Error when a deserialization or serialization operation fails
2626
#[error(transparent)]
2727
SerdeError(#[from] serde_json::Error),

‎postgresql_extensions/src/extensions.rs

Copy file name to clipboardExpand all lines: postgresql_extensions/src/extensions.rs
+11-9Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::model::AvailableExtension;
22
use crate::repository::registry;
33
use crate::repository::registry::get_repositories;
4+
use crate::Error::IoError;
45
use crate::{InstalledConfiguration, InstalledExtension, Result};
56
use postgresql_commands::pg_config::PgConfigBuilder;
67
use postgresql_commands::postgres::PostgresBuilder;
@@ -10,7 +11,7 @@ use postgresql_commands::CommandBuilder;
1011
#[cfg(not(feature = "tokio"))]
1112
use postgresql_commands::CommandExecutor;
1213
use postgresql_commands::Settings;
13-
use regex::Regex;
14+
use regex_lite::Regex;
1415
use semver::VersionReq;
1516
use std::path::PathBuf;
1617
use tracing::{debug, instrument};
@@ -116,9 +117,12 @@ pub async fn uninstall(settings: &impl Settings, namespace: &str, name: &str) ->
116117
if file.exists() {
117118
debug!("Removing file: {file:?}");
118119
#[cfg(feature = "tokio")]
119-
tokio::fs::remove_file(file).await?;
120+
tokio::fs::remove_file(file)
121+
.await
122+
.map_err(|error| IoError(error.to_string()))?;
120123
#[cfg(not(feature = "tokio"))]
121-
std::fs::remove_file(file)?;
124+
std::fs::remove_file(file)
125+
.map_err(|error| crate::error::Error::IoError(error.to_string()))?;
122126
}
123127
}
124128
}
@@ -208,16 +212,14 @@ async fn get_postgresql_version(settings: &dyn Settings) -> Result<String> {
208212
let (stdout, _stderr) = execute_command(command).await?;
209213
let re = Regex::new(r"PostgreSQL\)\s(\d+\.\d+)")?;
210214
let Some(captures) = re.captures(&stdout) else {
211-
return Err(regex::Error::Syntax(format!(
215+
return Err(IoError(format!(
212216
"Failed to obtain postgresql version from {stdout}"
213-
))
214-
.into());
217+
)));
215218
};
216219
let Some(version) = captures.get(1) else {
217-
return Err(regex::Error::Syntax(format!(
220+
return Err(IoError(format!(
218221
"Failed to match postgresql version from {stdout}"
219-
))
220-
.into());
222+
)));
221223
};
222224
let version = version.as_str();
223225
debug!("Obtained PostgreSQL version from postgres command: {version}");

‎postgresql_extensions/src/matcher.rs

Copy file name to clipboardExpand all lines: postgresql_extensions/src/matcher.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use postgresql_archive::Result;
2-
use regex::Regex;
2+
use regex_lite::Regex;
33
use semver::Version;
44
use std::collections::HashMap;
55
use std::env::consts;

‎postgresql_extensions/src/model.rs

Copy file name to clipboardExpand all lines: postgresql_extensions/src/model.rs
+26-10Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::Error::IoError;
12
use crate::Result;
23
use semver::Version;
34
use serde::{Deserialize, Serialize};
@@ -74,17 +75,23 @@ impl InstalledConfiguration {
7475
pub async fn read<P: Into<PathBuf>>(path: P) -> Result<Self> {
7576
#[cfg(feature = "tokio")]
7677
{
77-
let mut file = tokio::fs::File::open(path.into()).await?;
78+
let mut file = tokio::fs::File::open(path.into())
79+
.await
80+
.map_err(|error| IoError(error.to_string()))?;
7881
let mut contents = vec![];
79-
file.read_to_end(&mut contents).await?;
82+
file.read_to_end(&mut contents)
83+
.await
84+
.map_err(|error| IoError(error.to_string()))?;
8085
let config = serde_json::from_slice(&contents)?;
8186
Ok(config)
8287
}
8388
#[cfg(not(feature = "tokio"))]
8489
{
85-
let file = std::fs::File::open(path.into())?;
90+
let file =
91+
std::fs::File::open(path.into()).map_err(|error| IoError(error.to_string()))?;
8692
let reader = std::io::BufReader::new(file);
87-
let config = serde_json::from_reader(reader)?;
93+
let config =
94+
serde_json::from_reader(reader).map_err(|error| IoError(error.to_string()))?;
8895
Ok(config)
8996
}
9097
}
@@ -98,13 +105,19 @@ impl InstalledConfiguration {
98105

99106
#[cfg(feature = "tokio")]
100107
{
101-
let mut file = tokio::fs::File::create(path.into()).await?;
102-
file.write_all(content.as_bytes()).await?;
108+
let mut file = tokio::fs::File::create(path.into())
109+
.await
110+
.map_err(|error| IoError(error.to_string()))?;
111+
file.write_all(content.as_bytes())
112+
.await
113+
.map_err(|error| IoError(error.to_string()))?;
103114
}
104115
#[cfg(not(feature = "tokio"))]
105116
{
106-
let mut file = std::fs::File::create(path.into())?;
107-
file.write_all(content.as_bytes())?;
117+
let mut file =
118+
std::fs::File::create(path.into()).map_err(|error| IoError(error.to_string()))?;
119+
file.write_all(content.as_bytes())
120+
.map_err(|error| IoError(error.to_string()))?;
108121
}
109122
Ok(())
110123
}
@@ -236,7 +249,8 @@ mod tests {
236249
#[cfg(target_os = "linux")]
237250
#[tokio::test]
238251
async fn test_installed_configuration_io() -> Result<()> {
239-
let temp_file = tempfile::NamedTempFile::new()?;
252+
let temp_file =
253+
tempfile::NamedTempFile::new().map_err(|error| IoError(error.to_string()))?;
240254
let file = temp_file.as_ref();
241255
let extensions = vec![InstalledExtension::new(
242256
"namespace",
@@ -248,7 +262,9 @@ mod tests {
248262
expected_configuration.write(file).await?;
249263
let configuration = InstalledConfiguration::read(file).await?;
250264
assert_eq!(expected_configuration, configuration);
251-
tokio::fs::remove_file(file).await?;
265+
tokio::fs::remove_file(file)
266+
.await
267+
.map_err(|error| IoError(error.to_string()))?;
252268
Ok(())
253269
}
254270

‎postgresql_extensions/src/repository/portal_corp/repository.rs

Copy file name to clipboardExpand all lines: postgresql_extensions/src/repository/portal_corp/repository.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use async_trait::async_trait;
77
use postgresql_archive::extractor::{zip_extract, ExtractDirectories};
88
use postgresql_archive::get_archive;
99
use postgresql_archive::repository::github::repository::GitHub;
10-
use regex::Regex;
10+
use regex_lite::Regex;
1111
use semver::{Version, VersionReq};
1212
use std::fmt::Debug;
1313
use std::path::PathBuf;

‎postgresql_extensions/src/repository/steampipe/repository.rs

Copy file name to clipboardExpand all lines: postgresql_extensions/src/repository/steampipe/repository.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use async_trait::async_trait;
88
use postgresql_archive::extractor::{tar_gz_extract, ExtractDirectories};
99
use postgresql_archive::get_archive;
1010
use postgresql_archive::repository::github::repository::GitHub;
11-
use regex::Regex;
11+
use regex_lite::Regex;
1212
use semver::{Version, VersionReq};
1313
use std::fmt::Debug;
1414
use std::path::PathBuf;

‎postgresql_extensions/src/repository/tensor_chord/repository.rs

Copy file name to clipboardExpand all lines: postgresql_extensions/src/repository/tensor_chord/repository.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use async_trait::async_trait;
77
use postgresql_archive::extractor::{zip_extract, ExtractDirectories};
88
use postgresql_archive::get_archive;
99
use postgresql_archive::repository::github::repository::GitHub;
10-
use regex::Regex;
10+
use regex_lite::Regex;
1111
use semver::{Version, VersionReq};
1212
use std::fmt::Debug;
1313
use std::path::PathBuf;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.