Skip to content

Commit

Permalink
Replace PathBuf/Utf8PathBuf with Path/Utf8Path when ownership not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Integral-Tech authored and bnjbvr committed Dec 19, 2024
1 parent b181002 commit f18e0b1
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 23 deletions.
9 changes: 7 additions & 2 deletions bindings/matrix-sdk-crypto-ffi/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use std::{env, error::Error, path::PathBuf, process::Command};
use std::{
env,
error::Error,
path::{Path, PathBuf},
process::Command,
};

use vergen::EmitBuilder;

Expand Down Expand Up @@ -39,7 +44,7 @@ fn setup_x86_64_android_workaround() {
}

/// Run the clang binary at `clang_path`, and return its major version number
fn get_clang_major_version(clang_path: &PathBuf) -> String {
fn get_clang_major_version(clang_path: &Path) -> String {
let clang_output =
Command::new(clang_path).arg("-dumpversion").output().expect("failed to start clang");

Expand Down
9 changes: 7 additions & 2 deletions bindings/matrix-sdk-ffi/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use std::{env, error::Error, path::PathBuf, process::Command};
use std::{
env,
error::Error,
path::{Path, PathBuf},
process::Command,
};

use vergen::EmitBuilder;

Expand Down Expand Up @@ -39,7 +44,7 @@ fn setup_x86_64_android_workaround() {
}

/// Run the clang binary at `clang_path`, and return its major version number
fn get_clang_major_version(clang_path: &PathBuf) -> String {
fn get_clang_major_version(clang_path: &Path) -> String {
let clang_output =
Command::new(clang_path).arg("-dumpversion").output().expect("failed to start clang");

Expand Down
14 changes: 7 additions & 7 deletions bindings/matrix-sdk-ffi/src/client_builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fs, num::NonZeroUsize, path::PathBuf, sync::Arc, time::Duration};
use std::{fs, num::NonZeroUsize, path::Path, sync::Arc, time::Duration};

use futures_util::StreamExt;
use matrix_sdk::{
Expand Down Expand Up @@ -509,21 +509,21 @@ impl ClientBuilder {
}

if let Some(session_paths) = &builder.session_paths {
let data_path = PathBuf::from(&session_paths.data_path);
let cache_path = PathBuf::from(&session_paths.cache_path);
let data_path = Path::new(&session_paths.data_path);
let cache_path = Path::new(&session_paths.cache_path);

debug!(
data_path = %data_path.to_string_lossy(),
cache_path = %cache_path.to_string_lossy(),
"Creating directories for data and cache stores.",
);

fs::create_dir_all(&data_path)?;
fs::create_dir_all(&cache_path)?;
fs::create_dir_all(data_path)?;
fs::create_dir_all(cache_path)?;

inner_builder = inner_builder.sqlite_store_with_cache_path(
&data_path,
&cache_path,
data_path,
cache_path,
builder.passphrase.as_deref(),
);
} else {
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-sqlite/src/crypto_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ impl CryptoStore for SqliteCryptoStore {

#[cfg(test)]
mod tests {
use std::path::PathBuf;
use std::path::Path;

use matrix_sdk_crypto::{
cryptostore_integration_tests, cryptostore_integration_tests_time, store::CryptoStore,
Expand All @@ -1428,7 +1428,7 @@ mod tests {
async fn get_test_db() -> TestDb {
let db_name = "matrix-sdk-crypto.sqlite3";

let manifest_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../..");
let manifest_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
let database_path = manifest_path.join("testing/data/storage").join(db_name);

let tmpdir = tempdir().unwrap();
Expand Down
10 changes: 5 additions & 5 deletions labs/multiverse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{
collections::HashMap,
env,
io::{self, stdout, Write},
path::PathBuf,
path::Path,
process::exit,
sync::{Arc, Mutex},
time::Duration,
Expand Down Expand Up @@ -62,7 +62,7 @@ async fn main() -> anyhow::Result<()> {
};

let config_path = env::args().nth(2).unwrap_or("/tmp/".to_owned());
let client = configure_client(server_name, config_path).await?;
let client = configure_client(&server_name, &config_path).await?;

let ec = client.event_cache();
ec.subscribe().unwrap();
Expand Down Expand Up @@ -978,10 +978,10 @@ impl<T> StatefulList<T> {
/// Configure the client so it's ready for sync'ing.
///
/// Will log in or reuse a previous session.
async fn configure_client(server_name: String, config_path: String) -> anyhow::Result<Client> {
let server_name = ServerName::parse(&server_name)?;
async fn configure_client(server_name: &str, config_path: &str) -> anyhow::Result<Client> {
let server_name = ServerName::parse(server_name)?;

let config_path = PathBuf::from(config_path);
let config_path = Path::new(config_path);
let mut client_builder = Client::builder()
.store_config(
StoreConfig::new("multiverse".to_owned())
Expand Down
4 changes: 2 additions & 2 deletions xtask/src/kotlin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl KotlinArgs {
package,
} => {
let profile = profile.as_deref().unwrap_or(if release { "release" } else { "dev" });
build_android_library(profile, only_target, src_dir, package)
build_android_library(profile, only_target, &src_dir, package)
}
}
}
Expand All @@ -80,7 +80,7 @@ impl KotlinArgs {
fn build_android_library(
profile: &str,
only_target: Option<String>,
src_dir: Utf8PathBuf,
src_dir: &Utf8Path,
package: Package,
) -> Result<()> {
let package_values = package.values();
Expand Down
6 changes: 3 additions & 3 deletions xtask/src/swift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ fn build_path_for_target(target: &Target, profile: &str) -> Result<Utf8PathBuf>
/// Lipo's together the libraries for each platform into a single library.
fn lipo_platform_libraries(
platform_build_paths: &HashMap<Platform, Vec<Utf8PathBuf>>,
generated_dir: &Utf8PathBuf,
generated_dir: &Utf8Path,
) -> Result<Vec<Utf8PathBuf>> {
let mut libs = Vec::new();
let sh = sh();
Expand Down Expand Up @@ -350,7 +350,7 @@ fn lipo_platform_libraries(

/// Moves all files of the specified file extension from one directory into
/// another.
fn move_files(extension: &str, source: &Utf8PathBuf, destination: &Utf8PathBuf) -> Result<()> {
fn move_files(extension: &str, source: &Utf8Path, destination: &Utf8Path) -> Result<()> {
for entry in source.read_dir_utf8()? {
let entry = entry?;

Expand All @@ -368,7 +368,7 @@ fn move_files(extension: &str, source: &Utf8PathBuf, destination: &Utf8PathBuf)
/// Consolidates the contents of each modulemap file found in the source
/// directory into a single `module.modulemap` file in the destination
/// directory.
fn consolidate_modulemap_files(source: &Utf8PathBuf, destination: &Utf8PathBuf) -> Result<()> {
fn consolidate_modulemap_files(source: &Utf8Path, destination: &Utf8Path) -> Result<()> {
let mut modulemap = String::new();
for entry in source.read_dir_utf8()? {
let entry = entry?;
Expand Down

0 comments on commit f18e0b1

Please sign in to comment.