Skip to content

Commit

Permalink
Merge branch 'main' into feature/async_incompatible
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsan authored Nov 18, 2024
2 parents eb2e1ed + c920320 commit 76a1fc0
Show file tree
Hide file tree
Showing 13 changed files with 296 additions and 268 deletions.
4 changes: 0 additions & 4 deletions .cargo/audit.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ ignore = [
# FIXME!: See https://github.com/RustCrypto/RSA/issues/19#issuecomment-1822995643.
# There is no workaround available yet.
"RUSTSEC-2023-0071",
# FIXME: backoff => used in backend, need to be replaced with backon
"RUSTSEC-2024-0384",
# FIXME: derivative => used for default impls
"RUSTSEC-2024-0388",
]
33 changes: 21 additions & 12 deletions .github/workflows/ci-heavy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,12 @@ jobs:
target: x86_64-pc-windows-msvc
architecture: x86_64
use-cross: false
- os: windows-latest
os-name: windows
target: x86_64-pc-windows-gnu
architecture: x86_64
use-cross: false
# FIXME: `aws-lc-sys` doesn't cross compile
# - os: windows-latest
# os-name: windows
# target: x86_64-pc-windows-gnu
# architecture: x86_64
# use-cross: false
- os: macos-13
os-name: macos
target: x86_64-apple-darwin
Expand Down Expand Up @@ -209,16 +210,24 @@ jobs:
target: i686-unknown-linux-gnu
architecture: i686
use-cross: true
- os: ubuntu-latest
os-name: netbsd
target: x86_64-unknown-netbsd
architecture: x86_64
use-cross: true
# Check because of Container images for rustic-rs
- os: ubuntu-latest
os-name: linux
target: armv7-unknown-linux-gnueabihf
architecture: armv7
target: aarch64-unknown-linux-musl
architecture: arm64
use-cross: true
# FIXME: `aws-lc-sys` doesn't cross compile
# - os: ubuntu-latest
# os-name: netbsd
# target: x86_64-unknown-netbsd
# architecture: x86_64
# use-cross: true
# FIXME: `aws-lc-sys` doesn't cross compile
# - os: ubuntu-latest
# os-name: linux
# target: armv7-unknown-linux-gnueabihf
# architecture: armv7
# use-cross: true

steps:
- name: Checkout repository
Expand Down
42 changes: 5 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions build-dependencies.just
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
install-default-x86_64-unknown-linux-musl:
sudo apt-get update
sudo apt-get install -y musl-tools

# Install dependencies for the default feature on aarch64-unknown-linux-musl
install-default-aarch64-unknown-linux-musl:
sudo apt-get update
sudo apt-get install -y musl-tools
8 changes: 4 additions & 4 deletions crates/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ opendal = [
"tokio/rt-multi-thread",
"dep:typed-path",
]
rest = ["dep:reqwest", "dep:backoff"]
rest = ["dep:reqwest", "dep:backon"]
rclone = ["rest", "dep:rand", "dep:semver"]

[dependencies]
Expand Down Expand Up @@ -78,7 +78,7 @@ aho-corasick = { workspace = true }
walkdir = "2.5.0"

# rest backend
backoff = { version = "0.4.0", optional = true }
backon = { version = "1.2.0", optional = true }
reqwest = { version = "0.12.8", default-features = false, features = ["json", "rustls-tls-native-roots", "stream", "blocking"], optional = true }

# rclone backend
Expand All @@ -97,11 +97,11 @@ features = ["prebuilt-nasm"]

[target.'cfg(not(windows))'.dependencies]
# opendal backend - sftp is not supported on windows, see https://github.com/apache/incubator-opendal/issues/2963
opendal = { version = "0.50.0", features = ["services-b2", "services-sftp", "services-swift", "services-azblob", "services-azdls", "services-cos", "services-fs", "services-ftp", "services-dropbox", "services-gdrive", "services-gcs", "services-ghac", "services-http", "services-ipmfs", "services-memory", "services-obs", "services-onedrive", "services-oss", "services-s3", "services-webdav", "services-webhdfs", "services-azfile", "layers-blocking", "layers-throttle"], optional = true }
opendal = { version = "0.50.2", features = ["services-b2", "services-sftp", "services-swift", "services-azblob", "services-azdls", "services-cos", "services-fs", "services-ftp", "services-dropbox", "services-gdrive", "services-gcs", "services-ghac", "services-http", "services-ipmfs", "services-memory", "services-obs", "services-onedrive", "services-oss", "services-s3", "services-webdav", "services-webhdfs", "services-azfile", "layers-blocking", "layers-throttle", "services-yandex-disk"], optional = true }

[target.'cfg(windows)'.dependencies]
# opendal backend
opendal = { version = "0.50.0", features = ["services-b2", "services-swift", "services-azblob", "services-azdls", "services-cos", "services-fs", "services-ftp", "services-dropbox", "services-gdrive", "services-gcs", "services-ghac", "services-http", "services-ipmfs", "services-memory", "services-obs", "services-onedrive", "services-oss", "services-s3", "services-webdav", "services-webhdfs", "services-azfile", "layers-blocking", "layers-throttle"], optional = true }
opendal = { version = "0.50.2", features = ["services-b2", "services-swift", "services-azblob", "services-azdls", "services-cos", "services-fs", "services-ftp", "services-dropbox", "services-gdrive", "services-gcs", "services-ghac", "services-http", "services-ipmfs", "services-memory", "services-obs", "services-onedrive", "services-oss", "services-s3", "services-webdav", "services-webhdfs", "services-azfile", "layers-blocking", "layers-throttle", "services-yandex-disk"], optional = true }

[dev-dependencies]
anyhow = { workspace = true }
Expand Down
46 changes: 44 additions & 2 deletions crates/backend/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,21 @@ impl LocalBackend {
}
Ok(())
}

/// Returns the parent path of the given file type and id.
///
/// # Arguments
///
/// * `tpe` - The type of the file.
/// * `id` - The id of the file.
///
/// # Returns
///
/// The parent path of the file or `None` if the file does not have a parent.
fn parent_path(&self, tpe: FileType, id: &Id) -> Option<PathBuf> {
let path = self.path(tpe, id);
path.parent().map(Path::to_path_buf)
}
}

impl ReadBackend for LocalBackend {
Expand Down Expand Up @@ -355,13 +370,14 @@ impl ReadBackend for LocalBackend {
length: u32,
) -> RusticResult<Bytes> {
trace!("reading tpe: {tpe:?}, id: {id}, offset: {offset}, length: {length}");
let mut file = File::open(self.path(tpe, id)).map_err(|err| {
let filename = self.path(tpe, id);
let mut file = File::open(filename.clone()).map_err(|err| {
RusticError::with_source(
ErrorKind::Backend,
"Failed to open the file `{path}`. Please check the file and try again.",
err,
)
.attach_context("path", self.path(tpe, id).to_string_lossy())
.attach_context("path", filename.to_string_lossy())
})?;
_ = file.seek(SeekFrom::Start(offset.into())).map_err(|err| {
RusticError::with_source(
Expand Down Expand Up @@ -466,6 +482,10 @@ impl WriteBackend for LocalBackend {
/// * If the length of the file could not be set.
/// * If the bytes could not be written to the file.
/// * If the OS Metadata could not be synced to disk.
/// * If the file does not have a parent directory.
/// * If the parent directory could not be created.
/// * If the file cannot be opened, due to missing permissions.
/// * If the file cannot be written to, due to lack of space on the disk.
fn write_bytes(
&self,
tpe: FileType,
Expand All @@ -476,6 +496,28 @@ impl WriteBackend for LocalBackend {
trace!("writing tpe: {:?}, id: {}", &tpe, &id);
let filename = self.path(tpe, id);

let Some(parent) = self.parent_path(tpe, id) else {
return Err(
RusticError::new(
ErrorKind::Backend,
"The file `{path}` does not have a parent directory. This may be empty or a root path. Please check the file and try again.",
)
.attach_context("path", filename.display().to_string())
.ask_report()
);
};

// create parent directory if it does not exist
fs::create_dir_all(parent.clone()).map_err(|err| {
RusticError::with_source(
ErrorKind::InputOutput,
"Failed to create directories `{path}`. Does the directory already exist? Please check the file and try again.",
err,
)
.attach_context("path", parent.display().to_string())
.ask_report()
})?;

let mut file = fs::OpenOptions::new()
.create(true)
.truncate(true)
Expand Down
Loading

0 comments on commit 76a1fc0

Please sign in to comment.