Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mburridge96 committed Sep 12, 2024
2 parents 9d35e79 + afad372 commit 5a4288d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 120 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ url = "2.2"
zip = "0.6.6"
walkdir = "2"
reqwest = { version = "0.11", features = ["blocking", "json"], default-features = false}
minio = {git="https://github.com/minio/minio-rs.git"}
tokio = "1.38.0"

[dev-dependencies]
tempfile = "3.9"
Expand Down
75 changes: 0 additions & 75 deletions src/ro_crate/transfer/minio.rs

This file was deleted.

3 changes: 0 additions & 3 deletions src/ro_crate/transfer/mod.rs

This file was deleted.

68 changes: 28 additions & 40 deletions src/ro_crate/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use crate::ro_crate::read::read_crate;
use crate::ro_crate::rocrate::RoCrate;
use std::env;
use std::fmt;
use std::fs::{self, File};
use std::io::{self, Write};
Expand Down Expand Up @@ -303,28 +302,27 @@ pub fn zip_crate_external(
fn update_zip_ids(rocrate: &mut RoCrate, id: PathBuf, zip_id: &str) {
let id_str = id.to_str().unwrap_or_default();

// NOTE: this only really checks for extended length path failures - others may be present so this can
// be refactored when needed
// base update on direct match
if rocrate.update_id_recursive(id_str, zip_id).is_none() {
// if fail - check if the ID string contains the '\\?\' prefix
if id_str.starts_with(r"\\?\") {
let stripped_id = &id_str[4..];
if let Some(_) = rocrate.update_id_recursive(stripped_id, zip_id) {
} else {
// if win extend length not an issue, check \\ stripping
if id_str.contains("\\\\") {
if let Some(_) = rocrate.update_id_recursive(stripped_id, zip_id) {}
} else {
if let Some(_) = rocrate.update_id_recursive(stripped_id, zip_id) {}
}
}
} else {
// Try updating based on a direct match
if rocrate.update_id_recursive(id_str, zip_id).is_some() {
return;
}

// Handle Windows extended-length path prefixes (\\?\)
if id_str.starts_with(r"\\?\") {
let stripped_id = &id_str[4..];

// Attempt to update using the stripped path
if rocrate.update_id_recursive(stripped_id, zip_id).is_some() {
return;
}

// Handle paths with '\\' by replacing them with a single '\'
if id_str.contains("\\\\") {
let normalized_id = stripped_id.replace("\\\\", "\\");
rocrate.update_id_recursive(&normalized_id, zip_id);
}
} else {
}
}

/// Identifies file paths that are not relative to the given RO-Crate directory.
///
/// When preparing an RO-Crate for zipping, it's important to include all related files, even those
Expand All @@ -339,38 +337,28 @@ fn update_zip_ids(rocrate: &mut RoCrate, id: PathBuf, zip_id: &str) {
fn get_nonrelative_paths(ids: &Vec<&String>, crate_dir: &Path) -> Vec<PathBuf> {
let mut nonrels: Vec<PathBuf> = Vec::new();

// Get the absolute path of the crate directory
let rocrate_path = get_absolute_path(crate_dir).unwrap();
let root_dir = rocrate_path.parent();
// Extract the directory part of the path
if let Some(directory_path) = root_dir {
// Try to change the current working directory
let _ = env::set_current_dir(directory_path);
} else {
}

// Iterate over all the ids, check the paths are relative to crate.
// If not relative to crate and a file, then grab, add to extern folder
// and zip
// Iterate over all the ids, check if the paths are relative to the crate.
for id in ids.iter() {
// Skip IDs that are fragment references (i.e., starting with '#')
if id.starts_with('#') {
continue;
}

// Resolve the absolute path of the current ID
if let Some(path) = get_absolute_path(Path::new(id)) {
// Check if the path exists
if path.exists() {
let nonrel = is_outside_base_folder(root_dir.unwrap(), &path);
if nonrel {
if id.starts_with(".") {
nonrels.push(id.into());
} else {
nonrels.push(path);
}
// Check if the path is outside the base crate directory
if is_outside_base_folder(&rocrate_path, &path) {
nonrels.push(path);
}
} else {
}
} else {
continue;
}
}

nonrels
}
/// Converts a relative path to an absolute one, if possible.
Expand Down

0 comments on commit 5a4288d

Please sign in to comment.